summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/Zle/zle_params.c3
-rw-r--r--Src/Zle/zle_utils.c24
2 files changed, 25 insertions, 2 deletions
diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c
index ce4b0724d..b84e72088 100644
--- a/Src/Zle/zle_params.c
+++ b/Src/Zle/zle_params.c
@@ -95,6 +95,8 @@ static const struct gsu_integer region_active_gsu =
 { get_region_active, set_region_active, zleunsetfn };
 static const struct gsu_integer undo_change_no_gsu =
 { get_undo_current_change, NULL, zleunsetfn };
+static const struct gsu_integer undo_limit_no_gsu =
+{ get_undo_limit_change, set_undo_limit_change, zleunsetfn };
 
 static const struct gsu_array killring_gsu =
 { get_killring, set_killring, unset_killring };
@@ -137,6 +139,7 @@ static struct zleparam {
     { "region_highlight", PM_ARRAY, GSU(region_highlight_gsu), NULL },
     { "UNDO_CHANGE_NO", PM_INTEGER | PM_READONLY, GSU(undo_change_no_gsu),
       NULL },
+    { "UNDO_LIMIT_NO", PM_INTEGER, GSU(undo_limit_no_gsu), NULL },
     { "WIDGET", PM_SCALAR | PM_READONLY, GSU(widget_gsu), NULL },
     { "WIDGETFUNC", PM_SCALAR | PM_READONLY, GSU(widgetfunc_gsu), NULL },
     { "WIDGETSTYLE", PM_SCALAR | PM_READONLY, GSU(widgetstyle_gsu), NULL },
diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index 06e458190..198c0baa3 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -1405,6 +1405,10 @@ static struct change *nextchanges, *endnextchanges;
 /**/
 zlong undo_changeno;
 
+/* If positive, don't undo beyond this point */
+
+zlong undo_limitno;
+
 /* If non-zero, the last increment to undo_changeno was for the variable */
 
 static int undo_set_by_variable;
@@ -1418,7 +1422,7 @@ initundo(void)
     curchange->prev = curchange->next = NULL;
     curchange->del = curchange->ins = NULL;
     curchange->dell = curchange->insl = 0;
-    curchange->changeno = undo_changeno = 0;
+    curchange->changeno = undo_changeno = undo_limitno = 0;
     undo_set_by_variable = 0;
     lastline = zalloc((lastlinesz = linesz) * ZLE_CHAR_SIZE);
     ZS_memcpy(lastline, zleline, (lastll = zlell));
@@ -1582,6 +1586,8 @@ undo(char **args)
 	    return 1;
 	if (prev->changeno < last_change)
 	    break;
+	if (prev->changeno < undo_limitno && !*args)
+	    break;
 	if (unapplychange(prev))
 	    curchange = prev;
 	else
@@ -1744,7 +1750,21 @@ get_undo_current_change(UNUSED(Param pm))
      * Increment the number in case a change is in progress;
      * we don't want to back off what's already been done when
      * we return to this change number.  This eliminates any
-     * problem about the point where a change is numbered.
+     * problem about the point where a change is numbered
      */
     return ++undo_changeno;
 }
+
+/**/
+zlong
+get_undo_limit_change(UNUSED(Param pm))
+{
+    return undo_limitno;
+}
+
+/**/
+void
+set_undo_limit_change(UNUSED(Param pm), zlong value)
+{
+    undo_limitno = value;
+}