vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 45d0ef8203f015bd0e85b3e6b4bb7044ca1cf418 parent 0ee7d823dc01acde3e057e06b6044e218f725fca Author: Evan Gates <evan@gnarbox.com> Date: Fri, 18 Sep 2020 12:05:27 -0700 Add ignorecase option Add a global ignorecase boolean option. When set add REG_ICASE to cflags when calling text_regex_compile(). Diffstat:
| M | man/vis.1 | | | 2 | ++ |
| M | sam.c | | | 6 | ++++++ |
| M | vis-cmds.c | | | 3 | +++ |
| M | vis-core.h | | | 1 | + |
| M | vis-prompt.c | | | 3 | ++- |
| M | vis.c | | | 3 | ++- |
6 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/man/vis.1 b/man/vis.1 @@ -1409,6 +1409,8 @@ lager ones. WARNING: modifying a memory mapped file in-place will cause data loss. .It Ic layout Op Do v Dc or Do h Dc Whether to use vertical or horizontal layout. +.It Cm ignorecase , Cm ic Op Cm off +Whether to ignore case when searching. .El . .Sh COMMAND and SEARCH PROMPT diff --git a/sam.c b/sam.c @@ -300,6 +300,7 @@ enum { OPTION_LOAD_METHOD, OPTION_CHANGE_256COLORS, OPTION_LAYOUT, + OPTION_IGNORECASE, }; static const OptionDef options[] = { @@ -388,6 +389,11 @@ static const OptionDef options[] = { VIS_OPTION_TYPE_STRING, VIS_HELP("Vertical or horizontal window layout") }, + [OPTION_IGNORECASE] = { + { "ignorecase", "ic" }, + VIS_OPTION_TYPE_BOOL, + VIS_HELP("Ignore case when searching") + }, }; bool sam_init(Vis *vis) { diff --git a/vis-cmds.c b/vis-cmds.c @@ -361,6 +361,9 @@ static bool cmd_set(Vis *vis, Win *win, Command *cmd, const char *argv[], Select windows_arrange(vis, layout); break; } + case OPTION_IGNORECASE: + vis->ignorecase = toggle ? !vis->ignorecase : arg.b; + break; default: if (!opt->func) return false; diff --git a/vis-core.h b/vis-core.h @@ -221,6 +221,7 @@ struct Vis { Array motions; Array textobjects; Array bindings; + bool ignorecase; /* whether to ignore case when searching */ }; enum VisEvents { diff --git a/vis-prompt.c b/vis-prompt.c @@ -63,7 +63,8 @@ static const char *prompt_enter(Vis *vis, const char *keys, const Arg *arg) { pattern = "^:"; else if (prompt->file == vis->search_file) pattern = "^(/|\\?)"; - if (pattern && regex && text_regex_compile(regex, pattern, REG_EXTENDED|REG_NEWLINE) == 0) { + int cflags = REG_EXTENDED|REG_NEWLINE|(REG_ICASE*vis->ignorecase); + if (pattern && regex && text_regex_compile(regex, pattern, cflags) == 0) { size_t end = text_line_end(txt, pos); size_t prev = text_search_backward(txt, end, regex); if (prev > pos) diff --git a/vis.c b/vis.c @@ -1685,7 +1685,8 @@ Regex *vis_regex(Vis *vis, const char *pattern) { Regex *regex = text_regex_new(); if (!regex) return NULL; - if (text_regex_compile(regex, pattern, REG_EXTENDED|REG_NEWLINE) != 0) { + int cflags = REG_EXTENDED|REG_NEWLINE|(REG_ICASE*vis->ignorecase); + if (text_regex_compile(regex, pattern, cflags) != 0) { text_regex_free(regex); return NULL; }