zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: vim style text objects
@ 2014-11-07 13:19 Oliver Kiddle
  0 siblings, 0 replies; only message in thread
From: Oliver Kiddle @ 2014-11-07 13:19 UTC (permalink / raw)
  To: Zsh workers

This patches getvirange to support vim style text objects. It does this
by using the mark in addition to the cursor to mark the range.

Using the mark makes more sense than you might first thing. vim
text-objects can also be used in visual mode and in that case are just
setting MARK and CURSOR. Also vim recommends using visual mode if
implementing text-objects in vim script.

I've had to set the mark to -1 to detect if the movement changed it.
That will be user-visible via the MARK parameter.

Oliver

diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c
index 89fa685..76c54ee 100644
--- a/Src/Zle/zle_vi.c
+++ b/Src/Zle/zle_vi.c
@@ -161,12 +161,13 @@ vigetkey(void)
 static int
 getvirange(int wf)
 {
-    int pos = zlecs, ret = 0;
+    int pos = zlecs, mpos = mark, ret = 0;
     int mult1 = zmult, hist1 = histline;
     Thingy k2;
 
     virangeflag = 1;
     wordflag = wf;
+    mark = -1;
     /* use operator-pending keymap if one exists */
     Keymap km = openkeymap("viopp");
     if (km)
@@ -191,6 +192,7 @@ getvirange(int wf)
 		k2 == Th(z_sendbreak)) {
 	    wordflag = 0;
 	    virangeflag = 0;
+	    mark = mpos;
 	    return -1;
 	}
 	/*
@@ -216,13 +218,16 @@ getvirange(int wf)
 	histline = hist1;
 	ZS_memcpy(zleline, lastline, zlell = lastll);
 	zlecs = pos;
+        mark = mpos;
 	return -1;
     }
 
     /* Can't handle an empty file.  Also, if the movement command *
      * failed, or didn't move, it is an error.                    */
-    if (!zlell || (zlecs == pos && virangeflag != 2) || ret == -1)
+    if (!zlell || (zlecs == pos && mark == -1 && virangeflag != 2) || ret == -1) {
+        mark = mpos;
 	return -1;
+    }
 
     /* vi-match-bracket changes the value of virangeflag when *
      * moving to the opening bracket, meaning that we need to *
@@ -236,6 +241,12 @@ getvirange(int wf)
 	zlecs = origcs;
     }
 
+    /* if the mark has moved, ignore the original cursor position *
+     * and use the mark. */
+    if (mark != -1)
+	pos = mark;
+    mark = mpos;
+
     /* Get the range the right way round.  zlecs is placed at the *
      * start of the range, and pos (the return value of this   *
      * function) is the end.                                   */


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-11-07 13:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-07 13:19 PATCH: vim style text objects Oliver Kiddle

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).