From 9f3dc6605aa049e689f769dd2b4a864361c92b1d Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sun, 14 Jun 2015 20:12:42 -0700 Subject: 35469: test UNDO_CHANGE_NO to determine whether to start over or use the next history event --- Functions/Zle/smart-insert-last-word | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'Functions/Zle') diff --git a/Functions/Zle/smart-insert-last-word b/Functions/Zle/smart-insert-last-word index 27b0849ee..67adea760 100644 --- a/Functions/Zle/smart-insert-last-word +++ b/Functions/Zle/smart-insert-last-word @@ -47,13 +47,15 @@ setopt extendedglob nohistignoredups zle auto-suffix-retain # Not strictly necessary: -# (($+_ilw_hist)) || integer -g _ilw_hist _ilw_count _ilw_cursor _ilw_lcursor +# (($+_ilw_hist)) || integer -g _ilw_hist _ilw_count _ilw_cursor _ilw_lcursor _ilw_changeno integer cursor=$CURSOR lcursor=$CURSOR local lastcmd pattern numeric=$NUMERIC # Save state for repeated calls -if (( HISTNO == _ilw_hist && cursor == _ilw_cursor )); then +if (( HISTNO == _ilw_hist && cursor == _ilw_cursor && + UNDO_CHANGE_NO == _ilw_changeno )) +then NUMERIC=$[_ilw_count+1] lcursor=$_ilw_lcursor else @@ -61,7 +63,8 @@ else _ilw_lcursor=$lcursor fi # Handle the up to three arguments of .insert-last-word -if (( $+1 )); then +if (( $+1 )) +then if (( $+3 )); then ((NUMERIC = -($1))) else @@ -117,3 +120,6 @@ fi LBUFFER[lcursor+1,cursor+1]=$lastcmd[-NUMERIC] _ilw_cursor=$CURSOR + +# This is necessary to update UNDO_CHANGE_NO immediately +zle split-undo && _ilw_changeno=$UNDO_CHANGE_NO -- cgit v1.2.3 From 09e1b2434d6c44d95d97c87d5e803e5f5e747b6e Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sun, 21 Jun 2015 18:16:40 +0100 Subject: 35545: enhance narrow-to-region to return LBUFFER and RBUFFER --- ChangeLog | 5 +++++ Functions/Zle/narrow-to-region | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'Functions/Zle') diff --git a/ChangeLog b/ChangeLog index 45011327f..882430eb5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-06-21 Peter Stephenson + + * 35545: Functions/Zle/narrow-to-region: Add ability to return + buffer components from narrowed region. + 2015-06-19 Oliver Kiddle * 35531: Completion/Unix/Command/_adb: fallback on file completion diff --git a/Functions/Zle/narrow-to-region b/Functions/Zle/narrow-to-region index 86fd7ac13..c65c80cb9 100644 --- a/Functions/Zle/narrow-to-region +++ b/Functions/Zle/narrow-to-region @@ -11,6 +11,8 @@ # Either or both may be empty. # -n Only replace the text before or after the region with # the -p or -P options if the text was not empty. +# -l lbufvar ) $lbufvar and $rbufvar will contain the value of $LBUFFER and +# -r rbufvar ) $RBUFFER resulting from any recursive edit (i.e. not with -S or -R) # -S statevar # -R statevar # Save or restore the state in/from the parameter named statevar. In @@ -28,16 +30,20 @@ integer _ntr_start _ntr_end _ntr_swap _ntr_cursor=$CURSOR _ntr_mark=$MARK integer _ntr_stat local _ntr_opt _ntr_pretext _ntr_posttext _ntr_usepretext _ntr_useposttext -local _ntr_nonempty _ntr_save _ntr_restore +local _ntr_nonempty _ntr_save _ntr_restore _ntr_lbuffer _ntr_rbuffer -while getopts "np:P:R:S:" _ntr_opt; do +while getopts "l:np:P:r:R:S:" _ntr_opt; do case $_ntr_opt in + (l) _ntr_lbuffer=$OPTARG + ;; (n) _ntr_nonempty=1 ;; (p) _ntr_pretext=$OPTARG _ntr_usepretext=1 ;; (P) _ntr_posttext=$OPTARG _ntr_useposttext=1 ;; + (r) _ntr_rbuffer=$OPTARG + ;; (R) _ntr_restore=$OPTARG ;; (S) _ntr_save=$OPTARG @@ -101,6 +107,9 @@ fi if [[ -z $_ntr_save && -z $_ntr_restore ]]; then zle recursive-edit _ntr_stat=$? + + [[ -n $_ntr_lbuffer ]] && eval "${_ntr_lbuffer}=\${LBUFFER}" + [[ -n $_ntr_rbuffer ]] && eval "${_ntr_rbuffer}=\${RBUFFER}" fi if [[ -n $_ntr_restore || -z $_ntr_save ]]; then -- cgit v1.2.3 From ea0f612c3ad8fa1b4dea2245ce107e751c8e06d6 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Mon, 22 Jun 2015 03:34:48 +0200 Subject: 35558: narrow-to-region: Use unique parameter names for new feature --- ChangeLog | 3 +++ Functions/Zle/narrow-to-region | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'Functions/Zle') diff --git a/ChangeLog b/ChangeLog index 982609e87..5d8682ec8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,9 @@ * 35554: Doc/Zsh/contrib.yo: Document narrow-to-region -l and -r. + * 35558: Functions/Zle/narrow-to-region: narrow-to-region: + Use unique parameter names for new feature. + 2015-06-21 Peter Stephenson * 35545: Functions/Zle/narrow-to-region: Add ability to return diff --git a/Functions/Zle/narrow-to-region b/Functions/Zle/narrow-to-region index c65c80cb9..8b88da4a9 100644 --- a/Functions/Zle/narrow-to-region +++ b/Functions/Zle/narrow-to-region @@ -24,7 +24,7 @@ emulate -L zsh setopt extendedglob -local _ntr_lbuffer _ntr_rbuffer +local _ntr_lbuf_return _ntr_rbuf_return local _ntr_predisplay=$PREDISPLAY _ntr_postdisplay=$POSTDISPLAY integer _ntr_start _ntr_end _ntr_swap _ntr_cursor=$CURSOR _ntr_mark=$MARK integer _ntr_stat @@ -34,7 +34,7 @@ local _ntr_nonempty _ntr_save _ntr_restore _ntr_lbuffer _ntr_rbuffer while getopts "l:np:P:r:R:S:" _ntr_opt; do case $_ntr_opt in - (l) _ntr_lbuffer=$OPTARG + (l) _ntr_lbuf_return=$OPTARG ;; (n) _ntr_nonempty=1 ;; @@ -42,7 +42,7 @@ while getopts "l:np:P:r:R:S:" _ntr_opt; do ;; (P) _ntr_posttext=$OPTARG _ntr_useposttext=1 ;; - (r) _ntr_rbuffer=$OPTARG + (r) _ntr_rbuf_return=$OPTARG ;; (R) _ntr_restore=$OPTARG ;; @@ -108,8 +108,8 @@ if [[ -z $_ntr_save && -z $_ntr_restore ]]; then zle recursive-edit _ntr_stat=$? - [[ -n $_ntr_lbuffer ]] && eval "${_ntr_lbuffer}=\${LBUFFER}" - [[ -n $_ntr_rbuffer ]] && eval "${_ntr_rbuffer}=\${RBUFFER}" + [[ -n $_ntr_lbuf_return ]] && eval "${_ntr_lbuf_return}=\${LBUFFER}" + [[ -n $_ntr_rbuf_return ]] && eval "${_ntr_rbuf_return}=\${RBUFFER}" fi if [[ -n $_ntr_restore || -z $_ntr_save ]]; then -- 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 'Functions/Zle') 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 35ffe36318955d03fca3df0d34a0997970cfc6a3 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 7 Jul 2015 20:30:15 +0000 Subject: 35769: edit-command-line: Go to the right byte offset --- ChangeLog | 5 +++++ Functions/Zle/edit-command-line | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'Functions/Zle') diff --git a/ChangeLog b/ChangeLog index 7679d4ed8..38d64d458 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-07-13 Daniel Shahaf + + * 35769: Functions/Zle/edit-command-line: edit-command-line: + Go to the right byte offset + 2015-07-13 Oliver Kiddle * 35737: (tweaked c.f. Peter: 35759): Src/Zle/zle_utils.c, diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line index 100af9601..2ad4825b7 100644 --- a/Functions/Zle/edit-command-line +++ b/Functions/Zle/edit-command-line @@ -8,7 +8,17 @@ () { exec Date: Wed, 22 Jul 2015 12:48:03 -0700 Subject: 35823: fix handling of MARK and CURSOR, clean up documentary comment --- ChangeLog | 5 ++++ Functions/Zle/narrow-to-region | 63 +++++++++++++++++++++++++----------------- 2 files changed, 42 insertions(+), 26 deletions(-) (limited to 'Functions/Zle') diff --git a/ChangeLog b/ChangeLog index 7e21be806..90babd20e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-07-22 Barton E. Schaefer + + * 35823: Functions/Zle/narrow-to-region: fix handling of MARK + and CURSOR, clean up documentary comment + 2015-07-22 Barton E. Schaefer * 35582: Test/A06assign.ztst, Test/B02typeset.ztst: test for 35581 diff --git a/Functions/Zle/narrow-to-region b/Functions/Zle/narrow-to-region index 8b88da4a9..293f89b0f 100644 --- a/Functions/Zle/narrow-to-region +++ b/Functions/Zle/narrow-to-region @@ -5,21 +5,26 @@ # Optionally accepts exactly two arguments, which are used instead of # $CURSOR and $MARK as limits to the range. # +# Upon exit, $MARK is always the start of the edited range and $CURSOR +# the end of the range, even if they began in the opposite order. +# # Other options: -# -p pretext show `pretext' instead of the buffer text before the region. -# -P posttext show `posttext' instead of the buffer text after the region. -# Either or both may be empty. +# -p pretext show "pretext" instead of the buffer text before the region. +# -P posttext show "posttext" instead of the buffer text after the region. +# Either or both may be empty. # -n Only replace the text before or after the region with # the -p or -P options if the text was not empty. -# -l lbufvar ) $lbufvar and $rbufvar will contain the value of $LBUFFER and -# -r rbufvar ) $RBUFFER resulting from any recursive edit (i.e. not with -S or -R) +# -l lbufvar $lbufvar is assigned the value of $LBUFFER and +# -r rbufvar $rbufvar is assigned the value of $RBUFFER +# from any recursive edit (i.e. not with -S or -R). Neither +# lbufvar nor rbufvar may begin with the prefix "_ntr_". # -S statevar # -R statevar -# Save or restore the state in/from the parameter named statevar. In -# either case no recursive editing takes place; this will typically be -# done within the calling function between calls with -S and -R. The -# statevar may not begin with the prefix _ntr_ which is reserved for -# parameters within narrow-to-region. +# Save or restore the state in/from the parameter named statevar. In +# either case no recursive editing takes place; this will typically be +# done within the calling function between calls with -S and -R. The +# statevar may not begin with the prefix "_ntr_" which is reserved for +# parameters within narrow-to-region. emulate -L zsh setopt extendedglob @@ -55,7 +60,8 @@ while getopts "l:np:P:r:R:S:" _ntr_opt; do done (( OPTIND > 1 )) && shift $(( OPTIND - 1 )) -if [[ $_ntr_restore = _ntr_* || $_ntr_save = _ntr_* ]]; then +if [[ $_ntr_restore = _ntr_* || $_ntr_save = _ntr_* || + $_ntr_lbuf_return = _ntr_* || $ntr_rbuf_return = _ntr_* ]]; then zle -M "$0: _ntr_ prefix is reserved" >&2 return 1 fi @@ -64,7 +70,7 @@ if [[ -n $_ntr_save || -z $_ntr_restore ]]; then if (( $# )); then if (( $# != 2 )); then - zle -M "$0: supply zero or two arguments" + zle -M "$0: supply zero or two arguments" >&2 return 1 fi _ntr_start=$1 @@ -94,39 +100,44 @@ if [[ -n $_ntr_save || -z $_ntr_restore ]]; then fi PREDISPLAY="$_ntr_predisplay$_ntr_pretext" POSTDISPLAY="$_ntr_posttext$_ntr_postdisplay" - BUFFER=${BUFFER[_ntr_start+1,_ntr_end-1]} - CURSOR=$_ntr_cursor - MARK=$_ntr_mark if [[ -n $_ntr_save ]]; then - eval "$_ntr_save=(${(qq)_ntr_predisplay} ${(qq)_ntr_postdisplay} -${(qq)_ntr_lbuffer} ${(qq)_ntr_rbuffer})" || return 1 + builtin typeset -ga $_ntr_save + set -A $_ntr_save "${_ntr_predisplay}" "${_ntr_postdisplay}" \ + "${_ntr_lbuffer}" "${_ntr_rbuffer}" || return 1 fi + + BUFFER=${BUFFER[_ntr_start+1,_ntr_end-1]} + CURSOR=$_ntr_cursor + MARK=$_ntr_mark fi if [[ -z $_ntr_save && -z $_ntr_restore ]]; then zle recursive-edit _ntr_stat=$? - [[ -n $_ntr_lbuf_return ]] && eval "${_ntr_lbuf_return}=\${LBUFFER}" - [[ -n $_ntr_rbuf_return ]] && eval "${_ntr_rbuf_return}=\${RBUFFER}" + [[ -n $_ntr_lbuf_return ]] && + builtin typeset -g ${_ntr_lbuf_return}="${LBUFFER}" + [[ -n $_ntr_rbuf_return ]] && + builtin typeset -g ${_ntr_rbuf_return}="${RBUFFER}" fi if [[ -n $_ntr_restore || -z $_ntr_save ]]; then if [[ -n $_ntr_restore ]]; then - if ! eval "_ntr_predisplay=\${${_ntr_restore}[1]} -_ntr_postdisplay=\${${_ntr_restore}[2]} -_ntr_lbuffer=\${${_ntr_restore}[3]} -_ntr_rbuffer=\${${_ntr_restore}[4]}"; then - zle -M Failed. + 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 + zle -M Failed. >&2 return 1 fi fi PREDISPLAY=$_ntr_predisplay POSTDISPLAY=$_ntr_postdisplay - LBUFFER="$_ntr_lbuffer$LBUFFER" - RBUFFER="$RBUFFER$_ntr_rbuffer" + LBUFFER="$_ntr_lbuffer$BUFFER" + RBUFFER="$_ntr_rbuffer" + MARK=${#_ntr_lbuffer} fi return $_ntr_stat -- cgit v1.2.3 From a8e18dc370eefac3919b8c1a92dbbb2c3e2cf08d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 16 Jul 2015 12:07:48 +0000 Subject: 35807: edit-command-line: Fix for non-7bit-data (after 35769) Bug reported and fix suggested by Mikael. --- ChangeLog | 5 +++++ Functions/Zle/edit-command-line | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'Functions/Zle') diff --git a/ChangeLog b/ChangeLog index d22c727f5..989516b8c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-07-24 Daniel Shahaf + + * 35807: Functions/Zle/edit-command-line: edit-command-line: + Fix for non-7bit-data (after 35769) + 2015-07-24 Oliver Kiddle * 35865: Doc/Zsh/prompt.yo: document %^ prompt expansion diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line index 2ad4825b7..2c7f34b8b 100644 --- a/Functions/Zle/edit-command-line +++ b/Functions/Zle/edit-command-line @@ -9,9 +9,12 @@ () { exec Date: Wed, 5 Aug 2015 15:44:18 +0200 Subject: unposted (c.f. Bart: 35902): use - after zle -U in case $key is - --- ChangeLog | 5 +++++ Functions/Zle/incremental-complete-word | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'Functions/Zle') diff --git a/ChangeLog b/ChangeLog index a135c650a..65c9153d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-08-05 Oliver Kiddle + + * unposted (c.f. 35902): Functions/Zle/incremental-complete-word: + use - after zle -U in case $key starts with - + 2015-08-04 Daniel Shahaf * unposted: Src/builtin.c: Typo fix. diff --git a/Functions/Zle/incremental-complete-word b/Functions/Zle/incremental-complete-word index 67a9d4744..ccc007543 100644 --- a/Functions/Zle/incremental-complete-word +++ b/Functions/Zle/incremental-complete-word @@ -69,7 +69,7 @@ incremental-complete-word() { '#key' -ne '#\\C-g' ]]; do twid=$wid if [[ "$key" = ${~stop} ]]; then - zle -U "$key" + zle -U - "$key" return elif [[ "$key" = ${~brk} ]]; then return -- 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 'Functions/Zle') 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 From 795e6eb9b3a245e1cf5d173dd9d0b9c2b9bd2078 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sun, 16 Aug 2015 22:23:06 -0700 Subject: 36195, 36196: wrapper of bracketed-paste for compatibilty with url-quote-magic and other self-insert wrapper widgets --- ChangeLog | 6 ++ Functions/Zle/bracketed-paste-magic | 192 ++++++++++++++++++++++++++++++++++++ 2 files changed, 198 insertions(+) create mode 100644 Functions/Zle/bracketed-paste-magic (limited to 'Functions/Zle') diff --git a/ChangeLog b/ChangeLog index 2966957fb..5c3932493 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2015-08-16 Barton E. Schaefer + + * 36195, 36196: Functions/Zle/bracketed-paste-magic: wrapper of + bracketed-paste for compatibilty with url-quote-magic and other + self-insert wrapper widgets + 2015-08-15 Barton E. Schaefer * 36180: Src/jobs.c: avoid infinite job stop/continue loop on diff --git a/Functions/Zle/bracketed-paste-magic b/Functions/Zle/bracketed-paste-magic new file mode 100644 index 000000000..da106d1ac --- /dev/null +++ b/Functions/Zle/bracketed-paste-magic @@ -0,0 +1,192 @@ +# Starting with zsh-5.0.9, ZLE began to recognize the "bracketed paste" +# capability of terminal emulators, that is, the sequences $'\e[200~' to +# start a paste and $'\e[201~' to indicate the end of the pasted text. +# Pastes are handled by the bracketed-paste widget and insert literally +# into the editor buffer rather than being interpreted as keystrokes. +# +# This disables some common usages where the self-insert widget has been +# replaced in order to accomplish some extra processing. An example is +# the contributed url-quote-magic widget. The bracketed-paste-magic +# widget replaces bracketed-paste with a wrapper that re-enables these +# self-insert actions, and other actions as selected by the zstyles +# described below. +# +# Setup: +# autoload -Uz bracketed-paste-magic +# zle -N bracketed-paste bracketed-paste-magic + +# The following zstyles may be set to control processing of pasted text. +# +# active-widgets +# Looked up in the context :bracketed-paste-magic to obtain a list of +# patterns that match widget names that should be activated during the +# paste. All other key sequences are processed as self-insert-unmeta. +# The default is 'self-*' so any user-defined widgets named with that +# prefix are active along with the builtin self-insert. If this style is +# not set (note: it must be explicitly deleted after loading this +# function, otherwise it becomes set by default) or has no value, no +# widgets are active and the pasted text is inserted literally. If the +# value includes undefined-key, any unknown sequences are discarded from +# the pasted text. +# +# inactive-keys +# This is the inverse of active-widgets, it lists key sequences that +# always use self-insert-unmeta even when bound to an active-widget. +# Note that this is a list of literal key sequences, not patterns. +# This style is in context :bracketed-paste-magic and has no default. +# +# paste-init +# paste-finish +# Also looked up in the context :bracketed-paste-magic, these styles +# each are a list of function names. They are executed in widget +# context but are called as functions (NOT as widgets with "zle name"). +# They also run in zsh emulation context set by bracketed-paste-magic. +# As with hooks, the functions are called in order until one of them +# returns a nonzero exit status. The parameter PASTED contains the +# current state of the pasted text, other ZLE parameters are as usual. +# Although a nonzero status stops each list of functions, it does NOT +# abort the entire paste operation; use "zle send-break" for that. + +# IMPORTANT: During processing of the paste (after paste-init and +# before paste-finish), BUFFER starts empty and history is restricted, +# so cursor motions etc. may not pass outside of the pasted content. +# However, the paste-init functions have access to the full history and +# the original BUFFER, so they may for example move words from BUFFER +# into PASTED to make those words visible to the active-widgets. + +# Establish default values for styles, but only if not already set +zstyle -m :bracketed-paste-magic active-widgets '*' || + zstyle ':bracketed-paste-magic' active-widgets 'self-*' + +# Helper/example paste-init for exposing a word prefix inside PASTED. +# Useful with url-quote-magic if you have http://... on the line and +# are pasting additional text on the end of the URL. +# +# Usage: +# zstyle :bracketed-paste-magic paste-init backward-extend-paste +# +# TODO: rewrite this using match-words-by-style +# +backward-extend-paste() { + : emulate -LR zsh # Already set by bracketed-paste-magic + integer bep_mark=$MARK bep_region=$REGION_ACTIVE + if (( REGION_ACTIVE && MARK < CURSOR )); then + zle .exchange-point-and-mark + fi + if (( CURSOR )); then + local -a bep_words=( ${(z)LBUFFER} ) + if [[ -n $bep_words[-1] && $LBUFFER = *$bep_words[-1] ]]; then + PASTED=$bep_words[-1]$PASTED + LBUFFER=${LBUFFER%${bep_words[-1]}} + fi + fi + if (( MARK > bep_mark )); then + zle .exchange-point-and-mark + fi + REGION_ACTIVE=$bep_region +} + +# Example paste-finish for quoting the pasted text. +# +# Usage e.g.: +# zstyle :bracketed-paste-magic paste-finish quote-paste +# zstyle :bracketed-paste-magic:finish quote-style qqq +# +# Using "zstyle -e" to examine $PASTED lets you choose different quotes +# depending on context. +# +# To forcibly turn off numeric prefix quoting, use e.g.: +# zstyle :bracketed-paste-magic:finish quote-style none +# +quote-paste() { + : emulate -LR zsh # Already set by bracketed-paste-magic + local qstyle + # If there's a quoting style, be sure .bracketed-paste leaves it alone + zstyle -s :bracketed-paste-magic:finish quote-style qstyle && NUMERIC=1 + case $qstyle in + (b) PASTED=${(b)PASTED};; + (q-) PASTED=${(q-)PASTED};; + (\\|q) PASTED=${(q)PASTED};; + (\'|qq) PASTED=${(qq)PASTED};; + (\"|qqq) PASTED=${(qqq)PASTED};; + (\$|qqqq) PASTED=${(qqqq)PASTED};; + (Q) PASTED=${(Q)PASTED};; + esac +} + +# Now the actual function + +bracketed-paste-magic() { + emulate -LR zsh + local -a bpm_hooks bpm_inactive + local PASTED bpm_func bpm_active + + # Set PASTED and run the paste-init functions + zle .bracketed-paste PASTED + if zstyle -a :bracketed-paste-magic paste-init bpm_hooks; then + for bpm_func in $bpm_hooks; do + if (( $+functions[$bpm_func] )); then + $bpm_func || break + fi + done + fi + + # Save context, create a clean slate for the paste + integer bpm_mark=$MARK bpm_cursor=$CURSOR bpm_region=$REGION_ACTIVE + integer bpm_numeric=${NUMERIC:-1} + local bpm_buffer=$BUFFER + fc -p -a /dev/null 0 0 + BUFFER= + + zstyle -a :bracketed-paste-magic inactive-keys bpm_inactive + if zstyle -s :bracketed-paste-magic active-widgets bpm_active '|'; then + # There are active widgets. Reprocess $PASTED as keystrokes. + NUMERIC=1 + zle -U - $PASTED + while [[ -n $PASTED ]] && zle .read-command; do + PASTED=${PASTED#$KEYS} + if [[ $KEYS = ${(~j:|:)${(b)bpm_inactive}} ]]; then + zle .self-insert-unmeta + else + case $REPLY in + (${~bpm_active}) zle $REPLY;; + (*) zle .self-insert-unmeta;; + esac + fi + done + PASTED=$BUFFER + fi + + # Restore state + BUFFER=$bpm_buffer + MARK=$bpm_mark + CURSOR=$bpm_cursor + REGION_ACTIVE=$bpm_region + NUMERIC=$bpm_numeric + fc -P + + # PASTED has been updated, run the paste-finish functions + if zstyle -a :bracketed-paste-magic paste-finish bpm_hooks; then + for bpm_func in $bpm_hooks; do + if (( $+functions[$bpm_func] )); then + $bpm_func || break + fi + done + fi + + # Reprocess $PASTED as an actual paste this time + zle -U - $PASTED$'\e[201~' # append paste-end marker + zle .bracketed-paste + zle .split-undo + + # Arrange to display highlighting if necessary + if [[ -n ${(M)zle_highlight:#paste:*} ]]; then + zle -R + zle .read-command && zle -U - $KEYS + fi +} + +# Handle zsh autoloading conventions +if [[ $zsh_eval_context = *loadautofunc && ! -o kshautoload ]]; then + bracketed-paste-magic "$@" +fi -- cgit v1.2.3 From 2f2808098b9326922f17297041b97241c15aa595 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sun, 16 Aug 2015 22:52:21 -0700 Subject: unposted: mention bracketed-paste-magic in url-quote-magic comments --- ChangeLog | 7 ++++++- Functions/Zle/url-quote-magic | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'Functions/Zle') diff --git a/ChangeLog b/ChangeLog index c8b2c6f2b..11794708b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-08-17 Barton E. Schaefer + + * unposted: Functions/Zle/url-quote-magic: mention + bracketed-paste-magic in comment + 2015-08-17 Mikael Magnusson * 36177: Completion/Zsh/Command/_setopt: complete printexitvalue @@ -5,7 +10,7 @@ * 36183: Completion/Unix/Command/_ssh: update to 7.0 -2015-08-16 Barton E. Schaefer +2015-08-16 Barton E. Schaefer * 36195, 36196: Functions/Zle/bracketed-paste-magic: wrapper of bracketed-paste for compatibilty with url-quote-magic and other diff --git a/Functions/Zle/url-quote-magic b/Functions/Zle/url-quote-magic index fbcc7c19c..362d15c44 100644 --- a/Functions/Zle/url-quote-magic +++ b/Functions/Zle/url-quote-magic @@ -8,6 +8,12 @@ # autoload -Uz url-quote-magic # zle -N self-insert url-quote-magic +# As of zsh-5.0.9, the following may also be necessary in order to apply +# quoting to copy-pasted URLs: +# autload -Uz bracketed-paste-magic +# zle -N bracketed-paste bracketed-paste-magic +# See also backward-extend-paste in bracketed-paste-magic source file. + # A number of zstyles may be set to control the quoting behavior. # # url-metas -- cgit v1.2.3 From c239a7bd91d8cfdc8b8aaf42059add04ba4c16c2 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Mon, 17 Aug 2015 20:59:00 -0700 Subject: 36212: save and restore HISTNO along with other editor state, for sanity of "zle undo" --- ChangeLog | 5 +++++ Functions/Zle/narrow-to-region | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'Functions/Zle') diff --git a/ChangeLog b/ChangeLog index 7a84c0a9b..6dd37caf9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-08-17 Barton E. Schaefer + + * 36212: Functions/Zle/narrow-to-region: save and restore HISTNO + along with other editor state, for sanity of "zle undo" + 2015-08-18 brian m. carlson * 36209: Functions/VCS_Info/Backends/VCS_INFO_get_data_git: diff --git a/Functions/Zle/narrow-to-region b/Functions/Zle/narrow-to-region index 0ef28a8dc..261d821a9 100644 --- a/Functions/Zle/narrow-to-region +++ b/Functions/Zle/narrow-to-region @@ -32,7 +32,7 @@ setopt localoptions noshwordsplit noksharrays 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_savelim=UNDO_LIMIT_NO _ntr_changeno _ntr_histno=HISTNO integer _ntr_start _ntr_end _ntr_swap _ntr_cursor=$CURSOR _ntr_mark=$MARK integer _ntr_stat @@ -108,7 +108,7 @@ if [[ -n $_ntr_save || -z $_ntr_restore ]]; then builtin typeset -ga $_ntr_save set -A $_ntr_save "${_ntr_predisplay}" "${_ntr_postdisplay}" \ "${_ntr_savelim}" "${_ntr_changeno}" \ - "${_ntr_start}" "${_ntr_end}" || return 1 + "${_ntr_start}" "${_ntr_end}" "${_ntr_histno}" || return 1 fi BUFFER=${BUFFER[_ntr_start+1,_ntr_end]} @@ -135,13 +135,15 @@ if [[ -n $_ntr_restore || -z $_ntr_save ]]; 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 + _ntr_end="${${(@P)_ntr_restore}[6]}" + _ntr_histno="${${(@P)_ntr_restore}[7]}" }; then zle -M Failed. >&2 return 1 fi fi _ntr_newbuf="$BUFFER" + HISTNO=_ntr_histno zle undo $_ntr_changeno PREDISPLAY=$_ntr_predisplay POSTDISPLAY=$_ntr_postdisplay -- cgit v1.2.3