diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-11-10 22:04:27 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-11-10 22:04:27 +0100 |
| commit | d0bf693ea5c1343495d627844c9e52f63cf0cca9 (patch) | |
| tree | 9e7b470e16305e6247a2fedbe12bad7acde83388 | |
| parent | 4d245d0a8f6c3d729509eab4fb40656d6d4e13b8 (diff) | |
| download | vis-d0bf693ea5c1343495d627844c9e52f63cf0cca9.tar.gz vis-d0bf693ea5c1343495d627844c9e52f63cf0cca9.tar.xz | |
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.
| -rw-r--r-- | README.md | 8 | ||||
| -rw-r--r-- | sam.c | 22 | ||||
| -rw-r--r-- | vis-cmds.c | 40 |
3 files changed, 34 insertions, 36 deletions
@@ -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 @@ -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" }, @@ -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) { |
