vis

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

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

commit 199728ac0e15a7128bd9c4c0a01239dd23996709
parent ecbf9b13994754bff4da5fa06a9fe4e97817d2f1
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Tue, 30 Jun 2015 11:37:00 +0200

Perform character prev/next movements based on Text not View

While it is slower, it allows to move to characters which are
currently not visible. This will be handy when experimenting
with multiple cursors.

Diffstat:
Mview.c | 40----------------------------------------
Mview.h | 2--
Mvis.c | 4++--
3 files changed, 2 insertions(+), 44 deletions(-)

diff --git a/view.c b/view.c @@ -519,46 +519,6 @@ View *view_new(Text *text, ViewEvent *events) { void view_ui(View *view, UiWin* ui) { view->ui = ui; } -size_t view_char_prev(View *view) { - Cursor *cursor = &view->cursor; - Line *line = cursor->line; - - do { - if (cursor->col == 0) { - if (!line->prev) - return cursor->pos; - cursor->line = line = line->prev; - cursor->col = MIN(line->width, view->width - 1); - cursor->row--; - } else { - cursor->col--; - } - } while (line->cells[cursor->col].len == 0); - - cursor->pos -= line->cells[cursor->col].len; - return view_cursor_update(view); -} - -size_t view_char_next(View *view) { - Cursor *cursor = &view->cursor; - Line *line = cursor->line; - - do { - cursor->pos += line->cells[cursor->col].len; - if ((line->width == view->width && cursor->col == view->width - 1) || - cursor->col == line->width) { - if (!line->next) - return cursor->pos; - cursor->line = line = line->next; - cursor->row++; - cursor->col = 0; - } else { - cursor->col++; - } - } while (line->cells[cursor->col].len == 0); - - return view_cursor_update(view); -} static size_t view_cursor_set(View *view, Line *line, int col) { int row = 0; diff --git a/view.h b/view.h @@ -54,8 +54,6 @@ void view_tabwidth_set(View*, int tabwidth); /* cursor movements which also update selection if one is active. * they return new cursor postion */ -size_t view_char_next(View*); -size_t view_char_prev(View*); size_t view_line_down(View*); size_t view_line_up(View*); size_t view_screenline_down(View*); diff --git a/vis.c b/vis.c @@ -184,8 +184,8 @@ static Movement moves[] = { [MOVE_LINE_NEXT] = { .txt = text_line_next, .type = LINEWISE }, [MOVE_LINE] = { .txt = line, .type = LINEWISE|IDEMPOTENT|JUMP}, [MOVE_COLUMN] = { .txt = column, .type = CHARWISE|IDEMPOTENT}, - [MOVE_CHAR_PREV] = { .view = view_char_prev }, - [MOVE_CHAR_NEXT] = { .view = view_char_next }, + [MOVE_CHAR_PREV] = { .txt = text_char_prev }, + [MOVE_CHAR_NEXT] = { .txt = text_char_next }, [MOVE_WORD_START_PREV] = { .txt = text_word_start_prev, .type = CHARWISE }, [MOVE_WORD_START_NEXT] = { .txt = text_word_start_next, .type = CHARWISE }, [MOVE_WORD_END_PREV] = { .txt = text_word_end_prev, .type = CHARWISE|INCLUSIVE },