diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2014-09-25 12:22:52 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2014-09-25 12:22:52 +0200 |
| commit | b7072550a93e57c2c295fc5d42a2a1175ff530f6 (patch) | |
| tree | 50f76121e1ff8a582ae426b9000f24b4326e1dca /vis.c | |
| parent | cef2c51df7e782452c8e2cc8f32dcb0931b3ac99 (diff) | |
| download | vis-b7072550a93e57c2c295fc5d42a2a1175ff530f6.tar.gz vis-b7072550a93e57c2c295fc5d42a2a1175ff530f6.tar.xz | |
Implement '*'
This still has a couple of problems:
- it uses the regular expression search (because 'n' and 'N' should
operate on the same search term)
- the word should be deliminited not only by spaces but also by
special symbols. this should be fixed once the word/WORD distinction
gets implemented
Diffstat (limited to 'vis.c')
| -rw-r--r-- | vis.c | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -220,6 +220,7 @@ enum { MOVE_FILE_END, MOVE_MARK, MOVE_MARK_LINE, + MOVE_SEARCH_WORD, MOVE_SEARCH_FORWARD, MOVE_SEARCH_BACKWARD, MOVE_WINDOW_LINE_TOP, @@ -228,6 +229,8 @@ enum { }; /** movements which can be used besides the one in text-motions.h and window.h */ +/* search in forward direction for the word where the cursor is currently located */ +static size_t search_word(const Arg *arg); /* search again for the last used search pattern */ static size_t search_forward(const Arg *arg); static size_t search_backward(const Arg *arg); @@ -288,6 +291,7 @@ static Movement moves[] = { [MOVE_RIGHT_TILL] = { .cmd = till, .type = LINEWISE|INCLUSIVE }, [MOVE_MARK] = { .cmd = mark_goto, .type = LINEWISE }, [MOVE_MARK_LINE] = { .cmd = mark_line_goto, .type = LINEWISE }, + [MOVE_SEARCH_WORD] = { .cmd = search_word, .type = LINEWISE }, [MOVE_SEARCH_FORWARD] = { .cmd = search_forward, .type = LINEWISE }, [MOVE_SEARCH_BACKWARD] = { .cmd = search_backward, .type = LINEWISE }, [MOVE_WINDOW_LINE_TOP] = { .cmd = window_lines_top, .type = LINEWISE }, @@ -594,6 +598,27 @@ static void op_case_change(OperatorContext *c) { /** movement implementations of type: size_t (*move)(const Arg*) */ +static size_t search_word(const Arg *arg) { + size_t pos = window_cursor_get(vis->win->win); + /* TODO: to make this useful the other variant breaking on special symbols + * should be used here */ + Filerange word = text_object_word_raw(vis->win->text, pos); + if (!text_range_valid(&word)) + return pos; + size_t len = word.end - word.start; + char *buf = malloc(len+1); + if (!buf) + return pos; + len = text_bytes_get(vis->win->text, word.start, len, buf); + buf[len] = '\0'; + /* TODO: using regular expression search here is wrong, but 'n', 'N' should + * reuse this search term */ + if (!text_regex_compile(vis->search_pattern, buf, REG_EXTENDED)) + pos = text_search_forward(vis->win->text, pos, vis->search_pattern); + free(buf); + return pos; +} + static size_t search_forward(const Arg *arg) { size_t pos = window_cursor_get(vis->win->win); return text_search_forward(vis->win->text, pos, vis->search_pattern); |
