zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Re: Undo does too much
@ 2000-03-30  8:48 Sven Wischnowsky
  0 siblings, 0 replies; only message in thread
From: Sven Wischnowsky @ 2000-03-30  8:48 UTC (permalink / raw)
  To: zsh-workers


I felt a bit adventurous yesterday...

Ages ago, I wrote:

> Bart Schaefer wrote:
> 
> > 3.1.6-dev-17, zsh -f:
> > 
> > zagzig% setopt completeinword
> > zagzig% setopt | less
> > (output elided)
> > zagzig% setopt co<ESC-p>
> > zagzig% setopt | less<CTRL-/>
> > zagzig% setopt c
> > 
> > Hey, where did the 'o' go?  We undid two changes, not one.  (The setopts
> > are irrelevant, they're just sample input.)

The problem was that the history line stuff was handled in
unapplychange() and even if it had to get another history line, it
still unapplied the change.

> Just adding some fuel: there is also still the problem that the first
> undo after a completion with an automatically inserted suffix doesn't
> seem to have an effect (in reality, it has: auto-removing the suffix
> and undoing it back in). I once tried to fix that but failed
> completely because of the rather difficult undo-recording logic.

This seems to be fixed with the change in iwidgets.list. I know I
tried to understand how to fix this more than once... weird that I
never tried this solution.

Bye
 Sven

diff -ru ../z.old/Src/Zle/iwidgets.list Src/Zle/iwidgets.list
--- ../z.old/Src/Zle/iwidgets.list	Thu Mar 30 10:46:47 2000
+++ Src/Zle/iwidgets.list	Thu Mar 30 10:47:10 2000
@@ -85,7 +85,7 @@
 "quote-line", quoteline, 0
 "quote-region", quoteregion, 0
 "redisplay", redisplay, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_LASTCOL
-"redo", redo, 0
+"redo", redo, ZLE_KEEPSUFFIX
 "reverse-menu-complete", reversemenucomplete, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_ISCOMP
 "run-help", processcmd, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_LASTCOL
 "self-insert", selfinsert, ZLE_MENUCMP | ZLE_KEEPSUFFIX
@@ -97,7 +97,7 @@
 "transpose-chars", transposechars, 0
 "transpose-words", transposewords, 0
 "undefined-key", undefinedkey, 0
-"undo", undo, 0
+"undo", undo, ZLE_KEEPSUFFIX
 "universal-argument", universalargument, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_LASTCOL | ZLE_NOTCOMMAND
 "up-case-word", upcaseword, 0
 "up-history", uphistory, 0
@@ -162,7 +162,7 @@
 "vi-set-mark", visetmark, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_LASTCOL
 "vi-substitute", visubstitute, 0
 "vi-swap-case", viswapcase, 0
-"vi-undo-change", viundochange, 0
+"vi-undo-change", viundochange, ZLE_KEEPSUFFIX
 "vi-unindent", viunindent, 0
 "vi-up-line-or-history", viuplineorhistory, ZLE_LINEMOVE
 "vi-yank", viyank, 0
diff -ru ../z.old/Src/Zle/zle_utils.c Src/Zle/zle_utils.c
--- ../z.old/Src/Zle/zle_utils.c	Thu Mar 30 09:58:21 2000
+++ Src/Zle/zle_utils.c	Thu Mar 30 10:42:40 2000
@@ -557,18 +557,24 @@
     do {
 	if(!curchange->prev)
 	    return 1;
-	unapplychange(curchange = curchange->prev);
+	if (unapplychange(curchange->prev))
+	    curchange = curchange->prev;
+	else
+	    break;
     } while(curchange->flags & CH_PREV);
     setlastline();
     return 0;
 }
 
 /**/
-static void
+static int
 unapplychange(struct change *ch)
 {
-    if(ch->hist != histline)
+    if(ch->hist != histline) {
 	zle_setline(quietgethist(ch->hist));
+	cs = ch->new_cs;
+	return 0;
+    }
     cs = ch->off;
     if(ch->ins)
 	foredel(ztrlen(ch->ins));
@@ -583,6 +589,7 @@
 		line[cs++] = STOUC(*c);
     }
     cs = ch->old_cs;
+    return 1;
 }
 
 /* move forwards through the change list */
@@ -595,19 +602,24 @@
     do {
 	if(!curchange->next)
 	    return 1;
-	applychange(curchange);
-	curchange = curchange->next;
+	if (applychange(curchange))
+	    curchange = curchange->next;
+	else
+	    break;
     } while(curchange->prev->flags & CH_NEXT);
     setlastline();
     return 0;
 }
 
 /**/
-static void
+static int
 applychange(struct change *ch)
 {
-    if(ch->hist != histline)
+    if(ch->hist != histline) {
 	zle_setline(quietgethist(ch->hist));
+	cs = ch->old_cs;
+	return 0;
+    }
     cs = ch->off;
     if(ch->del)
 	foredel(ztrlen(ch->del));
@@ -622,6 +634,7 @@
 		line[cs++] = STOUC(*c);
     }
     cs = ch->new_cs;
+    return 1;
 }
 
 /* vi undo: toggle between the end of the undo list and the preceding point */

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

only message in thread, other threads:[~2000-03-30  8:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-30  8:48 PATCH: Re: Undo does too much Sven Wischnowsky

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).