aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-09-25 12:22:52 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-09-25 12:22:52 +0200
commitb7072550a93e57c2c295fc5d42a2a1175ff530f6 (patch)
tree50f76121e1ff8a582ae426b9000f24b4326e1dca
parentcef2c51df7e782452c8e2cc8f32dcb0931b3ac99 (diff)
downloadvis-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
-rw-r--r--config.def.h1
-rw-r--r--vis.c25
2 files changed, 26 insertions, 0 deletions
diff --git a/config.def.h b/config.def.h
index 0a59028..ac0dfd7 100644
--- a/config.def.h
+++ b/config.def.h
@@ -142,6 +142,7 @@ static KeyBinding vis_movements[] = {
{ { NONE('H') }, movement, { .i = MOVE_WINDOW_LINE_TOP } },
{ { NONE('M') }, movement, { .i = MOVE_WINDOW_LINE_MIDDLE} },
{ { NONE('L') }, movement, { .i = MOVE_WINDOW_LINE_BOTTOM} },
+ { { NONE('*') }, movement, { .i = MOVE_SEARCH_WORD } },
{ { NONE('f') }, movement_key, { .i = MOVE_RIGHT_TO } },
{ { NONE('F') }, movement_key, { .i = MOVE_LEFT_TO } },
{ { NONE('t') }, movement_key, { .i = MOVE_RIGHT_TILL } },
diff --git a/vis.c b/vis.c
index 46220b3..7689b30 100644
--- a/vis.c
+++ b/vis.c
@@ -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);