diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | Doc/Zsh/contrib.yo | 17 | ||||
-rw-r--r-- | Functions/Zle/.distfiles | 49 | ||||
-rw-r--r-- | Functions/Zle/transpose-lines | 43 |
4 files changed, 99 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog index dec583429..d9a9f9dd8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-06-16 Peter Stephenson <p.w.stephenson@ntlworld.com> + + * 28042: Doc/Zsh/contrib.yo, Functions/Zle/.distfiles, + Functions/Zle/transpose-lines: new widget. + 2010-06-14 Peter Stephenson <pws@csr.com> * 28038: Index: Completion/Zsh/Command/_zstyle, Doc/Zsh/calsys.yo, @@ -13297,5 +13302,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5005 $ +* $Revision: 1.5006 $ ***************************************************** diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index c512f89d9..ac0d32d19 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2073,6 +2073,23 @@ a true value, the search continues upward through the history. When tt(auto-previous) is unset or false (the default), the widget must be invoked repeatedly in order to search earlier history lines. ) +tindex(transpose-lines) +item(tt(transpose-lines))( +Only useful with a multi-line editing buffer; the lines here are +lines within the current on-screen buffer, not history lines. +The effect is similar to the function of the same name in Emacs. + +Transpose the current line with the previous line and move the cursor +to the start of the next line. Repeating this (which can be done by +providing a positive numeric prefix argument) has the effect of moving +the line above the cursor down by a number of lines. + +With a negative numeric prefix argument, requires two lines above the +cursor. These two lines are transposed and the cursor moved to the +start of the previous line. Using a numeric prefix less than -1 +has the effect of moving the line above the cursor up by minus that +number of lines. +) tindex(which-command) item(tt(which-command))( This function is a drop-in replacement for the builtin widget diff --git a/Functions/Zle/.distfiles b/Functions/Zle/.distfiles index 4f01a8c01..2ec4adc22 100644 --- a/Functions/Zle/.distfiles +++ b/Functions/Zle/.distfiles @@ -1,28 +1,45 @@ DISTFILES_SRC=' .distfiles -backward-kill-word-match backward-word-match -capitalize-word-match copy-earlier-word -cycle-completion-positions define-composed-chars -delete-whole-word-match down-case-word-match -down-line-or-beginning-search edit-command-line -forward-word-match history-beginning-search-menu -history-pattern-search history-search-end -incarg incremental-complete-word -insert-composed-char insert-files -insert-unicode-char keeper -keymap+widget kill-word-match +backward-kill-word-match +backward-word-match +capitalize-word-match +copy-earlier-word +cycle-completion-positions +define-composed-chars +delete-whole-word-match +down-case-word-match +down-line-or-beginning-search +edit-command-line +forward-word-match +history-beginning-search-menu +history-pattern-search +history-search-end +incarg +incremental-complete-word +insert-composed-char +insert-files +insert-unicode-char +keeper +keymap+widget +kill-word-match match-word-context match-words-by-style modify-current-argument narrow-to-region -narrow-to-region-invisible predict-on -quote-and-complete-word read-from-minibuffer -replace-string select-word-style +narrow-to-region-invisible +predict-on +quote-and-complete-word +read-from-minibuffer +replace-string replace-string-again +select-word-style smart-insert-last-word split-shell-arguments +transpose-lines transpose-words-match -up-case-word-match up-line-or-beginning-search -url-quote-magic which-command +up-case-word-match +up-line-or-beginning-search +url-quote-magic +which-command zed-set-file-name ' diff --git a/Functions/Zle/transpose-lines b/Functions/Zle/transpose-lines new file mode 100644 index 000000000..06e1da4ac --- /dev/null +++ b/Functions/Zle/transpose-lines @@ -0,0 +1,43 @@ +# Transpose lines. This is like in emacs: with a positive argument +# (default 1) the current line and the previous line are swapped and the +# cursor goes down one line; with a negative argument the previous two +# lines are swapped and the cursor goes up one line. + +emulate -L zsh +setopt extendedglob # xtrace + +local -a match mbegin mend +integer count=${NUMERIC:-1} +local init prev lline final rrline + +if (( ${NUMERIC:-1} < 0 )); then + while (( count++ )); do + [[ $LBUFFER != (#b)(|*$'\n')([^$'\n']#$'\n')([^$'\n']#$'\n')([^$'\n']#) ]] && return 1 + + LBUFFER=$match[1]$match[3] + RBUFFER=$match[2]$match[4]$RBUFFER + done +else + while (( count-- )); do + [[ $LBUFFER != (#b)(*)$'\n'([^$'\n']#) ]] && return 1 + + prev=$match[1] + lline=$match[2] + + if [[ $prev = (#b)(*$'\n')([^$'\n']#) ]]; then + init=$match[1] + prev=$match[2] + fi + + if [[ $RBUFFER = (#b)([^$'\n']#)$'\n'(*) ]]; then + rline=$match[1] + final=$match[2] + prev+=$'\n' + else + rline=$RBUFFER + fi + + LBUFFER=$init$lline$rline$'\n'$prev + RBUFFER=$final + done +fi |