Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Vim special marks - Re: PATCH: highlight pasted text



On 24 Jul, I wrote:
> There's one very unfortunate
> effect of this design choice, however: if the start of some inserted
> text looks the same as what was there before, the undo mechanism will
> identify the later characters as having been inserted rather than the
> earlier ones.

I've not come up with a solution to this. One part of the patch was
actually a bug fix: the use of histline rather than curhist when
checking whether the zle_goto_hist call is needed. This prevented you
from returning to the original line.

The following is a cut down version of the patch. It includes the addition
of the . mark which uses the cursor position from the last change rather
than the offset so is unaffected by the problem,

Oliver

diff --git a/Src/Zle/zle_move.c b/Src/Zle/zle_move.c
index d751c43..208839e 100644
--- a/Src/Zle/zle_move.c
+++ b/Src/Zle/zle_move.c
@@ -876,24 +876,36 @@ int
 vigotomark(UNUSED(char **args))
 {
     ZLE_INT_T ch;
+    int *markcs, *markhist = 0;
     int oldcs = zlecs;
     int oldline = histline;
+    int tmpcs, tmphist;
 
     ch = getfullchar(0);
-    if (ch == ZWC('\'') || ch == ZWC('`'))
-	ch = 26;
-    else {
-	if (ch < ZWC('a') || ch > ZWC('z'))
-	    return 1;
-	ch -= ZWC('a');
-    }
-    if (!vimarkline[ch])
-	return 1;
-    if (curhist != vimarkline[ch] && !zle_goto_hist(vimarkline[ch], 0, 0)) {
-	vimarkline[ch] = 0;
+    if (ch == ZWC('\'') || ch == ZWC('`')) {
+	markhist = vimarkline + 26;
+	markcs = vimarkcs + 26;
+    } else if (ch == ZWC('.') && curchange->prev) {
+	/* position cursor where it was after the last change. not exactly
+	 * what vim does but close enough */
+	tmpcs = curchange->prev->new_cs;
+	tmphist = curchange->prev->hist;
+	markcs = &tmpcs;
+	markhist = &tmphist;
+    } else if (ch >= ZWC('a') && ch <= ZWC('z')) {
+	markhist = vimarkline + (ch - ZWC('a'));
+	markcs = vimarkcs + (ch - ZWC('a'));
+    } else
 	return 1;
+    if (markhist) {
+	if (!*markhist)
+	    return 1;
+	if (histline != *markhist && !zle_goto_hist(*markhist, 0, 0)) {
+	    *markhist = 0;
+	    return 1;
+	}
     }
-    zlecs = vimarkcs[ch];
+    zlecs = *markcs;
     vimarkcs[26] = oldcs;
     vimarkline[26] = oldline;
     if (zlecs > zlell)



Messages sorted by: Reverse Date, Date, Thread, Author