aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md8
-rw-r--r--sam.c22
-rw-r--r--vis-cmds.c40
3 files changed, 34 insertions, 36 deletions
diff --git a/README.md b/README.md
index 115917f..1eb5f66 100644
--- 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
index 883cfd9..5ebf71c 100644
--- 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
index ab4a4d2..16debea 100644
--- 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) {