aboutsummaryrefslogtreecommitdiff
path: root/editor.h
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-10-26 09:23:48 +0100
committerMarc André Tanner <mat@brain-dump.org>2015-10-26 15:04:42 +0100
commite912a488cbb9065700316ff0f34cde183c90cbfc (patch)
tree870de5f63a4c1ce501b72897bd0d0f91f65ce4ca /editor.h
parent5958d1e993298920deb02bf61eeb351ca768e3e4 (diff)
downloadvis-e912a488cbb9065700316ff0f34cde183c90cbfc.tar.gz
vis-e912a488cbb9065700316ff0f34cde183c90cbfc.tar.xz
vis: merge editor.c into vis.c
Diffstat (limited to 'editor.h')
-rw-r--r--editor.h339
1 files changed, 0 insertions, 339 deletions
diff --git a/editor.h b/editor.h
deleted file mode 100644
index abb0b57..0000000
--- a/editor.h
+++ /dev/null
@@ -1,339 +0,0 @@
-#ifndef EDITOR_H
-#define EDITOR_H
-
-#include <signal.h>
-#include <stddef.h>
-#include <stdbool.h>
-#include <setjmp.h>
-
-typedef struct Editor Editor;
-typedef Editor Vis;
-typedef struct File File;
-typedef struct Win Win;
-
-#include "ui.h"
-#include "view.h"
-#include "register.h"
-#include "macro.h"
-#include "syntax.h"
-#include "ring-buffer.h"
-#include "map.h"
-#include "text-regex.h"
-
-typedef union {
- bool b;
- int i;
- const char *s;
- void (*w)(View*); /* generic window commands */
- void (*f)(Editor*); /* generic editor commands */
-} Arg;
-
-typedef struct {
- const char *name;
- const char *help;
- const char* (*func)(Vis*, const char *keys, const Arg*);
- /* returns a pointer to the first not consumed character in keys
- * or NULL if not enough input was available to complete the command */
- const Arg arg;
-
-} KeyAction;
-
-typedef struct {
- const char *key;
- KeyAction *action;
- const char *alias;
-} KeyBinding;
-
-/* a mode contains a set of key bindings which are currently valid.
- *
- * each mode can specify one parent mode which is consultated if a given key
- * is not found in the current mode. hence the modes form a tree which is
- * searched from the current mode up towards the root mode until a valid binding
- * is found.
- *
- * if no binding is found, mode->input(...) is called and the user entered
- * keys are passed as argument. this is used to change the document content.
- */
-typedef struct Mode Mode;
-struct Mode {
- Mode *parent; /* if no match is found in this mode, search will continue there */
- Map *bindings;
- KeyBinding *default_bindings;
- const char *name; /* descriptive, user facing name of the mode */
- const char *status; /* name displayed in the window status bar */
- const char *help; /* short description used by :help */
- bool isuser; /* whether this is a user or internal mode */
- void (*enter)(Vis*, Mode *old); /* called right before the mode becomes active */
- void (*leave)(Vis*, Mode *new); /* called right before the mode becomes inactive */
- void (*input)(Vis*, const char*, size_t); /* called whenever a key is not found in this mode and all its parent modes */
- void (*idle)(Vis*); /* called whenever a certain idle time i.e. without any user input elapsed */
- time_t idle_timeout; /* idle time in seconds after which the registered function will be called */
- bool visual; /* whether text selection is possible in this mode */
-};
-
-typedef struct {
- int count; /* how many times should the command be executed? */
- Register *reg; /* always non-NULL, set to a default register */
- Filerange range; /* which part of the file should be affected by the operator */
- size_t pos; /* at which byte from the start of the file should the operation start? */
- bool linewise; /* should the changes always affect whole lines? */
- const Arg *arg; /* arbitrary arguments */
-} OperatorContext;
-
-typedef struct {
- size_t (*func)(Vis*, Text*, OperatorContext*); /* operator logic, returns new cursor position */
-} Operator;
-
-typedef struct {
- /* TODO: merge types / use union to save space */
- size_t (*cur)(Cursor*); /* a movement based on current window content from view.h */
- size_t (*txt)(Text*, size_t pos); /* a movement form text-motions.h */
- size_t (*file)(Vis*, File*, size_t pos);
- size_t (*vis)(Vis*, Text*, size_t pos);
- size_t (*view)(Vis*, View*);
- size_t (*win)(Vis*, Win*, size_t pos);
- enum {
- LINEWISE = 1 << 0,
- CHARWISE = 1 << 1,
- INCLUSIVE = 1 << 2,
- EXCLUSIVE = 1 << 3,
- IDEMPOTENT = 1 << 4,
- JUMP = 1 << 5,
- } type;
- int count;
-} Movement;
-
-typedef struct {
- Filerange (*range)(Text*, size_t pos); /* a text object from text-objects.h */
- enum {
- INNER,
- OUTER,
- } type;
-} TextObject;
-
-typedef struct { /** collects all information until an operator is executed */
- int count;
- int type;
- const Operator *op;
- const Movement *movement;
- const TextObject *textobj;
- Register *reg;
- int mark;
- Arg arg;
-} Action;
-
-enum CmdOpt { /* option flags for command definitions */
- CMD_OPT_NONE, /* no option (default value) */
- CMD_OPT_FORCE, /* whether the command can be forced by appending '!' */
- CMD_OPT_ARGS, /* whether the command line should be parsed in to space
- * separated arguments to placed into argv, otherwise argv[1]
- * will contain the remaining command line unmodified */
-};
-
-typedef struct { /* command definitions for the ':'-prompt */
- const char *name[3]; /* name and optional alias for the command */
- /* command logic called with a NULL terminated array of arguments.
- * argv[0] will be the command name */
- bool (*cmd)(Vis*, Filerange*, enum CmdOpt opt, const char *argv[]);
- enum CmdOpt opt; /* command option flags */
-} Command;
-
-enum Reg {
- REG_a,
- REG_b,
- REG_c,
- REG_d,
- REG_e,
- REG_f,
- REG_g,
- REG_h,
- REG_i,
- REG_j,
- REG_k,
- REG_l,
- REG_m,
- REG_n,
- REG_o,
- REG_p,
- REG_q,
- REG_r,
- REG_s,
- REG_t,
- REG_u,
- REG_v,
- REG_w,
- REG_x,
- REG_y,
- REG_z,
- REG_DEFAULT,
- REG_LAST,
-};
-
-enum Mark {
- MARK_a,
- MARK_b,
- MARK_c,
- MARK_d,
- MARK_e,
- MARK_f,
- MARK_g,
- MARK_h,
- MARK_i,
- MARK_j,
- MARK_k,
- MARK_l,
- MARK_m,
- MARK_n,
- MARK_o,
- MARK_p,
- MARK_q,
- MARK_r,
- MARK_s,
- MARK_t,
- MARK_u,
- MARK_v,
- MARK_w,
- MARK_x,
- MARK_y,
- MARK_z,
- MARK_SELECTION_START,
- MARK_SELECTION_END,
- MARK_INVALID,
-};
-
-struct File {
- Text *text;
- const char *name;
- volatile sig_atomic_t truncated;
- bool is_stdin;
- struct stat stat;
- int refcount;
- Mark marks[MARK_INVALID];
- File *next, *prev;
-};
-
-typedef struct {
- time_t state; /* state of the text, used to invalidate change list */
- size_t index; /* #number of changes */
- size_t pos; /* where the current change occured */
-} ChangeList;
-
-struct Win {
- Editor *editor; /* editor instance to which this window belongs */
- UiWin *ui;
- File *file; /* file being displayed in this window */
- View *view; /* currently displayed part of underlying text */
- ViewEvent events;
- RingBuffer *jumplist; /* LRU jump management */
- ChangeList changelist; /* state for iterating through least recently changes */
- Win *prev, *next; /* neighbouring windows */
-};
-
-#define MACRO_LAST 26
-
-struct Editor {
- Ui *ui;
- File *files;
- Win *windows; /* list of windows */
- Win *win; /* currently active window */
- Syntax *syntaxes; /* NULL terminated array of syntax definitions */
- Register registers[REG_LAST]; /* register used for copy and paste */
- Macro macros[MACRO_LAST]; /* recorded macros */
- Macro *recording, *last_recording;/* currently and least recently recorded macro */
- Win *prompt; /* 1-line height window to get user input */
- Win *prompt_window; /* window which was focused before prompt was shown */
- char prompt_type; /* command ':' or search '/','?' prompt */
- Regex *search_pattern; /* last used search pattern */
- char search_char[8]; /* last used character to search for via 'f', 'F', 't', 'T' */
- int last_totill; /* last to/till movement used for ';' and ',' */
- int tabwidth; /* how many spaces should be used to display a tab */
- bool expandtab; /* whether typed tabs should be converted to spaces */
- bool autoindent; /* whether indentation should be copied from previous line on newline */
- Map *cmds; /* ":"-commands, used for unique prefix queries */
- Map *options; /* ":set"-options */
- Buffer buffer_repeat; /* holds data to repeat last insertion/replacement */
- Buffer input_queue; /* holds pending input keys */
-
- Action action; /* current action which is in progress */
- Action action_prev; /* last operator action used by the repeat '.' key */
- Mode *mode; /* currently active mode, used to search for keybindings */
- Mode *mode_prev; /* previsouly active user mode */
- Mode *mode_before_prompt; /* user mode which was active before entering prompt */
- volatile bool running; /* exit main loop once this becomes false */
- volatile sig_atomic_t cancel_filter; /* abort external command */
- volatile sig_atomic_t sigbus;
- sigjmp_buf sigbus_jmpbuf;
- Map *actions; /* built in special editor keys / commands */
-};
-
-Editor *editor_new(Ui*);
-void editor_free(Editor*);
-void editor_resize(Editor*);
-void editor_draw(Editor*);
-void editor_update(Editor*);
-void editor_suspend(Editor*);
-
-bool editor_mode_bindings(Mode*, KeyBinding**);
-bool editor_mode_map(Mode*, const char *name, KeyBinding*);
-bool editor_mode_unmap(Mode*, const char *name);
-
-bool editor_action_register(Editor*, KeyAction*);
-
-/* these function operate on the currently focused window but make sure
- * that all windows which show the affected region are redrawn too. */
-void editor_insert_key(Editor*, const char *data, size_t len);
-void editor_replace_key(Editor*, const char *data, size_t len);
-void editor_insert(Editor*, size_t pos, const char *data, size_t len);
-void editor_delete(Editor*, size_t pos, size_t len);
-void editor_replace(Editor*, size_t pos, const char *data, size_t len);
-
-/* set tabwidth (must be in range [1, 8], affects all windows */
-void editor_tabwidth_set(Editor*, int tabwidth);
-int editor_tabwidth_get(Editor*);
-
-/* load a set of syntax highlighting definitions which will be associated
- * to the underlying window based on the file type loaded.
- *
- * The parameter `syntaxes' has to point to a NULL terminated array.
- */
-bool editor_syntax_load(Editor*, Syntax *syntaxes);
-void editor_syntax_unload(Editor*);
-
-/* creates a new window, and loads the given file. if filename is NULL
- * an unamed / empty buffer is created. If the given file is already opened
- * in another window, share the underlying text that is changes will be
- * visible in both windows */
-bool editor_window_new(Editor*, const char *filename);
-/* reload the file currently displayed in the window from disk */
-bool editor_window_reload(Win*);
-void editor_window_close(Win*);
-/* split the given window. changes to the displayed text will be reflected
- * in both windows */
-bool editor_window_split(Win*);
-/* focus the next / previous window */
-void editor_window_next(Editor*);
-void editor_window_prev(Editor*);
-/* set the filename of the file displayed in this window */
-void editor_window_name(Win*, const char *filename);
-
-/* rearrange all windows either vertically or horizontally */
-void editor_windows_arrange(Editor*, enum UiLayout);
-/* display a user prompt with a certain title and default text */
-void editor_prompt_show(Editor*, const char *title, const char *text);
-/* hide the user prompt if it is currently shown */
-void editor_prompt_hide(Editor*);
-/* return the content of the command prompt in a malloc(3)-ed string
- * which the call site has to free. */
-char *editor_prompt_get(Editor*);
-/* replace the current command line content with the one given */
-void editor_prompt_set(Editor*, const char *line);
-
-/* display a message to the user */
-void editor_info_show(Editor*, const char *msg, ...);
-void editor_info_hide(Editor*);
-
-/* look up a curses color pair for the given combination of fore and
- * background color */
-short editor_color_get(short fg, short bg);
-
-#endif