diff options
Diffstat (limited to 'Functions/Zle')
-rw-r--r-- | Functions/Zle/down-line-or-beginning-search | 2 | ||||
-rw-r--r-- | Functions/Zle/keeper | 27 | ||||
-rw-r--r-- | Functions/Zle/modify-current-argument | 35 | ||||
-rw-r--r-- | Functions/Zle/up-line-or-beginning-search | 2 |
4 files changed, 43 insertions, 23 deletions
diff --git a/Functions/Zle/down-line-or-beginning-search b/Functions/Zle/down-line-or-beginning-search index fbd2c3341..4c713f197 100644 --- a/Functions/Zle/down-line-or-beginning-search +++ b/Functions/Zle/down-line-or-beginning-search @@ -3,6 +3,8 @@ emulate -L zsh +typeset -g __searching __savecursor + if [[ ${+NUMERIC} -eq 0 && ( $LASTWIDGET = $__searching || $RBUFFER != *$'\n'* ) ]] then diff --git a/Functions/Zle/keeper b/Functions/Zle/keeper index c29b22d6f..a40125771 100644 --- a/Functions/Zle/keeper +++ b/Functions/Zle/keeper @@ -4,6 +4,9 @@ # Shell Corner column on UnixReview.com in January 2005 at the URL # <http://www.unixreview.com/documents/s=9513/ur0501a/ur0501a.htm> # +# Article still available on the Wayback Machine: +# <http://web.archive.org/web/20050207041146/http://www.unixreview.com/documents/s=9513/ur0501a/ur0501a.htm> +# # A few minor edits have been made to those functions for this file. Key # bindings are commented out to avoid clashes with any existing bindings. ## @@ -69,17 +72,21 @@ zstyle ':completion:expand-kept-result:*' completer _insert_kept # "_insert_kept". _expand_word_and_keep() { - function compadd() { - local -A args - zparseopts -E -A args J: - if [[ $args[-J] == all-expansions ]] - then - builtin compadd -A kept "$@" - kept=( ${(Q)${(z)kept}} ) - fi - builtin compadd "$@" + { + function compadd { + local -A args + zparseopts -E -A args J: + if [[ $args[-J] == all-expansions ]] + then + builtin compadd -A kept "$@" + kept=( ${(Q)${(z)kept}} ) + fi + builtin compadd "$@" + } + _expand_word + } always { + unfunction compadd } - { _expand_word } always { unfunction compadd } } zle -C _expand_word complete-word _expand_word_and_keep diff --git a/Functions/Zle/modify-current-argument b/Functions/Zle/modify-current-argument index 92851d600..941eb80af 100644 --- a/Functions/Zle/modify-current-argument +++ b/Functions/Zle/modify-current-argument @@ -14,24 +14,27 @@ setopt localoptions noksharrays multibyte local -a reply -integer REPLY REPLY2 fromend endoffset +integer posword poschar fromend endoffset +local REPLY REPLY2 autoload -Uz split-shell-arguments split-shell-arguments +(( posword = REPLY, poschar = REPLY2 )) + # Can't do this unless there's some text under or left of us. -(( REPLY < 2 )) && return 1 +(( posword < 2 )) && return 1 # Get the index of the word we want. -if (( REPLY & 1 )); then +if (( posword & 1 )); then # Odd position; need previous word. - (( REPLY-- )) + (( posword-- )) # Pretend position was just after the end of it. - (( REPLY2 = ${#reply[REPLY]} + 1 )) + (( poschar = ${#reply[posword]} + 1 )) fi # Work out offset from end of string -(( fromend = $REPLY2 - ${#reply[REPLY]} - 1 )) +(( fromend = $poschar - ${#reply[posword]} - 1 )) if (( fromend >= -1 )); then # Cursor is near the end of the word, we'll try to keep it there. endoffset=1 @@ -39,11 +42,17 @@ fi # Length of all characters before current. # Force use of character (not index) counting and join without IFS. -integer wordoff="${(cj..)#reply[1,REPLY-1]}" +integer wordoff="${(cj..)#reply[1,posword-1]}" -# Replacement for current word. This could do anything to ${reply[REPLY]}. -local ARG="${reply[REPLY]}" repl -eval repl=\"$1\" +# Replacement for current word. This could do anything to ${reply[posword]}. +local ARG="${reply[posword]}" repl +if [[ $1 != *ARG* ]]; then + REPLY= + $1 $ARG || return 1 + repl=$REPLY +else + eval repl=\"$1\" +fi if (( !endoffset )) && [[ ${repl[fromend,-1]} = ${ARG[fromend,-1]} ]]; then # If the part of the string from here to the end hasn't changed, @@ -54,8 +63,8 @@ fi # New line: all words before and after current word, with # no additional spaces since we've already got the whitespace # and the replacement word in the middle. -local left="${(j..)reply[1,REPLY-1]}${repl}" -local right="${(j..)reply[REPLY+1,-1]}" +local left="${(j..)reply[1,posword-1]}${repl}" +local right="${(j..)reply[posword+1,-1]}" if [[ endoffset -ne 0 && ${#repl} -ne 0 ]]; then # Place cursor relative to end. @@ -71,5 +80,5 @@ else integer repmax=$(( ${#repl} + 1 )) # Remember CURSOR starts from offset 0 for some reason, so # subtract 1 from positions. - (( CURSOR = wordoff + (REPLY2 > repmax ? repmax : REPLY2) - 1 )) + (( CURSOR = wordoff + (poschar > repmax ? repmax : poschar) - 1 )) fi diff --git a/Functions/Zle/up-line-or-beginning-search b/Functions/Zle/up-line-or-beginning-search index 5348e7ad3..bdc39335a 100644 --- a/Functions/Zle/up-line-or-beginning-search +++ b/Functions/Zle/up-line-or-beginning-search @@ -3,6 +3,8 @@ emulate -L zsh +typeset -g __searching __savecursor + if [[ $LBUFFER == *$'\n'* ]]; then zle .up-line-or-history __searching='' |