vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit bef80e205150792c21396e835f03c8028caf5258 parent 760c4f9ad25a7135c1229cbf967dca00d561d485 Author: Marc André Tanner <mat@brain-dump.org> Date: Thu, 11 Feb 2016 10:47:28 +0100 vis: try to make * and # motions work on more systems The used regular expression \<%s\> where %s refers to the search term/word under cursor is not POSIX compliant but happens to work on both musl and glibc. First try the alternate syntax [[:<:]]%s[[:>:]] which works on Mac OS X. The reason it is done in this order is that musl/glibc will reject it as invalid pattern when compiling while the Mac OS X libc will accept \<%s\> but not match anything. Based on a patch by Erlend Fagerheim. Diffstat:
| M | vis-motions.c | | | 9 | +++++++-- |
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/vis-motions.c b/vis-motions.c @@ -16,9 +16,14 @@ static bool search_word(Vis *vis, Text *txt, size_t pos) { char *buf = text_bytes_alloc0(txt, word.start, text_range_size(&word)); if (!buf) return false; - snprintf(expr, sizeof(expr), "\\<%s\\>", buf); + snprintf(expr, sizeof(expr), "[[:<:]]%s[[:>:]]", buf); + bool ret = text_regex_compile(vis->search_pattern, expr, REG_EXTENDED) == 0; + if (!ret) { + snprintf(expr, sizeof(expr), "\\<%s\\>", buf); + ret = text_regex_compile(vis->search_pattern, expr, REG_EXTENDED) == 0; + } free(buf); - return text_regex_compile(vis->search_pattern, expr, REG_EXTENDED) == 0; + return ret; } /** motion implementations */