vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 198010135e69551a6f24cb72f2a38504ff3b19c4 parent 6e3e8ec849a03eef10aafebeee9cb7df3d7249e0 Author: Marc André Tanner <mat@brain-dump.org> Date: Fri, 10 Apr 2015 21:52:52 +0200 Make ":set syntax" without any argument display the currently active one Diffstat:
| M | vis.c | | | 14 | ++++++++++++-- |
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/vis.c b/vis.c @@ -1370,6 +1370,7 @@ static bool cmd_set(Filerange *range, enum CmdOpt cmdopt, const char *argv[]) { OPTION_TYPE_BOOL, OPTION_TYPE_NUMBER, } type; + bool optional; int index; } OptionDef; @@ -1387,7 +1388,7 @@ static bool cmd_set(Filerange *range, enum CmdOpt cmdopt, const char *argv[]) { [OPTION_AUTOINDENT] = { { "autoindent", "ai" }, OPTION_TYPE_BOOL }, [OPTION_EXPANDTAB] = { { "expandtab", "et" }, OPTION_TYPE_BOOL }, [OPTION_TABWIDTH] = { { "tabwidth", "tw" }, OPTION_TYPE_NUMBER }, - [OPTION_SYNTAX] = { { "syntax" }, OPTION_TYPE_STRING }, + [OPTION_SYNTAX] = { { "syntax" }, OPTION_TYPE_STRING, true }, [OPTION_NUMBER] = { { "numbers", "nu" }, OPTION_TYPE_BOOL }, [OPTION_NUMBER_RELATIVE] = { { "relativenumbers", "rnu" }, OPTION_TYPE_BOOL }, }; @@ -1432,7 +1433,7 @@ static bool cmd_set(Filerange *range, enum CmdOpt cmdopt, const char *argv[]) { switch (opt->type) { case OPTION_TYPE_STRING: - if (!argv[2]) { + if (!opt->optional && !argv[2]) { editor_info_show(vis, "Expecting string option value"); return false; } @@ -1468,6 +1469,15 @@ static bool cmd_set(Filerange *range, enum CmdOpt cmdopt, const char *argv[]) { editor_tabwidth_set(vis, arg.i); break; case OPTION_SYNTAX: + if (!argv[2]) { + Syntax *syntax = window_syntax_get(vis->win->win); + if (syntax) + editor_info_show(vis, "Syntax definition in use: `%s'", syntax->name); + else + editor_info_show(vis, "No syntax definition in use"); + return true; + } + for (Syntax *syntax = syntaxes; syntax && syntax->name; syntax++) { if (!strcasecmp(syntax->name, argv[2])) { window_syntax_set(vis->win->win, syntax);