diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-05-07 17:59:16 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-05-12 19:28:30 -0300 |
commit | b3268d071277c8967b3e3ecb60430718e1f36472 (patch) | |
tree | 37fbdeb52835cd3fff0648301292aec12f25bb12 /src/api | |
parent | fc22317389fa8713f27f5a754ee142ae003f5871 (diff) | |
download | rneovim-b3268d071277c8967b3e3ecb60430718e1f36472.tar.gz rneovim-b3268d071277c8967b3e3ecb60430718e1f36472.tar.bz2 rneovim-b3268d071277c8967b3e3ecb60430718e1f36472.zip |
Refactor API types and prototypes
- Split functions with multiple files in the 'api' subdirectory
- Move/Add more types in the 'api/defs.h' header
- Add more prototypes
- Refactor scripts/msgpack-gen.lua
- Move msgpack modules to 'os' subdirectory
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/buffer.c | 87 | ||||
-rw-r--r-- | src/api/buffer.h | 135 | ||||
-rw-r--r-- | src/api/defs.h | 74 | ||||
-rw-r--r-- | src/api/tabpage.c | 32 | ||||
-rw-r--r-- | src/api/tabpage.h | 46 | ||||
-rw-r--r-- | src/api/vim.c | 140 | ||||
-rw-r--r-- | src/api/vim.h | 172 | ||||
-rw-r--r-- | src/api/window.c | 73 | ||||
-rw-r--r-- | src/api/window.h | 105 |
9 files changed, 864 insertions, 0 deletions
diff --git a/src/api/buffer.c b/src/api/buffer.c new file mode 100644 index 0000000000..743d8c4729 --- /dev/null +++ b/src/api/buffer.c @@ -0,0 +1,87 @@ +#include <stdint.h> +#include <stdlib.h> + +#include "api/buffer.h" +#include "api/defs.h" + +int64_t buffer_get_length(Buffer buffer, Error *err) +{ + abort(); +} + +String buffer_get_line(Buffer buffer, int64_t index, Error *err) +{ + abort(); +} + +void buffer_set_line(Buffer buffer, int64_t index, String line, Error *err) +{ + abort(); +} + +StringArray buffer_get_slice(Buffer buffer, + int64_t start, + int64_t end, + Error *err) +{ + abort(); +} + +void buffer_set_slice(Buffer buffer, + int64_t start, + int64_t end, + StringArray lines, + Error *err) +{ + abort(); +} + +Object buffer_get_var(Buffer buffer, String name, Error *err) +{ + abort(); +} + +void buffer_set_var(Buffer buffer, String name, Object value, Error *err) +{ + abort(); +} + +String buffer_get_option(Buffer buffer, String name, Error *err) +{ + abort(); +} + +void buffer_set_option(Buffer buffer, String name, String value, Error *err) +{ + abort(); +} + +void buffer_del_option(Buffer buffer, String name, Error *err) +{ + abort(); +} + +String buffer_get_name(Buffer buffer, Error *err) +{ + abort(); +} + +void buffer_set_name(Buffer buffer, String name, Error *err) +{ + abort(); +} + +bool buffer_is_valid(Buffer buffer) +{ + abort(); +} + +void buffer_insert(Buffer buffer, StringArray lines, int64_t lnum, Error *err) +{ + abort(); +} + +Position buffer_mark(Buffer buffer, String name, Error *err) +{ + abort(); +} diff --git a/src/api/buffer.h b/src/api/buffer.h new file mode 100644 index 0000000000..14e91c6382 --- /dev/null +++ b/src/api/buffer.h @@ -0,0 +1,135 @@ +#ifndef NEOVIM_API_BUFFER_H +#define NEOVIM_API_BUFFER_H + +#include <stdint.h> +#include <stdbool.h> + +#include "api/defs.h" + +/// Gets the buffer line count +/// +/// @param buffer The buffer handle +/// @param[out] err Details of an error that may have occurred +/// @return The line count +int64_t buffer_get_length(Buffer buffer, Error *err); + +/// Gets a buffer line +/// +/// @param buffer The buffer handle +/// @param index The line index +/// @param[out] err Details of an error that may have occurred +/// @return The line string +String buffer_get_line(Buffer buffer, int64_t index, Error *err); + +/// Sets a buffer line +/// +/// @param buffer The buffer handle +/// @param index The line index +/// @param line The new line +/// @param[out] err Details of an error that may have occurred +void buffer_set_line(Buffer buffer, int64_t index, String line, Error *err); + +/// Retrieves a line range from the buffer +/// +/// @param buffer The buffer handle +/// @param start The first line index +/// @param end The last line index(exclusive) +/// @param[out] err Details of an error that may have occurred +/// @return An array of lines +StringArray buffer_get_slice(Buffer buffer, + int64_t start, + int64_t end, + Error *err); + +/// Replaces a line range on the buffer +/// +/// @param buffer The buffer handle +/// @param start The first line index +/// @param end The last line index(exclusive) +/// @param lines An array of lines to use as replacement +/// @param[out] err Details of an error that may have occurred +void buffer_set_slice(Buffer buffer, + int64_t start, + int64_t end, + StringArray lines, + Error *err); + +/// Gets a buffer variable +/// +/// @param buffer The buffer handle +/// @param name The variable name +/// @param[out] err Details of an error that may have occurred +/// @return The variable value +Object buffer_get_var(Buffer buffer, String name, Error *err); + +/// Sets a buffer variable +/// +/// @param buffer The buffer handle +/// @param name The variable name +/// @param value The variable value +/// @param[out] err Details of an error that may have occurred +void buffer_set_var(Buffer buffer, String name, Object value, Error *err); + +/// Gets a buffer option value +/// +/// @param buffer The buffer handle +/// @param name The option name +/// @param[out] err Details of an error that may have occurred +/// @return The option value +String buffer_get_option(Buffer buffer, String name, Error *err); + +/// Sets a buffer option value +/// +/// @param buffer The buffer handle +/// @param name The option name +/// @param value The option value +/// @param[out] err Details of an error that may have occurred +void buffer_set_option(Buffer buffer, String name, String value, Error *err); + +/// Deletes a buffer option(falls back to the global value if available) +/// +/// @param buffer The buffer handle +/// @param name The option name +/// @param[out] err Details of an error that may have occurred +void buffer_del_option(Buffer buffer, String name, Error *err); + +/// Gets the full file name for the buffer +/// +/// @param buffer The buffer handle +/// @param[out] err Details of an error that may have occurred +/// @return The buffer name +String buffer_get_name(Buffer buffer, Error *err); + +/// Sets the full file name for a buffer +/// +/// @param buffer The buffer handle +/// @param name The buffer name +/// @param[out] err Details of an error that may have occurred +void buffer_set_name(Buffer buffer, String name, Error *err); + +/// Checks if a buffer is valid +/// +/// @param buffer The buffer handle +/// @return true if the buffer is valid, false otherwise +bool buffer_is_valid(Buffer buffer); + +/// Inserts a sequence of lines to a buffer at a certain index +/// +/// @param buffer The buffer handle +/// @param lines An array of lines +/// @param lnum Insert the lines before `lnum`. If negative, it will append +/// to the end of the buffer. +/// @param[out] err Details of an error that may have occurred +void buffer_insert(Buffer buffer, StringArray lines, int64_t lnum, Error *err); + +/// Creates a mark in the buffer and returns a tuple(row, col) representing +/// the position of the named mark +/// +/// @param buffer The buffer handle +/// @param name The mark's name +/// @param[out] err Details of an error that may have occurred +/// @return The (row, col) tuple +Position buffer_mark(Buffer buffer, String name, Error *err); + +#endif // NEOVIM_API_BUFFER_H + diff --git a/src/api/defs.h b/src/api/defs.h new file mode 100644 index 0000000000..fc1ac655ea --- /dev/null +++ b/src/api/defs.h @@ -0,0 +1,74 @@ +#ifndef NEOVIM_API_DEFS_H +#define NEOVIM_API_DEFS_H + +#include <stdint.h> +#include <string.h> + +// Basic types +typedef struct { + char msg[256]; + bool set; +} Error; + +typedef struct { + char *data; + size_t size; +} String; + +typedef uint16_t Buffer; +typedef uint16_t Window; +typedef uint16_t Tabpage; + +typedef struct object Object; + +typedef struct { + String *items; + size_t size; +} StringArray; + +typedef struct { + uint16_t row, col; +} Position; + +typedef struct { + Object *items; + size_t size; +} Array; + +typedef struct key_value_pair KeyValuePair; + +typedef struct { + KeyValuePair *items; + size_t size; +} Dictionary; + +typedef enum { + kObjectTypeNil, + kObjectTypeBool, + kObjectTypeInt, + kObjectTypeFloat, + kObjectTypeString, + kObjectTypeArray, + kObjectTypeDictionary +} ObjectType; + +struct object { + ObjectType type; + union { + bool boolean; + int64_t integer; + double floating_point; + String string; + Array array; + Dictionary dictionary; + } data; +}; + +struct key_value_pair { + String key; + Object value; +}; + + +#endif // NEOVIM_API_DEFS_H + diff --git a/src/api/tabpage.c b/src/api/tabpage.c new file mode 100644 index 0000000000..1bbde0d986 --- /dev/null +++ b/src/api/tabpage.c @@ -0,0 +1,32 @@ +#include <stdbool.h> +#include <stdint.h> +#include <stdlib.h> + +#include "api/tabpage.h" +#include "api/defs.h" + +int64_t tabpage_get_window_count(Tabpage tabpage, Error *err) +{ + abort(); +} + +Object tabpage_get_var(Tabpage tabpage, String name, Error *err) +{ + abort(); +} + +void tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err) +{ + abort(); +} + +Window tabpage_get_buffer(Tabpage tabpage, Error *err) +{ + abort(); +} + +bool tabpage_is_valid(Tabpage tabpage) +{ + abort(); +} + diff --git a/src/api/tabpage.h b/src/api/tabpage.h new file mode 100644 index 0000000000..5bfbf6cda3 --- /dev/null +++ b/src/api/tabpage.h @@ -0,0 +1,46 @@ +#ifndef NEOVIM_API_TABPAGE_H +#define NEOVIM_API_TABPAGE_H + +#include <stdint.h> +#include <stdbool.h> + +#include "api/defs.h" + +/// Gets the number of windows in a tabpage +/// +/// @param tabpage The tabpage +/// @param[out] err Details of an error that may have occurred +/// @return The number of windows in `tabpage` +int64_t tabpage_get_window_count(Tabpage tabpage, Error *err); + +/// Gets a tabpage variable +/// +/// @param tabpage The tab page handle +/// @param name The variable name +/// @param[out] err Details of an error that may have occurred +/// @return The variable value +Object tabpage_get_var(Tabpage tabpage, String name, Error *err); + +/// Sets a tabpage variable +/// +/// @param tabpage andle +/// @param name The variable name +/// @param value The variable value +/// @param[out] err Details of an error that may have occurred +void tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err); + +/// Gets the current window in a tab page +/// +/// @param tabpage The tab page handle +/// @param[out] err Details of an error that may have occurred +/// @return The Window handle +Window tabpage_get_buffer(Tabpage tabpage, Error *err); + +/// Checks if a tab page is valid +/// +/// @param tabpage The tab page handle +/// @return true if the tab page is valid, false otherwise +bool tabpage_is_valid(Tabpage tabpage); + +#endif // NEOVIM_API_TABPAGE_H + diff --git a/src/api/vim.c b/src/api/vim.c new file mode 100644 index 0000000000..aef4276f5b --- /dev/null +++ b/src/api/vim.c @@ -0,0 +1,140 @@ +#include <stdint.h> +#include <stdlib.h> + +#include "api/vim.h" +#include "api/defs.h" + +void vim_push_keys(String str) +{ + abort(); +} + +void vim_command(String str, Error *err) +{ + abort(); +} + +Object vim_eval(String str, Error *err) +{ + abort(); +} + +int64_t vim_strwidth(String str) +{ + abort(); +} + +StringArray vim_list_runtime_paths(void) +{ + abort(); +} + +void vim_change_directory(String dir) +{ + abort(); +} + +String vim_get_current_line(void) +{ + abort(); +} + +void vim_set_current_line(String line) +{ + abort(); +} + +Object vim_get_var(bool special, String name, Error *err) +{ + abort(); +} + +void vim_set_var(bool special, String name, Object value, Error *err) +{ + abort(); +} + +String vim_get_option(String name, Error *err) +{ + abort(); +} + +void vim_set_option(String name, String value, Error *err) +{ + abort(); +} + +void vim_del_option(String name, Error *err) +{ + abort(); +} + +void vim_out_write(String str) +{ + abort(); +} + +void vim_err_write(String str) +{ + abort(); +} + +int64_t vim_get_buffer_count(void) +{ + abort(); +} + +Buffer vim_get_buffer(int64_t num, Error *err) +{ + abort(); +} + +Buffer vim_get_current_buffer(void) +{ + abort(); +} + +void vim_set_current_buffer(Buffer buffer) +{ + abort(); +} + +int64_t vim_get_window_count(void) +{ + abort(); +} + +Window vim_get_window(int64_t num, Error *err) +{ + abort(); +} + +Window vim_get_current_window(void) +{ + abort(); +} + +void vim_set_current_window(Window window) +{ + abort(); +} + +int64_t vim_get_tabpage_count(void) +{ + abort(); +} + +Tabpage vim_get_tabpage(int64_t num, Error *err) +{ + abort(); +} + +Tabpage vim_get_current_tabpage(void) +{ + abort(); +} + +void vim_set_current_tabpage(Tabpage tabpage) +{ + abort(); +} diff --git a/src/api/vim.h b/src/api/vim.h new file mode 100644 index 0000000000..cc373e1cc2 --- /dev/null +++ b/src/api/vim.h @@ -0,0 +1,172 @@ +#ifndef NEOVIM_API_VIM_H +#define NEOVIM_API_VIM_H + +#include <stdint.h> +#include <stdbool.h> + +#include "api/defs.h" + +/// Send keys to vim input buffer, simulating user input. +/// +/// @param str The keys to send +void vim_push_keys(String str); + +/// Executes an ex-mode command str +/// +/// @param str The command str +/// @param[out] err Details of an error that may have occurred +void vim_command(String str, Error *err); + +/// Evaluates the expression str using the vim internal expression +/// evaluator (see |expression|). Returns the expression result as: +/// - a string if the Vim expression evaluates to a string or number +/// - a list if the Vim expression evaluates to a Vim list +/// - a dictionary if the Vim expression evaluates to a Vim dictionary +/// Dictionaries and lists are recursively expanded. +/// +/// @param str The expression str +/// @param[out] err Details of an error that may have occurred +/// @return The expanded object +Object vim_eval(String str, Error *err); + +/// Calculates the number of display cells `str` occupies, tab is counted as +/// one cell. +/// +/// @param str Some text +/// @return The number of cells +int64_t vim_strwidth(String str); + +/// Returns a list of paths contained in 'runtimepath' +/// +/// @return The list of paths +StringArray vim_list_runtime_paths(void); + +/// Changes vim working directory +/// +/// @param dir The new working directory +void vim_change_directory(String dir); + +/// Return the current line +/// +/// @return The current line string +String vim_get_current_line(void); + +/// Sets the current line +/// +/// @param line The line contents +void vim_set_current_line(String line); + +/// Gets a global or special variable +/// +/// @param special If it's a special(:v) variable +/// @param name The variable name +/// @param[out] err Details of an error that may have occurred +/// @return The variable value +Object vim_get_var(bool special, String name, Error *err); + +/// Sets a global or special variable +/// +/// @param special If it's a special(:v) variable +/// @param name The variable name +/// @param value The variable value +/// @param[out] err Details of an error that may have occurred +void vim_set_var(bool special, String name, Object value, Error *err); + +/// Get an option value string +/// +/// @param name The option name +/// @param[out] err Details of an error that may have occurred +/// @return The option value +String vim_get_option(String name, Error *err); + +/// Sets an option value +/// +/// @param name The option name +/// @param value The new option value +/// @param[out] err Details of an error that may have occurred +void vim_set_option(String name, String value, Error *err); + +/// Deletes an option, falling back to the default value +/// +/// @param name The option name +/// @param[out] err Details of an error that may have occurred +void vim_del_option(String name, Error *err); + +/// Write a message to vim output buffer +/// +/// @param str The message +void vim_out_write(String str); + +/// Write a message to vim error buffer +/// +/// @param str The message +void vim_err_write(String str); + +/// Gets the number of buffers +/// +/// @return The number of buffers +int64_t vim_get_buffer_count(void); + +/// Gets a buffer by index +/// +/// @param num The buffer number +/// @param[out] err Details of an error that may have occurred +/// @return The buffer handle +Buffer vim_get_buffer(int64_t num, Error *err); + +/// Return the current buffer +/// +/// @reqturn The buffer handle +Buffer vim_get_current_buffer(void); + +/// Sets the current buffer +/// +/// @param id The buffer handle +void vim_set_current_buffer(Buffer buffer); + +/// Gets the number of windows +/// +/// @return The number of windows +int64_t vim_get_window_count(void); + +/// Gets a window by index +/// +/// @param num The window number +/// @param[out] err Details of an error that may have occurred +/// @return The window handle +Window vim_get_window(int64_t num, Error *err); + +/// Return the current window +/// +/// @return The window handle +Window vim_get_current_window(void); + +/// Sets the current window +/// +/// @param handle The window handle +void vim_set_current_window(Window window); + +/// Gets the number of tab pages +/// +/// @return The number of tab pages +int64_t vim_get_tabpage_count(void); + +/// Gets a tab page by index +/// +/// @param num The tabpage number +/// @param[out] err Details of an error that may have occurred +/// @return The tab page handle +Tabpage vim_get_tabpage(int64_t num, Error *err); + +/// Return the current tab page +/// +/// @return The tab page handle +Tabpage vim_get_current_tabpage(void); + +/// Sets the current tab page +/// +/// @param handle The tab page handle +void vim_set_current_tabpage(Tabpage tabpage); + +#endif // NEOVIM_API_VIM_H + diff --git a/src/api/window.c b/src/api/window.c new file mode 100644 index 0000000000..fe59c2dc8b --- /dev/null +++ b/src/api/window.c @@ -0,0 +1,73 @@ +#include <stdbool.h> +#include <stdint.h> +#include <stdlib.h> + +#include "api/window.h" +#include "api/defs.h" + + +Buffer window_get_buffer(Window window, Error *err) +{ + abort(); +} + +Position window_get_cursor(Window window, Error *err) +{ + abort(); +} + +void window_set_cursor(Window window, Position pos, Error *err) +{ + abort(); +} + +int64_t window_get_height(Window window, Error *err) +{ + abort(); +} + +void window_set_height(Window window, int64_t height, Error *err) +{ + abort(); +} + +int64_t window_get_width(Window window, Error *err) +{ + abort(); +} + +Object window_get_var(Window window, String name, Error *err) +{ + abort(); +} + +void window_set_var(Window window, String name, Object value, Error *err) +{ + abort(); +} + +String window_get_option(Window window, String name, Error *err) +{ + abort(); +} + +void window_set_option(Window window, String name, String value, Error *err) +{ + abort(); +} + +Position window_get_pos(Window window, Error *err) +{ + abort(); +} + +Tabpage window_get_tabpage(Window window, Error *err) +{ + abort(); +} + +bool window_is_valid(Window window) +{ + abort(); +} + diff --git a/src/api/window.h b/src/api/window.h new file mode 100644 index 0000000000..c502b23951 --- /dev/null +++ b/src/api/window.h @@ -0,0 +1,105 @@ +#ifndef NEOVIM_API_WINDOW_H +#define NEOVIM_API_WINDOW_H + +#include <stdint.h> +#include <stdbool.h> + +#include "api/defs.h" + +/// Gets the current buffer in a window +/// +/// @param window The window handle +/// @param[out] err Details of an error that may have occurred +/// @return The buffer handle +Buffer window_get_buffer(Window window, Error *err); + +/// Gets the cursor position in the window +/// +/// @param window The window handle +/// @param[out] err Details of an error that may have occurred +/// @return the (row, col) tuple +Position window_get_cursor(Window window, Error *err); + +/// Sets the cursor position in the window +/// +/// @param window The window handle +/// @param pos the (row, col) tuple representing the new position +/// @param[out] err Details of an error that may have occurred +void window_set_cursor(Window window, Position pos, Error *err); + +/// Gets the window height +/// +/// @param window The window handle +/// @param[out] err Details of an error that may have occurred +/// @return the height in rows +int64_t window_get_height(Window window, Error *err); + +/// Sets the window height. This will only succeed if the screen is split +/// horizontally. +/// +/// @param window The window handle +/// @param height the new height in rows +/// @param[out] err Details of an error that may have occurred +void window_set_height(Window window, int64_t height, Error *err); + +/// Gets the window width +/// +/// @param window The window handle +/// @param[out] err Details of an error that may have occurred +/// @return the width in columns +int64_t window_get_width(Window window, Error *err); + +/// Gets a window variable +/// +/// @param window The window handle +/// @param name The variable name +/// @param[out] err Details of an error that may have occurred +/// @return The variable value +Object window_get_var(Window window, String name, Error *err); + +/// Sets a window variable +/// +/// @param window The window handle +/// @param name The variable name +/// @param value The variable value +/// @param[out] err Details of an error that may have occurred +void window_set_var(Window window, String name, Object value, Error *err); + +/// Gets a window option value +/// +/// @param window The window handle +/// @param name The option name +/// @param[out] err Details of an error that may have occurred +/// @return The option value +String window_get_option(Window window, String name, Error *err); + +/// Sets a window option value +/// +/// @param window The window handle +/// @param name The option name +/// @param value The option value +/// @param[out] err Details of an error that may have occurred +void window_set_option(Window window, String name, String value, Error *err); + +/// Gets the window position in display cells. First position is zero. +/// +/// @param window The window handle +/// @param[out] err Details of an error that may have occurred +/// @return The (row, col) tuple with the window position +Position window_get_pos(Window window, Error *err); + +/// Gets the window tab page +/// +/// @param window The window handle +/// @param[out] err Details of an error that may have occurred +/// @return The tab page that contains the window +Tabpage window_get_tabpage(Window window, Error *err); + +/// Checks if a window is valid +/// +/// @param window The window handle +/// @return true if the window is valid, false otherwise +bool window_is_valid(Window window); + +#endif // NEOVIM_API_WINDOW_H + |