vis

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

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

commit 52601e0314d996275009c44fc39317fdf0f85ebd
parent 5b4d39d2af72704a62a1adeb47041f8c503c150e
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Fri, 27 Nov 2015 07:15:34 +0100

vis: change semantics of operator implementation return value

The return value of operator implementations denoting the new
cursor position is interpreted in the following way:

 - EPOS dispose the cursor
 - [0, text_size] place the cursor accordingly
 - otherwise i.e. > text_size keep the cursor position unchanged

The newly introduced last case is useful for operators which
are called from visual mode, but do not want to change the current
selection.

Diffstat:
Mvis.c | 6+++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/vis.c b/vis.c @@ -645,10 +645,10 @@ static void action_do(Vis *vis, Action *a) { if (a->op) { size_t pos = a->op->func(vis, txt, &c); - if (pos != EPOS) { - view_cursors_to(cursor, pos); - } else { + if (pos == EPOS) { view_cursors_dispose(cursor); + } else if (pos <= text_size(txt)) { + view_cursors_to(cursor, pos); } } }