diff options
| author | Evan Gates <evan@gnarbox.com> | 2020-09-18 12:05:27 -0700 |
|---|---|---|
| committer | Evan Gates <evan@gnarbox.com> | 2020-09-19 09:49:48 -0700 |
| commit | e938326eee9781d340ae3704a742d5e3bad95cb6 (patch) | |
| tree | 014bc26df53c5a2be8812da679b25ec7618b6269 | |
| parent | 2290224c844775d446fc8aaf3a98c0149d935875 (diff) | |
| download | vis-e938326eee9781d340ae3704a742d5e3bad95cb6.tar.gz vis-e938326eee9781d340ae3704a742d5e3bad95cb6.tar.xz | |
Add ignorecase option
Add a global ignorecase boolean option. When set add REG_ICASE to cflags
when calling text_regex_compile().
| -rw-r--r-- | man/vis.1 | 2 | ||||
| -rw-r--r-- | sam.c | 6 | ||||
| -rw-r--r-- | vis-cmds.c | 3 | ||||
| -rw-r--r-- | vis-core.h | 1 | ||||
| -rw-r--r-- | vis-prompt.c | 3 | ||||
| -rw-r--r-- | vis.c | 3 |
6 files changed, 16 insertions, 2 deletions
@@ -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 @@ -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) { @@ -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; @@ -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 index fd57a04..bb1db39 100644 --- 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) @@ -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; } |
