diff options
Diffstat (limited to 'Functions/Zle')
-rw-r--r-- | Functions/Zle/bracketed-paste-magic | 29 | ||||
-rw-r--r-- | Functions/Zle/bracketed-paste-url-magic | 44 | ||||
-rw-r--r-- | Functions/Zle/edit-command-line | 9 | ||||
-rw-r--r-- | Functions/Zle/match-word-context | 9 | ||||
-rw-r--r-- | Functions/Zle/smart-insert-last-word | 10 |
5 files changed, 74 insertions, 27 deletions
diff --git a/Functions/Zle/bracketed-paste-magic b/Functions/Zle/bracketed-paste-magic index 464c6b339..2b2bc630d 100644 --- a/Functions/Zle/bracketed-paste-magic +++ b/Functions/Zle/bracketed-paste-magic @@ -116,10 +116,14 @@ quote-paste() { # Now the actual function bracketed-paste-magic() { - # Fast exit in the vi-mode cut-buffer context if [[ "$LASTWIDGET" = *vi-set-buffer ]]; then + # Fast exit in the vi-mode cut-buffer context zle .bracketed-paste return + else + # Capture the pasted text in $PASTED + local PASTED REPLY + zle .bracketed-paste PASTED fi # Really necessary to go to this much effort? @@ -127,10 +131,9 @@ bracketed-paste-magic() { emulate -L zsh local -a bpm_hooks bpm_inactive - local PASTED bpm_func bpm_active bpm_keymap=$KEYMAP + local bpm_func bpm_active bpm_keymap=$KEYMAP - # Set PASTED and run the paste-init functions - zle .bracketed-paste PASTED + # Run the paste-init functions if zstyle -a :bracketed-paste-magic paste-init bpm_hooks; then for bpm_func in $bpm_hooks; do if (( $+functions[$bpm_func] )); then @@ -164,25 +167,17 @@ bracketed-paste-magic() { integer bpm_limit=$UNDO_LIMIT_NO bpm_undo=$UNDO_CHANGE_NO UNDO_LIMIT_NO=$UNDO_CHANGE_NO - local mbchar - integer ismb while [[ -n $PASTED ]] && zle .read-command; do - mbchar=$KEYS - ismb=0 - while [[ $mbchar = [[:INCOMPLETE:]]* ]] && zle .read-command; do - mbchar+=$KEYS - ismb=1 - done - PASTED=${PASTED#$mbchar} - if [[ ismb -ne 0 || $mbchar = ${(~j:|:)${(b)bpm_inactive}} ]]; then - LBUFFER+=$mbchar + PASTED=${PASTED#$KEYS} + if [[ $KEYS = ${(~j:|:)${(b)bpm_inactive}} ]]; then + zle .self-insert else case $REPLY in (${~bpm_active}) function () { emulate -L $bpm_emulate; set -$bpm_opts zle $REPLY };; - (*) LBUFFER+=$mbchar; + (*) zle .self-insert;; esac fi done @@ -221,7 +216,7 @@ bracketed-paste-magic() { zle .split-undo # Arrange to display highlighting if necessary - if [[ -n ${(M)zle_highlight:#paste:*} ]]; then + if [[ -z $zle_highlight || -n ${(M)zle_highlight:#paste:*} ]]; then zle -R zle .read-command && zle -U - $KEYS fi diff --git a/Functions/Zle/bracketed-paste-url-magic b/Functions/Zle/bracketed-paste-url-magic new file mode 100644 index 000000000..06dee2657 --- /dev/null +++ b/Functions/Zle/bracketed-paste-url-magic @@ -0,0 +1,44 @@ +# bracketed-paste-url-magic quotes pasted urls automatically, if the +# paste exactly starts with a url, eg no spaces or other characters precede it +# +# If the numeric argument is provided (eg, pressing alt-0 or alt-1 in emacs mode, +# or just the number by itself in vi command mode), then +# 0 is the default and means auto detect urls +# 1 means always quote +# any other value means never quote +# +# To use this widget, put this in your startup files (eg, .zshrc) +# +# autoload -Uz bracketed-paste-url-magic +# zle -N bracketed-paste bracketed-paste-url-magic +# +# You can customize which schemas are to be quoted by using +# +# zstyle :bracketed-paste-url-magic schema http https ftp +# +# The default can be seen just below. + +local -a schema +zstyle -a :bracketed-paste-url-magic schema schema || schema=(http https ftp ftps file ssh sftp) + +local wantquote=${NUMERIC:-0} +local content +local start=$#LBUFFER + +zle .$WIDGET -N content + +if (( $wantquote == 0 )); then + if [[ $content = (${(~j:|:)schema})://* ]]; then + wantquote=1 + fi +fi + +if (( $wantquote == 1 )); then + content=${(q-)content} +fi + +LBUFFER+=$content + +YANK_START=$start +YANK_END=$#LBUFFER +zle -f yank diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line index 2c7f34b8b..103a1c1a5 100644 --- a/Functions/Zle/edit-command-line +++ b/Functions/Zle/edit-command-line @@ -11,13 +11,16 @@ # Compute the cursor's position in bytes, not characters. setopt localoptions nomultibyte - integer byteoffset=$(( $#PREBUFFER + $#LBUFFER + 1 )) # Open the editor, placing the cursor at the right place if we know how. local editor=${${VISUAL:-${EDITOR:-vi}}} case $editor in - (*vim*) ${=editor} -c "normal! ${byteoffset}go" -- $1;; - (*emacs*) ${=editor} $1 -eval "(goto-char ${byteoffset})";; + (*vim*) + integer byteoffset=$(( $#PREBUFFER + $#LBUFFER + 1 )) + ${=editor} -c "normal! ${byteoffset}go" -- $1;; + (*emacs*) + local lines=( ${(f):-"$PREBUFFER$LBUFFER"} ) + ${=editor} +${#lines}:$((${#lines[-1]} + 1)) $1;; (*) ${=editor} $1;; esac diff --git a/Functions/Zle/match-word-context b/Functions/Zle/match-word-context index 7f1154498..8793483f4 100644 --- a/Functions/Zle/match-word-context +++ b/Functions/Zle/match-word-context @@ -7,7 +7,7 @@ setopt extendedglob local -a worcon bufwords local pat tag lastword word backword forword -integer iword +integer iword between zstyle -a $curcontext word-context worcon || return 0 @@ -25,13 +25,18 @@ if [[ $lastword = ${bufwords[iword]} ]]; then # If the word immediately left of the cursor is complete, # we're not on it for forward operations. forword=${bufwords[iword+1]} + # If, furthermore, we're on whitespace, then we're between words. + # It can't be significant whitespace because the previous word is complete. + [[ $RBUFFER[1] = [[:space:]] ]] && between=1 else # We're on a word. forword=${bufwords[iword]} fi backword=${bufwords[iword]} -if [[ $curcontext = *back* ]]; then +if [[ between -ne 0 && $curcontext = *between* ]]; then + word=' ' +elif [[ $curcontext = *back* ]]; then word=$backword else word=$forword diff --git a/Functions/Zle/smart-insert-last-word b/Functions/Zle/smart-insert-last-word index 67adea760..cf8715dfe 100644 --- a/Functions/Zle/smart-insert-last-word +++ b/Functions/Zle/smart-insert-last-word @@ -60,7 +60,7 @@ then lcursor=$_ilw_lcursor else NUMERIC=1 - _ilw_lcursor=$lcursor + typeset -g _ilw_lcursor=$lcursor fi # Handle the up to three arguments of .insert-last-word if (( $+1 )) @@ -73,8 +73,8 @@ then (( NUMERIC )) || LBUFFER[lcursor+1,cursor+1]='' numeric=$((-(${2:--numeric}))) fi -_ilw_hist=$HISTNO -_ilw_count=$NUMERIC +typeset -g _ilw_hist=$HISTNO +typeset -g _ilw_count=$NUMERIC if [[ -z "$numeric" ]] then @@ -119,7 +119,7 @@ fi (( NUMERIC > $#lastcmd )) && return 1 LBUFFER[lcursor+1,cursor+1]=$lastcmd[-NUMERIC] -_ilw_cursor=$CURSOR +typeset -g _ilw_cursor=$CURSOR # This is necessary to update UNDO_CHANGE_NO immediately -zle split-undo && _ilw_changeno=$UNDO_CHANGE_NO +zle split-undo && typeset -g _ilw_changeno=$UNDO_CHANGE_NO |