diff options
| -rw-r--r-- | main.c | 21 | ||||
| -rw-r--r-- | vis.c | 23 | ||||
| -rw-r--r-- | vis.h | 8 |
3 files changed, 24 insertions, 28 deletions
@@ -87,8 +87,6 @@ static const char *insert_register(Vis*, const char *keys, const Arg *arg); /* show a user prompt to get input with title arg->s */ static const char *prompt_search(Vis*, const char *keys, const Arg *arg); static const char *prompt_cmd(Vis*, const char *keys, const Arg *arg); -/* evaluate user input at prompt, perform search or execute a command */ -static const char *prompt_enter(Vis*, const char *keys, const Arg *arg); /* exit command mode if the last char is deleted */ static const char *prompt_backspace(Vis*, const char *keys, const Arg *arg); /* blocks to read 3 consecutive digits and inserts the corresponding byte value */ @@ -764,7 +762,7 @@ static KeyAction vis_action[] = { [VIS_ACTION_PROMPT_ENTER] = { "prompt-enter", "Execute current prompt content", - prompt_enter + call, { .f = vis_prompt_enter } }, [VIS_ACTION_PROMPT_SHOW_VISUAL] = { "prompt-show-visual", @@ -1369,25 +1367,10 @@ static const char *prompt_cmd(Vis *vis, const char *keys, const Arg *arg) { return keys; } -static const char *prompt_enter(Vis *vis, const char *keys, const Arg *arg) { - char *s = vis_prompt_get(vis); - /* it is important to switch back to the previous mode, which hides - * the prompt and more importantly resets vis->win to the currently - * focused editor window *before* anything is executed which depends - * on vis->win. - */ - vis_mode_set(vis, vis->mode_before_prompt); - if (s && *s && vis_prompt_cmd(vis, vis->prompt_type, s) && vis->running) - vis_mode_switch(vis, VIS_MODE_NORMAL); - free(s); - vis_draw(vis); - return keys; -} - static const char *prompt_backspace(Vis *vis, const char *keys, const Arg *arg) { char *cmd = vis_prompt_get(vis); if (!cmd || !*cmd) - prompt_enter(vis, keys, NULL); + vis_mode_switch(vis, VIS_MODE_NORMAL); else delete(vis, keys, &(const Arg){ .i = MOVE_CHAR_PREV }); free(cmd); @@ -126,6 +126,7 @@ typedef struct { /* command definitions for the ':'-prompt */ enum CmdOpt opt; /* command option flags */ } Command; +static void mode_set(Vis *vis, Mode *new_mode); /** window / file handling */ static void file_free(Vis *vis, File *file) { @@ -766,7 +767,7 @@ static void vis_mode_operator_leave(Vis *vis, Mode *new) { static void vis_mode_operator_input(Vis *vis, const char *str, size_t len) { /* invalid operator */ action_reset(vis, &vis->action); - vis_mode_set(vis, vis->mode_prev); + mode_set(vis, vis->mode_prev); } static void vis_mode_visual_enter(Vis *vis, Mode *old) { @@ -1513,7 +1514,7 @@ static void action_do(Vis *vis, Action *a) { if (a->op == &ops[OP_CHANGE]) vis_mode_switch(vis, VIS_MODE_INSERT); else if (vis->mode == &vis_modes[VIS_MODE_OPERATOR]) - vis_mode_set(vis, vis->mode_prev); + mode_set(vis, vis->mode_prev); else if (vis->mode->visual) vis_mode_switch(vis, VIS_MODE_NORMAL); text_snapshot(txt); @@ -1536,7 +1537,7 @@ static void action_reset(Vis *vis, Action *a) { a->reg = NULL; } -void vis_mode_set(Vis *vis, Mode *new_mode) { +static void mode_set(Vis *vis, Mode *new_mode) { if (vis->mode == new_mode) return; if (vis->mode->leave) @@ -2851,7 +2852,7 @@ bool vis_operator(Vis *vis, enum VisOperator id) { } void vis_mode_switch(Vis *vis, enum VisMode mode) { - vis_mode_set(vis, &vis_modes[mode]); + mode_set(vis, &vis_modes[mode]); } bool vis_motion(Vis *vis, enum VisMotion motion, ...) { @@ -3075,3 +3076,17 @@ void vis_insert_nl(Vis *vis) { if (vis->autoindent) copy_indent_from_previous_line(vis->win); } + +void vis_prompt_enter(Vis *vis) { + char *s = vis_prompt_get(vis); + /* it is important to switch back to the previous mode, which hides + * the prompt and more importantly resets vis->win to the currently + * focused editor window *before* anything is executed which depends + * on vis->win. + */ + mode_set(vis, vis->mode_before_prompt); + if (s && *s && vis_prompt_cmd(vis, vis->prompt_type, s) && vis->running) + vis_mode_switch(vis, VIS_MODE_NORMAL); + free(s); + vis_draw(vis); +} @@ -44,8 +44,6 @@ typedef struct { const char *alias; } KeyBinding; - - Vis *vis_new(Ui*); void vis_free(Vis*); void vis_resize(Vis*); @@ -77,6 +75,8 @@ void vis_window_next(Vis*); void vis_window_prev(Vis*); /* display a user prompt with a certain title and default text */ void vis_prompt_show(Vis*, const char *title, const char *text); +/* TODO: bad abstraction */ +void vis_prompt_enter(Vis*); /* hide the user prompt if it is currently shown */ void vis_prompt_hide(Vis*); /* return the content of the command prompt in a malloc(3)-ed string @@ -124,9 +124,6 @@ bool vis_mode_map(Vis*, enum VisMode, const char *name, KeyBinding*); bool vis_mode_unmap(Vis*, enum VisMode, const char *name); bool vis_mode_bindings(Vis*, enum VisMode, KeyBinding **bindings); const char *vis_mode_status(Vis*); -/* TODO: temporary */ -typedef struct Mode Mode; -void vis_mode_set(Vis*, Mode*); bool vis_action_register(Vis*, KeyAction*); @@ -335,6 +332,7 @@ bool vis_signal_handler(Vis*, int signum, const siginfo_t *siginfo, const void *context); /* TODO: temporary */ +typedef struct Mode Mode; typedef struct Operator Operator; typedef struct Movement Movement; typedef struct TextObject TextObject; |
