From f1923bdfa6300a0d32e3329eb2488447f76b8970 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 12 Jun 2015 09:30:39 +0100 Subject: Add non-metafied character length handling. Use this in regex module and add test using $'\ua0'. Rename mb_metacharinit() to mb_charinit() as it does not involve metafied characters. --- Src/Zle/zle_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Src/Zle/zle_utils.c') diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c index e4ab97a54..06e458190 100644 --- a/Src/Zle/zle_utils.c +++ b/Src/Zle/zle_utils.c @@ -1288,7 +1288,7 @@ showmsg(char const *msg) p = unmetafy(umsg, &ulen); memset(&mbs, 0, sizeof mbs); - mb_metacharinit(); + mb_charinit(); while (ulen > 0) { char const *n; if (*p == '\n') { -- cgit v1.2.3 From 2833299312dc3600849bd82ae7b93f5538cc10bb Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 9 Jul 2015 19:29:59 +0100 Subject: 35708: add UNDO_LIMIT_NO --- ChangeLog | 5 +++++ Doc/Zsh/zle.yo | 23 ++++++++++++++++++++++- Src/Zle/zle_params.c | 3 +++ Src/Zle/zle_utils.c | 24 ++++++++++++++++++++++-- 4 files changed, 52 insertions(+), 3 deletions(-) (limited to 'Src/Zle/zle_utils.c') diff --git a/ChangeLog b/ChangeLog index 358c3e916..6b15a9c5d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-07-09 Peter Stephenson + + * 35708: Doc/Zsh/zle.yo, Src/Zle/zle_params.c, + Src/Zle/zle_utils.c; UNDO_LIMIT_NO. + 2015-07-09 Peter Stephenson * 35751: Src/exec.c, Test/C03traps.ztst: fix ERR_RETURN / diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index d3f067031..da8ee4721 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -960,6 +960,26 @@ A number representing the state of the undo history. The only use of this is passing as an argument to the tt(undo) widget in order to undo back to the recorded point. Read-only. ) +vindex(UNDO_LIMIT_NO) +item(tt(UNDO_LIMIT_NO) (integer))( +A number corresponding to an existing change in the undo history; +compare tt(UNDO_CHANGE_NO). If this is set to a value greater +than zero, the tt(undo) command will not allow the line to +be undone beyond the given change number. It is still possible +to use `tt(zle undo) var(change)' in a widget to undo beyond +that point; in that case, it will not be possible to undo at +all until tt(UNDO_LIMIT_NO) is reduced. Set to 0 to disable the limit. + +A typical use of this variable in a widget function is as follows: + +example(integer save_limit=$UNDO_LIMIT_NO +UNDO_LIMIT_NO=$UNDO_CHANGE_NO +{ + # Perform some form of recursive edit. +} always { + UNDO_LIMIT_NO=save_limit +}) +) vindex(WIDGET) item(tt(WIDGET) (scalar))( The name of the widget currently being executed; read-only. @@ -2333,7 +2353,8 @@ item(tt(undo) (tt(^_ ^Xu ^X^U)) (tt(u)) (unbound))( Incrementally undo the last text modification. When called from a user-defined widget, takes an optional argument indicating a previous state of the undo history as returned by the tt(UNDO_CHANGE_NO) variable; -modifications are undone until that state is reached. +modifications are undone until that state is reached, subject to +any limit imposed by the tt(UNDO_LIMIT_NO) variable. Note that when invoked from vi command mode, the full prior change made in insert mode is reverted, the changes having been merged when command mode was 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; +} -- cgit v1.2.3 From 5911aca85f200cb7621b65ff61d79919fd21cfcb Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Tue, 14 Jul 2015 00:28:23 +0200 Subject: 35737: (tweaked c.f. Peter: 35759): use new undo limit for minibuffer and beep when limit is reached --- ChangeLog | 4 ++++ Functions/Zle/read-from-minibuffer | 5 ++++- Src/Zle/zle_utils.c | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) (limited to 'Src/Zle/zle_utils.c') diff --git a/ChangeLog b/ChangeLog index 1290497ae..7679d4ed8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2015-07-13 Oliver Kiddle + * 35737: (tweaked c.f. Peter: 35759): Src/Zle/zle_utils.c, + Functions/Zle/read-from-minibuffer: use new undo limit for + minibuffer and beep when limit is reached + * 35756: Completion/Zsh/Type/_ps1234: use the actual colours in the completion list for terminal colours diff --git a/Functions/Zle/read-from-minibuffer b/Functions/Zle/read-from-minibuffer index 8fec1105e..09dc68f97 100644 --- a/Functions/Zle/read-from-minibuffer +++ b/Functions/Zle/read-from-minibuffer @@ -20,7 +20,7 @@ done (( OPTIND > 1 )) && shift $(( OPTIND - 1 )) local readprompt="$1" lbuf_init="$2" rbuf_init="$3" -integer changeno=$UNDO_CHANGE_NO +integer savelim=$UNDO_LIMIT_NO changeno=$UNDO_CHANGE_NO { # Use anonymous function to make sure special values get restored, @@ -43,6 +43,8 @@ integer changeno=$UNDO_CHANGE_NO else local NUMERIC unset NUMERIC + zle split-undo + UNDO_LIMIT_NO=$UNDO_CHANGE_NO zle recursive-edit -K main stat=$? (( stat )) || REPLY=$BUFFER @@ -52,6 +54,7 @@ integer changeno=$UNDO_CHANGE_NO # This removes the edits relating to the read from the undo history. # These aren't useful once we get back to the main editing buffer. zle undo $changeno + UNDO_LIMIT_NO=savelim } return $stat diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c index 198c0baa3..8b55403b3 100644 --- a/Src/Zle/zle_utils.c +++ b/Src/Zle/zle_utils.c @@ -1587,7 +1587,7 @@ undo(char **args) if (prev->changeno < last_change) break; if (prev->changeno < undo_limitno && !*args) - break; + return 1; if (unapplychange(prev)) curchange = prev; else -- cgit v1.2.3 From 832130c57dedc532191512045096180657a049f3 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Thu, 13 Aug 2015 16:18:26 +0200 Subject: 36131: make use of undo limits; call mkundoent() when $UNDO_CHANGE_NO is referenced for a clear change number marking the current state --- ChangeLog | 4 ++++ Functions/Zle/narrow-to-region | 36 +++++++++++++++++++++++------------- Src/Zle/zle_utils.c | 33 +++++++++------------------------ 3 files changed, 36 insertions(+), 37 deletions(-) (limited to 'Src/Zle/zle_utils.c') diff --git a/ChangeLog b/ChangeLog index 104ac2c73..dfe254a21 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2015-08-13 Oliver Kiddle + * 36131: Functions/Zle/narrow-to-region, Src/Zle/zle_utils.c: + make use of undo limits; call mkundoent() when $UNDO_CHANGE_NO is + referenced for a clear change number marking the current state + * Eric Cook: 36113: Completion/Unix/Type/_find_net_interfaces: ip(8) may add suffixes which is not good for completion matches diff --git a/Functions/Zle/narrow-to-region b/Functions/Zle/narrow-to-region index 293f89b0f..0ef28a8dc 100644 --- a/Functions/Zle/narrow-to-region +++ b/Functions/Zle/narrow-to-region @@ -26,11 +26,13 @@ # statevar may not begin with the prefix "_ntr_" which is reserved for # parameters within narrow-to-region. -emulate -L zsh -setopt extendedglob +# set the minimum of options to avoid changing behaviour away from +# user preferences from within recursive-edit +setopt localoptions noshwordsplit noksharrays -local _ntr_lbuf_return _ntr_rbuf_return +local _ntr_newbuf _ntr_lbuf_return _ntr_rbuf_return local _ntr_predisplay=$PREDISPLAY _ntr_postdisplay=$POSTDISPLAY +integer _ntr_savelim=UNDO_LIMIT_NO _ntr_changeno integer _ntr_start _ntr_end _ntr_swap _ntr_cursor=$CURSOR _ntr_mark=$MARK integer _ntr_stat @@ -61,7 +63,7 @@ done (( OPTIND > 1 )) && shift $(( OPTIND - 1 )) if [[ $_ntr_restore = _ntr_* || $_ntr_save = _ntr_* || - $_ntr_lbuf_return = _ntr_* || $ntr_rbuf_return = _ntr_* ]]; then + $_ntr_lbuf_return = _ntr_* || $_ntr_rbuf_return = _ntr_* ]]; then zle -M "$0: _ntr_ prefix is reserved" >&2 return 1 fi @@ -86,30 +88,34 @@ if [[ -n $_ntr_save || -z $_ntr_restore ]]; then _ntr_end=_ntr_swap fi - (( _ntr_end++, _ntr_cursor -= _ntr_start, _ntr_mark -= _ntr_start )) + (( _ntr_cursor -= _ntr_start, _ntr_mark -= _ntr_start )) _ntr_lbuffer=${BUFFER[1,_ntr_start]} if [[ -z $_ntr_usepretext || ( -n $_ntr_nonempty && -z $_ntr_lbuffer ) ]] then _ntr_pretext=$_ntr_lbuffer fi - _ntr_rbuffer=${BUFFER[_ntr_end,-1]} + _ntr_rbuffer=${BUFFER[_ntr_end+1,-1]} if [[ -z $_ntr_useposttext || ( -n $_ntr_nonempty && -z $_ntr_rbuffer ) ]] then _ntr_posttext=$_ntr_rbuffer fi + _ntr_changeno=$UNDO_CHANGE_NO PREDISPLAY="$_ntr_predisplay$_ntr_pretext" POSTDISPLAY="$_ntr_posttext$_ntr_postdisplay" if [[ -n $_ntr_save ]]; then builtin typeset -ga $_ntr_save set -A $_ntr_save "${_ntr_predisplay}" "${_ntr_postdisplay}" \ - "${_ntr_lbuffer}" "${_ntr_rbuffer}" || return 1 + "${_ntr_savelim}" "${_ntr_changeno}" \ + "${_ntr_start}" "${_ntr_end}" || return 1 fi - BUFFER=${BUFFER[_ntr_start+1,_ntr_end-1]} + BUFFER=${BUFFER[_ntr_start+1,_ntr_end]} CURSOR=$_ntr_cursor MARK=$_ntr_mark + zle split-undo + UNDO_LIMIT_NO=$UNDO_CHANGE_NO fi if [[ -z $_ntr_save && -z $_ntr_restore ]]; then @@ -126,18 +132,22 @@ if [[ -n $_ntr_restore || -z $_ntr_save ]]; then if [[ -n $_ntr_restore ]]; then if ! { _ntr_predisplay="${${(@P)_ntr_restore}[1]}" _ntr_postdisplay="${${(@P)_ntr_restore}[2]}" - _ntr_lbuffer="${${(@P)_ntr_restore}[3]}" - _ntr_rbuffer="${${(@P)_ntr_restore}[4]}" }; then + _ntr_savelim="${${(@P)_ntr_restore}[3]}" + _ntr_changeno="${${(@P)_ntr_restore}[4]}" + _ntr_start="${${(@P)_ntr_restore}[5]}" + _ntr_end="${${(@P)_ntr_restore}[6]}" }; then zle -M Failed. >&2 return 1 fi fi + _ntr_newbuf="$BUFFER" + zle undo $_ntr_changeno PREDISPLAY=$_ntr_predisplay POSTDISPLAY=$_ntr_postdisplay - LBUFFER="$_ntr_lbuffer$BUFFER" - RBUFFER="$_ntr_rbuffer" - MARK=${#_ntr_lbuffer} + BUFFER[_ntr_start+1,_ntr_end]="$_ntr_newbuf" + (( MARK = _ntr_start, CURSOR = _ntr_start + ${#_ntr_newbuf} )) + UNDO_LIMIT_NO=_ntr_savelim fi return $_ntr_stat diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c index 8b55403b3..d1d320613 100644 --- a/Src/Zle/zle_utils.c +++ b/Src/Zle/zle_utils.c @@ -1409,10 +1409,6 @@ zlong undo_changeno; zlong undo_limitno; -/* If non-zero, the last increment to undo_changeno was for the variable */ - -static int undo_set_by_variable; - /**/ void initundo(void) @@ -1423,7 +1419,6 @@ initundo(void) curchange->del = curchange->ins = NULL; curchange->dell = curchange->insl = 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)); lastcs = zlecs; @@ -1549,7 +1544,6 @@ mkundoent(void) ch->prev = NULL; } ch->changeno = ++undo_changeno; - undo_set_by_variable = 0; endnextchanges = ch; } @@ -1584,14 +1578,13 @@ undo(char **args) struct change *prev = curchange->prev; if(!prev) return 1; - if (prev->changeno < last_change) + if (prev->changeno <= last_change) break; - if (prev->changeno < undo_limitno && !*args) + if (prev->changeno <= undo_limitno && !*args) return 1; - if (unapplychange(prev)) - curchange = prev; - else - break; + if (!unapplychange(prev) && last_change >= 0) + unapplychange(prev); + curchange = prev; } while (last_change >= (zlong)0 || (curchange->flags & CH_PREV)); setlastline(); return 0; @@ -1741,18 +1734,10 @@ zlecallhook(char *name, char *arg) zlong get_undo_current_change(UNUSED(Param pm)) { - if (undo_set_by_variable) { - /* We were the last to increment this, doesn't need another one. */ - return undo_changeno; - } - undo_set_by_variable = 1; - /* - * 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 - */ - return ++undo_changeno; + /* add entry for any pending changes */ + mkundoent(); + setlastline(); + return undo_changeno; } /**/ -- cgit v1.2.3