vis

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

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

commit 0cb20e1558fc3007275513eb1996225fac6f812d
parent af0a4b282beba31702edb72ff9794ecb4e663569
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Thu, 10 Nov 2016 22:04:27 +0100

vis: split `:set show <option>` into separate options

It was the only command option which needed `=` to assign a value to.
This unifies the argument parsing logic and adds the possibility to
specify a per-option help text.

You might want to adapt your visrc.lua configuration accordingly.

Diffstat:
MREADME.md | 8+++-----
Msam.c | 22+++++++++++++++++-----
Mvis-cmds.c | 40++++++++++++++--------------------------
3 files changed, 34 insertions(+), 36 deletions(-)

diff --git a/README.md b/README.md @@ -429,14 +429,12 @@ Operators can be forced to work line wise by specifying `V`. use syntax definition given (e.g. "ansi_c") or disable syntax highlighting if no such definition exists (e.g :set syntax off) - show + show-spaces (yes|no) default no + show-tabs (yes|no) default no + show-newlines (yes|no) default no show/hide special white space replacement symbols - newlines = [0|1] default 0 - tabs = [0|1] default 0 - spaces = [0|1] default 0 - cursorline (yes|no) default no highlight the line on which the cursor currently resides diff --git a/sam.c b/sam.c @@ -202,7 +202,9 @@ enum { OPTION_TABWIDTH, OPTION_THEME, OPTION_SYNTAX, - OPTION_SHOW, + OPTION_SHOW_SPACES, + OPTION_SHOW_TABS, + OPTION_SHOW_NEWLINES, OPTION_NUMBER, OPTION_NUMBER_RELATIVE, OPTION_CURSOR_LINE, @@ -236,10 +238,20 @@ static const OptionDef options[] = { OPTION_TYPE_STRING, OPTION_FLAG_WINDOW|OPTION_FLAG_OPTIONAL, "Syntax highlighting lexer to use filename without extension", }, - [OPTION_SHOW] = { - { "show" }, - OPTION_TYPE_STRING, OPTION_FLAG_WINDOW, - "Show white space replacement symbols", + [OPTION_SHOW_SPACES] = { + { "show-spaces" }, + OPTION_TYPE_BOOL, OPTION_FLAG_WINDOW, + "Display replacement symbol instead of a space", + }, + [OPTION_SHOW_TABS] = { + { "show-tabs" }, + OPTION_TYPE_BOOL, OPTION_FLAG_WINDOW, + "Display replacement symbol for tabs", + }, + [OPTION_SHOW_NEWLINES] = { + { "show-newlines" }, + OPTION_TYPE_BOOL, OPTION_FLAG_WINDOW, + "Display replacement symbol for newlines", }, [OPTION_NUMBER] = { { "numbers", "nu" }, diff --git a/vis-cmds.c b/vis-cmds.c @@ -148,7 +148,8 @@ static bool cmd_set(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor break; } - switch (opt - options) { + size_t opt_index = opt - options; + switch (opt_index) { case OPTION_EXPANDTAB: vis->expandtab = arg.b; break; @@ -175,36 +176,23 @@ static bool cmd_set(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor return false; } break; - case OPTION_SHOW: - if (!argv[2]) { - vis_info_show(vis, "Expecting: spaces, tabs, newlines"); - return false; - } - const char *keys[] = { "spaces", "tabs", "newlines" }; + case OPTION_SHOW_SPACES: + case OPTION_SHOW_TABS: + case OPTION_SHOW_NEWLINES: + { const int values[] = { - UI_OPTION_SYMBOL_SPACE, - UI_OPTION_SYMBOL_TAB|UI_OPTION_SYMBOL_TAB_FILL, - UI_OPTION_SYMBOL_EOL, + [OPTION_SHOW_SPACES] = UI_OPTION_SYMBOL_SPACE, + [OPTION_SHOW_TABS] = UI_OPTION_SYMBOL_TAB|UI_OPTION_SYMBOL_TAB_FILL, + [OPTION_SHOW_NEWLINES] = UI_OPTION_SYMBOL_EOL, }; int flags = view_options_get(win->view); - for (const char **args = &argv[2]; *args; args++) { - for (int i = 0; i < LENGTH(keys); i++) { - if (strcmp(*args, keys[i]) == 0) { - flags |= values[i]; - } else if (strstr(*args, keys[i]) == *args) { - bool show; - const char *v = *args + strlen(keys[i]); - if (*v == '=' && parse_bool(v+1, &show)) { - if (show) - flags |= values[i]; - else - flags &= ~values[i]; - } - } - } - } + if (arg.b) + flags |= values[opt_index]; + else + flags &= ~values[opt_index]; view_options_set(win->view, flags); break; + } case OPTION_NUMBER: { enum UiOption opt = view_options_get(win->view); if (arg.b) {