vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 30e22e8cc2e0bf45872af8fe9c1f4858f08ec32f
parent 0710990abd7bb3333092f70ae51c80fc207c2dee
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sun, 14 Sep 2014 15:23:08 +0200

Display current mode in window statusbar

For now just display the modes which start with '-'. I want to keep
the descriptive names of the other modes available for debugging
purposes.

Diffstat:
Mconfig.def.h | 19++++++++++++-------
Mvis.c | 6++----
2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -61,13 +61,15 @@ static Command cmds[] = { }; /* draw a statubar, do whatever you want with win->statuswin curses window */ -static void vis_statusbar(EditorWin *win) { +static void statusbar(EditorWin *win) { size_t line, col; bool focused = vis->win == win || vis->prompt->editor == win; window_cursor_getxy(win->win, &line, &col); wattrset(win->statuswin, focused ? A_REVERSE|A_BOLD : A_REVERSE); mvwhline(win->statuswin, 0, 0, ' ', win->width); - mvwprintw(win->statuswin, 0, 0, "%s %s", text_filename_get(win->text), + mvwprintw(win->statuswin, 0, 0, "%s %s %s", + mode->name && mode->name[0] == '-' ? mode->name : "", + text_filename_get(win->text), text_modified(win->text) ? "[+]" : ""); char buf[win->width + 1]; int len = snprintf(buf, win->width, "%d, %d", line, col); @@ -600,7 +602,7 @@ static Mode vis_modes[] = { .bindings = vis_mode_normal, }, [VIS_MODE_VISUAL] = { - .name = "VISUAL", + .name = "--VISUAL--", .parent = &vis_modes[VIS_MODE_REGISTER], .bindings = vis_mode_visual, .enter = vis_mode_visual_enter, @@ -625,7 +627,7 @@ static Mode vis_modes[] = { .bindings = vis_mode_insert_register, }, [VIS_MODE_INSERT] = { - .name = "INSERT", + .name = "--INSERT--", .parent = &vis_modes[VIS_MODE_INSERT_REGISTER], .bindings = vis_mode_insert, .leave = vis_mode_insert_leave, @@ -633,7 +635,7 @@ static Mode vis_modes[] = { .idle = vis_mode_insert_idle, }, [VIS_MODE_REPLACE] = { - .name = "REPLACE", + .name = "--REPLACE--", .parent = &vis_modes[VIS_MODE_INSERT], .bindings = vis_mode_replace, .leave = vis_mode_replace_leave, @@ -714,17 +716,20 @@ static Config editors[] = { { .name = "vis", .mode = &vis_modes[VIS_MODE_NORMAL], - .statusbar = vis_statusbar, + .statusbar = statusbar, .keypress = vis_keypress, }, { .name = "nano", .mode = &nano[1], - .statusbar = vis_statusbar, + .statusbar = statusbar, .keypress = vis_keypress, }, }; +/* default editor configuration to use */ +static Config *config = &editors[0]; + /* Color definitions, by default the i-th color is used for the i-th syntax * rule below. A color value of -1 specifies the default terminal color. */ diff --git a/vis.c b/vis.c @@ -887,6 +887,8 @@ static void switchmode_to(Mode *new_mode) { mode_prev = mode; //fprintf(stderr, "%s -> %s\n", mode_prev->name, new_mode->name); mode = new_mode; + if (mode == config->mode || (mode->name && mode->name[0] == '-')) + statusbar(vis->win); if (mode->enter) mode->enter(mode_prev); // TODO display mode name somewhere? @@ -1070,10 +1072,6 @@ static bool exec_command(char *cmdline) { return true; } -/* default editor configuration to use */ -static Config *config = &editors[0]; - - typedef struct Screen Screen; static struct Screen { int w, h;