vis

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

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

commit 48d3ff5b5a62296df6debdc2768b588b647e03f0
parent 1c76e551bab1a6e1fa11924abbbb8504981bc32b
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Mon, 27 Jul 2015 21:04:20 +0200

vis: add per cursor registers

Diffstat:
Mview.c | 6++++++
Mview.h | 3+++
Mvis.c | 10++++++++--
3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/view.c b/view.c @@ -41,6 +41,7 @@ struct Cursor { /* cursor position */ Line *line; /* screen line on which cursor currently resides */ Mark mark; /* mark used to keep track of current cursor position */ Selection *sel; /* selection (if any) which folows the cursor upon movement */ + Register reg; /* per cursor register to support yank/put operation */ View *view; /* associated view to which this cursor belongs */ Cursor *prev, *next;/* previous/next cursors in no particular order */ }; @@ -892,6 +893,7 @@ Cursor *view_cursors_new(View *view) { void view_cursors_free(Cursor *c) { if (!c) return; + register_release(&c->reg); if (c->prev) c->prev->next = c->next; if (c->next) @@ -923,6 +925,10 @@ size_t view_cursors_pos(Cursor *c) { return text_mark_get(c->view->text, c->mark); } +Register *view_cursors_register(Cursor *c) { + return &c->reg; +} + void view_cursors_scroll_to(Cursor *c, size_t pos) { View *view = c->view; if (view->cursor == c) { diff --git a/view.h b/view.h @@ -3,6 +3,7 @@ #include <stddef.h> #include <stdbool.h> +#include "register.h" #include "text.h" #include "ui.h" #include "syntax.h" @@ -130,6 +131,8 @@ size_t view_cursors_pos(Cursor*); /* place cursor at `pos' which should be in the interval [0, text-size] */ void view_cursors_to(Cursor*, size_t pos); void view_cursors_scroll_to(Cursor*, size_t pos); +/* get register associated with this register */ +Register *view_cursors_register(Cursor*); /* start selected area at current cursor position. further cursor movements * will affect the selected region. */ void view_cursors_selection_start(Cursor*); diff --git a/vis.c b/vis.c @@ -1227,16 +1227,22 @@ static void action_do(Action *a) { Text *txt = vis->win->file->text; View *view = vis->win->view; int count = MAX(1, a->count); + Cursor *cursor = view_cursors(view), *next; + bool multiple_cursors = cursor && view_cursors_next(cursor); - for (Cursor *cursor = view_cursors(view), *next; cursor; cursor = next) { + for (; cursor; cursor = next) { next = view_cursors_next(cursor); size_t pos = view_cursors_pos(cursor); + Register *reg = a->reg ? a->reg : &vis->registers[REG_DEFAULT]; + if (multiple_cursors) + reg = view_cursors_register(cursor); + OperatorContext c = { .count = a->count, .pos = pos, .range = text_range_empty(), - .reg = a->reg ? a->reg : &vis->registers[REG_DEFAULT], + .reg = reg, .linewise = a->linewise, .arg = &a->arg, };