diff options
| author | Laurence de Bruxelles <lfdebrux@gmail.com> | 2025-09-19 10:19:10 +0300 |
|---|---|---|
| committer | Randy Palamar <randy@rnpnr.xyz> | 2025-12-14 06:09:11 -0700 |
| commit | 992804cb27993d5de8e6830a8ab9268045ce6892 (patch) | |
| tree | b86c44c3154370d587c46050560516fcb10d9936 | |
| parent | 6c519e91c684838bebcc6d49d894af956f6815b4 (diff) | |
| download | vis-992804cb27993d5de8e6830a8ab9268045ce6892.tar.gz vis-992804cb27993d5de8e6830a8ab9268045ce6892.tar.xz | |
Use STYLE_WHITESPACE for spaces, newlines, and tabs
Allow theming the replacement characters shown for showspaces, showtabs,
and/or shownewlines.
| -rw-r--r-- | lua/vis.lua | 1 | ||||
| -rw-r--r-- | ui.h | 1 | ||||
| -rw-r--r-- | view.c | 23 | ||||
| -rw-r--r-- | vis-lua.c | 1 |
4 files changed, 21 insertions, 5 deletions
diff --git a/lua/vis.lua b/lua/vis.lua index 9ac41b0..42c536b 100644 --- a/lua/vis.lua +++ b/lua/vis.lua @@ -272,6 +272,7 @@ vis.types.window.set_syntax = function(win, syntax) win:style_define(win.STYLE_SEPARATOR, lexers.STYLE_SEPARATOR or '') win:style_define(win.STYLE_INFO, lexers.STYLE_INFO or '') win:style_define(win.STYLE_EOF, lexers.STYLE_EOF or '') + win:style_define(win.STYLE_WHITESPACE, lexers.STYLE_WHITESPACE or '') if syntax == nil or syntax == 'off' then win.syntax = nil @@ -48,6 +48,7 @@ enum UiStyle { UI_STYLE_SEPARATOR, UI_STYLE_INFO, UI_STYLE_EOF, + UI_STYLE_WHITESPACE, UI_STYLE_MAX, }; @@ -266,6 +266,9 @@ static bool view_add_cell(View *view, const Cell *cell) { } static bool view_expand_tab(View *view, Cell *cell) { + Win *win = (Win *)((char *)view - offsetof(Win, view)); + ui_window_style_set(&win->vis->ui, win->id, cell, UI_STYLE_WHITESPACE, false); + cell->width = 1; int displayed_width = view->tabwidth - (view->col % view->tabwidth); @@ -287,6 +290,9 @@ static bool view_expand_newline(View *view, Cell *cell) { size_t lineno = view->line->lineno; const char *symbol = view->symbols[SYNTAX_SYMBOL_EOL]; + Win *win = (Win *)((char *)view - offsetof(Win, view)); + ui_window_style_set(&win->vis->ui, win->id, cell, UI_STYLE_WHITESPACE, false); + strncpy(cell->data, symbol, sizeof(cell->data) - 1); cell->width = 1; if (!view_add_cell(view, cell)) @@ -299,6 +305,15 @@ static bool view_expand_newline(View *view, Cell *cell) { return true; } +static bool view_expand_space(View *view, Cell *cell) { + Win *win = (Win *)((char *)view - offsetof(Win, view)); + ui_window_style_set(&win->vis->ui, win->id, cell, UI_STYLE_WHITESPACE, false); + + const char *symbol = view->symbols[SYNTAX_SYMBOL_SPACE]; + strncpy(cell->data, symbol, sizeof(cell->data) - 1); + return view_add_cell(view, cell); +} + /* try to add another character to the view, return whether there was space left */ static bool view_addch(View *view, Cell *cell) { if (!view->line) @@ -318,11 +333,9 @@ static bool view_addch(View *view, Cell *cell) { return view_expand_tab(view, cell); case '\n': return view_expand_newline(view, cell); - case ' ': { - const char *symbol = view->symbols[SYNTAX_SYMBOL_SPACE]; - strncpy(cell->data, symbol, sizeof(cell->data) - 1); - return view_add_cell(view, cell); - }} + case ' ': + return view_expand_space(view, cell); + } if (ch < 128 && !isprint(ch)) { /* non-printable ascii char, represent it as ^(char + 64) */ @@ -3316,6 +3316,7 @@ static void vis_lua_init(Vis *vis) { { UI_STYLE_SEPARATOR, "STYLE_SEPARATOR" }, { UI_STYLE_INFO, "STYLE_INFO" }, { UI_STYLE_EOF, "STYLE_EOF" }, + { UI_STYLE_WHITESPACE, "STYLE_WHITESPACE" }, }; for (size_t i = 0; i < LENGTH(styles); i++) { |
