1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-01-01 05:16:05 +01:00

28042: transpose-lines widget

This commit is contained in:
Peter Stephenson 2010-06-16 21:50:39 +00:00
parent 14dde08475
commit 091cbd9d58
4 changed files with 99 additions and 17 deletions

View file

@ -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 $
*****************************************************

View file

@ -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

View file

@ -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
'

View file

@ -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