vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 38df58c587ba9d139dfcda2ac8d11586e11e2a44
parent 323ef825758316811b824bad5b4410747acff5dc
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Mon, 22 Sep 2014 06:09:07 +0200

Add support for the '<', '>' marks

Diffstat:
MREADME | 8++++++--
Mconfig.def.h | 4++++
Meditor.c | 10++++++++--
Meditor.h | 2++
Mtext.c | 2+-
5 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/README b/README @@ -389,8 +389,12 @@ and their current support in vis. Marks ----- - Only the 26 lower case marks [a-z] are supported. No marks across files - are supported. Marks are not preserved over editing sessions. + [a-z] general purpose marks + < start of the last selected visual area in current buffer + > end of the last selected visual area in current buffer + + No marks across files are supported. Marks are not preserved over + editing sessions. Registers --------- diff --git a/config.def.h b/config.def.h @@ -281,6 +281,8 @@ static KeyBinding vis_marks[] = { { { NONE('`'), NONE('x') }, mark, { .i = MARK_x } }, { { NONE('`'), NONE('y') }, mark, { .i = MARK_y } }, { { NONE('`'), NONE('z') }, mark, { .i = MARK_z } }, + { { NONE('`'), NONE('<') }, mark, { .i = MARK_SELECTION_START } }, + { { NONE('`'), NONE('>') }, mark, { .i = MARK_SELECTION_END } }, { /* empty last element, array terminator */ }, }; @@ -311,6 +313,8 @@ static KeyBinding vis_marks_line[] = { { { NONE('\''), NONE('x') }, mark_line, { .i = MARK_x } }, { { NONE('\''), NONE('y') }, mark_line, { .i = MARK_y } }, { { NONE('\''), NONE('z') }, mark_line, { .i = MARK_z } }, + { { NONE('\''), NONE('<') }, mark_line, { .i = MARK_SELECTION_START } }, + { { NONE('\''), NONE('>') }, mark_line, { .i = MARK_SELECTION_END } }, { /* empty last element, array terminator */ }, }; diff --git a/editor.c b/editor.c @@ -55,8 +55,14 @@ static void editor_window_statusbar_draw(EditorWin *win) { win->editor->statusbar(win); } -static void editor_window_cursor_moved(Win *win, void *data) { - editor_window_statusbar_draw(data); +static void editor_window_cursor_moved(Win *winwin, void *data) { + EditorWin *win = data; + Filerange sel = window_selection_get(winwin); + if (text_range_valid(&sel) && sel.start != sel.end) { + text_mark_set(win->text, MARK_SELECTION_START, sel.start); + text_mark_set(win->text, MARK_SELECTION_END, sel.end); + } + editor_window_statusbar_draw(win); } void editor_statusbar_set(Editor *ed, void (*statusbar)(EditorWin*)) { diff --git a/editor.h b/editor.h @@ -86,6 +86,8 @@ enum Mark { MARK_x, MARK_y, MARK_z, + MARK_SELECTION_START, + MARK_SELECTION_END, }; struct Editor { diff --git a/text.c b/text.c @@ -120,7 +120,7 @@ struct Text { struct stat info; /* stat as proped on load time */ int fd; /* the file descriptor of the original mmap-ed data */ LineCache lines; /* mapping between absolute pos in bytes and logical line breaks */ - const char *marks[26]; /* a mark is a pointer into an underlying buffer */ + const char *marks[32]; /* a mark is a pointer into an underlying buffer */ int newlines; /* 0: unknown, 1: \n, -1: \r\n */ };