diff options
Diffstat (limited to 'Functions/Zle')
-rw-r--r-- | Functions/Zle/forward-word-match | 36 | ||||
-rw-r--r-- | Functions/Zle/replace-string | 9 | ||||
-rw-r--r-- | Functions/Zle/select-word-style | 138 | ||||
-rw-r--r-- | Functions/Zle/split-shell-arguments | 2 | ||||
-rw-r--r-- | Functions/Zle/url-quote-magic | 5 |
5 files changed, 105 insertions, 85 deletions
diff --git a/Functions/Zle/forward-word-match b/Functions/Zle/forward-word-match index 50e18cbde..e5b5ef3a6 100644 --- a/Functions/Zle/forward-word-match +++ b/Functions/Zle/forward-word-match @@ -8,32 +8,36 @@ local -a matched_words integer count=${NUMERIC:-1} if (( count < 0 )); then - (( NUMERIC = -count )) - zle ${WIDGET/forward/backward} - return + (( NUMERIC = -count )) + zle ${WIDGET/forward/backward} + return fi while (( count-- )); do - - match-words-by-style - + match-words-by-style + + if zstyle -t $curcontext skip-whitespace-first; then + # Standard non-zsh behaviour: skip leading whitespace and the word. + word=$matched_words[4]$matched_words[5] + else + # Traditional zsh behaviour. # For some reason forward-word doesn't work like the other word # commands; it skips whitespace only after any matched word # characters. - if [[ -n $matched_words[4] ]]; then - # just skip the whitespace - word=$matched_words[4] + # just skip the whitespace + word=$matched_words[4] else - # skip the word and trailing whitespace - word=$matched_words[5]$matched_words[6] + # skip the word and trailing whitespace + word=$matched_words[5]$matched_words[6] fi + fi - if [[ -n $word ]]; then - (( CURSOR += ${#word} )) - else - return 1 - fi + if [[ -n $word ]]; then + (( CURSOR += ${#word} )) + else + return 1 + fi done return 0 diff --git a/Functions/Zle/replace-string b/Functions/Zle/replace-string index a3416a403..68aac28d2 100644 --- a/Functions/Zle/replace-string +++ b/Functions/Zle/replace-string @@ -4,6 +4,9 @@ setopt extendedglob autoload -Uz read-from-minibuffer replace-string-again local p1 p2 +integer changeno=$UNDO_CHANGE_NO + +{ if [[ -n $_replace_string_src ]]; then p1="[$_replace_string_src -> $_replace_string_rep]"$'\n' @@ -30,4 +33,10 @@ if [[ -n $REPLY ]]; then typeset -g _replace_string_rep=$REPLY fi +} always { + # Undo back to the original line; we don't want the + # undo history of editing the strings left. + zle undo $changeno +} + replace-string-again $curwidget diff --git a/Functions/Zle/select-word-style b/Functions/Zle/select-word-style index 95d2e4446..1e472229c 100644 --- a/Functions/Zle/select-word-style +++ b/Functions/Zle/select-word-style @@ -4,71 +4,75 @@ setopt extendedglob local -a word_functions word_functions=(backward-kill-word backward-word - capitalize-word down-case-word - forward-word kill-word - transpose-words up-case-word) + capitalize-word down-case-word + forward-word kill-word + transpose-words up-case-word) [[ -z $1 ]] && autoload -Uz read-from-minibuffer -local REPLY detail f wordstyle +local REPLY detail f wordstyle teststyle if ! zle -l $word_functions[1]; then - for f in $word_functions; do - autoload -Uz $f-match - zle -N $f $f-match - done + for f in $word_functions; do + autoload -Uz $f-match + zle -N $f $f-match + done fi while true; do - - if [[ -n $WIDGET && -z $1 ]]; then - read-from-minibuffer -k1 "Word styles (hit return for more detail): + if [[ -n $WIDGET && -z $1 ]]; then + read-from-minibuffer -k1 "Word styles (hit return for more detail): (b)ash (n)ormal (s)hell (w)hitespace (d)efault (q)uit (B), (N), (S), (W) as above with subword matching ${detail}? " || return 1 - else - REPLY=$1 - fi - - detail= - - case $REPLY in - ([bB]*) - # bash style - wordstyle=standard - zstyle ':zle:*' word-chars '' - ;; - - ([nN]*) - # normal zsh style - wordstyle=standard - zstyle ':zle:*' word-chars "$WORDCHARS" - ;; - - ([sS]*) - # shell command arguments or special tokens - wordstyle=shell - ;; - - ([wW]*) - # whitespace-delimited - wordstyle=space - ;; - - (d*) - # default: could also return widgets to builtins here - wordstyle= - zstyle -d ':zle:*' word-chars - ;; - - (q*) - # quit without setting - return 1 - ;; - - (*) - detail="\ + else + REPLY=$1 + fi + + detail= + + case $REPLY in + ([bB]*) + # bash style + wordstyle=standard + zstyle ':zle:*' word-chars '' + zstyle ':zle:*' skip-whitespace-first true + ;; + + ([nN]*) + # normal zsh style + wordstyle=standard + zstyle ':zle:*' word-chars "$WORDCHARS" + zstyle ':zle:*' skip-whitespace-first false + ;; + + ([sS]*) + # shell command arguments or special tokens + wordstyle=shell + zstyle ':zle:*' skip-whitespace-first false + ;; + + ([wW]*) + # whitespace-delimited + wordstyle=space + zstyle ':zle:*' skip-whitespace-first false + ;; + + (d*) + # default: could also return widgets to builtins here + wordstyle= + zstyle -d ':zle:*' word-chars + zstyle -d ':zle:*' skip-whitespace-first + ;; + + (q*) + # quit without setting + return 1 + ;; + + (*) + detail="\ (b)ash: Word characters are alphanumerics only (n)ormal: Word characters are alphanumerics plus \$WORDCHARS (s)hell: Words are command arguments using shell syntax @@ -76,21 +80,21 @@ ${detail}? " || return 1 (d)efault: Use default, no special handling (usually same as \`n') (q)uit: Quit without setting a new style " - if [[ -z $WIDGET || -n $1 ]]; then - print "Usage: $0 word-style + if [[ -z $WIDGET || -n $1 ]]; then + print "Usage: $0 word-style where word-style is one of the characters in parentheses: $detail" >&2 - return 1 - fi - continue - ;; - esac - - if [[ -n $wordstyle ]]; then - if [[ $REPLY = [[:upper:]]* ]]; then - wordstyle+=-subword - fi - zstyle ':zle:*' word-style $wordstyle + return 1 + fi + continue + ;; + esac + + if [[ -n $wordstyle ]]; then + if [[ $REPLY = [[:upper:]]* ]]; then + wordstyle+=-subword fi - return + zstyle ':zle:*' word-style $wordstyle + fi + return done diff --git a/Functions/Zle/split-shell-arguments b/Functions/Zle/split-shell-arguments index 32b04fcb5..11a928719 100644 --- a/Functions/Zle/split-shell-arguments +++ b/Functions/Zle/split-shell-arguments @@ -17,6 +17,7 @@ integer pos=1 cpos=$((CURSOR+1)) opos iword ichar bufwords=(${(Z+n+)BUFFER}) +typeset -ga reply reply=() while [[ ${BUFFER[pos]} = [[:space:]] ]]; do (( pos++ )) @@ -44,6 +45,7 @@ for word in "${bufwords[@]}"; do fi done +typeset -g REPLY REPLY2 if (( iword == 0 )); then # At the end of the line, so off the indexable positions # (but still a valid cursor position). diff --git a/Functions/Zle/url-quote-magic b/Functions/Zle/url-quote-magic index c7bb88c5d..fbcc7c19c 100644 --- a/Functions/Zle/url-quote-magic +++ b/Functions/Zle/url-quote-magic @@ -60,7 +60,7 @@ # Use compsys for nested quoting analysis and command parsing. # Establish default values for styles, but only if not already set -local -a reply +local -a reply match mbegin mend zstyle -m ':url-quote-magic:\*' url-metas '*' || zstyle ':url-quote-magic:*' url-metas '*?[]^(|)~#{}=' @@ -84,7 +84,7 @@ zstyle -m ':urlglobber' url-other-schema '*' || # Define the "urlglobber" helper function and shorthand "globurl" alias function urlglobber { - local -a args globbed localschema otherschema + local -a args globbed localschema otherschema reply local arg command="$1" shift zstyle -s :urlglobber url-local-schema localschema '|' @@ -109,6 +109,7 @@ alias globurl='noglob urlglobber ' function url-quote-magic { setopt localoptions noksharrays extendedglob local qkey="${(q)KEYS}" + local -a reply if [[ "$KEYS" != "$qkey" ]] then local lbuf="$LBUFFER$qkey" |