mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-04 10:41:11 +02:00
38770: vi upper/lowercase widgets and shell widget example that reads a vi movement
This commit is contained in:
parent
5ea32ce2fc
commit
a73ae70e82
7 changed files with 112 additions and 1 deletions
|
@ -1,5 +1,9 @@
|
||||||
2016-06-29 Oliver Kiddle <opk@zsh.org>
|
2016-06-29 Oliver Kiddle <opk@zsh.org>
|
||||||
|
|
||||||
|
* 38770: Src/Zle/zle_keymap.c, Src/Zle/zle_vi.c, Doc/Zsh/zle.yo,
|
||||||
|
Doc/Zsh/contrib.yo, Functions/Zle/vi-pipe: vi upper/lowercase
|
||||||
|
widgets and shell widget example that reads a vi movement
|
||||||
|
|
||||||
* 38752: Src/builtin.c: add comments to explain use of stdout
|
* 38752: Src/builtin.c: add comments to explain use of stdout
|
||||||
instead of stderr for the which builtin
|
instead of stderr for the which builtin
|
||||||
|
|
||||||
|
|
|
@ -2968,6 +2968,17 @@ and aliases `tt(globurl)' to `tt(noglob urlglobber)'. This function takes
|
||||||
a local URL apart, attempts to pattern-match the local file portion of the
|
a local URL apart, attempts to pattern-match the local file portion of the
|
||||||
URL path, and then puts the results back into URL format again.
|
URL path, and then puts the results back into URL format again.
|
||||||
)
|
)
|
||||||
|
tindex(vi-pipe)
|
||||||
|
item(tt(vi-pipe))(
|
||||||
|
This function reads a movement command from the keyboard and then
|
||||||
|
prompts for an external command. The part of the buffer covered by
|
||||||
|
the movement is piped to the external command and then replaced by
|
||||||
|
the command's output. If the movement command is bound to vi-pipe,
|
||||||
|
the current line is used.
|
||||||
|
|
||||||
|
The function serves as an example for reading a vi movement command
|
||||||
|
from within a user-defined widget.
|
||||||
|
)
|
||||||
tindex(which-command)
|
tindex(which-command)
|
||||||
item(tt(which-command))(
|
item(tt(which-command))(
|
||||||
This function is a drop-in replacement for the builtin widget
|
This function is a drop-in replacement for the builtin widget
|
||||||
|
|
|
@ -1781,6 +1781,13 @@ tindex(down-case-word)
|
||||||
item(tt(down-case-word) (tt(ESC-L ESC-l)) (unbound) (unbound))(
|
item(tt(down-case-word) (tt(ESC-L ESC-l)) (unbound) (unbound))(
|
||||||
Convert the current word to all lowercase and move past it.
|
Convert the current word to all lowercase and move past it.
|
||||||
)
|
)
|
||||||
|
tindex(vi-down-case)
|
||||||
|
item(tt(vi-down-case)) ((unbound) (tt(gu)) (unbound))(
|
||||||
|
Read a movement command from the keyboard, and convert all characters
|
||||||
|
from the cursor position to the endpoint of the movement to lowercase.
|
||||||
|
If the movement command is tt(vi-down-case), swap the case of all
|
||||||
|
characters on the current line.
|
||||||
|
)
|
||||||
tindex(kill-word)
|
tindex(kill-word)
|
||||||
item(tt(kill-word) (tt(ESC-D ESC-d)) (unbound) (unbound))(
|
item(tt(kill-word) (tt(ESC-D ESC-d)) (unbound) (unbound))(
|
||||||
Kill the current word.
|
Kill the current word.
|
||||||
|
@ -1946,6 +1953,13 @@ tindex(vi-unindent)
|
||||||
item(tt(vi-unindent) (unbound) (tt(<)) (unbound))(
|
item(tt(vi-unindent) (unbound) (tt(<)) (unbound))(
|
||||||
Unindent a number of lines.
|
Unindent a number of lines.
|
||||||
)
|
)
|
||||||
|
tindex(vi-up-case)
|
||||||
|
item(tt(vi-up-case)) ((unbound) (tt(gU)) (unbound))(
|
||||||
|
Read a movement command from the keyboard, and convert all characters
|
||||||
|
from the cursor position to the endpoint of the movement to lowercase.
|
||||||
|
If the movement command is tt(vi-up-case), swap the case of all
|
||||||
|
characters on the current line.
|
||||||
|
)
|
||||||
tindex(up-case-word)
|
tindex(up-case-word)
|
||||||
item(tt(up-case-word) (tt(ESC-U ESC-u)) (unbound) (unbound))(
|
item(tt(up-case-word) (tt(ESC-U ESC-u)) (unbound) (unbound))(
|
||||||
Convert the current word to all caps and move past it.
|
Convert the current word to all caps and move past it.
|
||||||
|
|
31
Functions/Zle/vi-pipe
Normal file
31
Functions/Zle/vi-pipe
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# Example of a widget that takes a vi motion
|
||||||
|
|
||||||
|
# Filter part of buffer corresponding to a vi motion through an external
|
||||||
|
# program.
|
||||||
|
|
||||||
|
# To enable with vi compatible bindings use:
|
||||||
|
# autoload -Uz vi-pipe
|
||||||
|
# bindkey -a '!' vi-pipe
|
||||||
|
|
||||||
|
autoload -Uz read-from-minibuffer
|
||||||
|
local _save_cut="$CUTBUFFER" REPLY
|
||||||
|
|
||||||
|
# Use the standard vi-delete to accept a vi motion.
|
||||||
|
zle .vi-delete || return
|
||||||
|
read-from-minibuffer "!"
|
||||||
|
local _save_cur=$CURSOR
|
||||||
|
|
||||||
|
# cut buffer contains the deleted text and can be modified
|
||||||
|
CUTBUFFER="$(eval $REPLY <<<$CUTBUFFER)"
|
||||||
|
|
||||||
|
# put the modified text back in position.
|
||||||
|
if [[ CURSOR -eq 0 || $BUFFER[CURSOR] = $'\n' ]]; then
|
||||||
|
# at the beginning of a line, vi-delete won't have moved the cursor
|
||||||
|
# back to a previous line
|
||||||
|
zle .vi-put-before -n 1
|
||||||
|
else
|
||||||
|
zle .vi-put-after -n 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# restore cut buffer and cursor to the start of the range
|
||||||
|
CUTBUFFER="$_save_cut" CURSOR="$_save_cur"
|
|
@ -143,6 +143,7 @@
|
||||||
"vi-delete", videlete, ZLE_KEEPSUFFIX | ZLE_LASTCOL | ZLE_VIOPER
|
"vi-delete", videlete, ZLE_KEEPSUFFIX | ZLE_LASTCOL | ZLE_VIOPER
|
||||||
"vi-delete-char", videletechar, ZLE_KEEPSUFFIX
|
"vi-delete-char", videletechar, ZLE_KEEPSUFFIX
|
||||||
"vi-digit-or-beginning-of-line", vidigitorbeginningofline, 0
|
"vi-digit-or-beginning-of-line", vidigitorbeginningofline, 0
|
||||||
|
"vi-down-case", vidowncase, ZLE_LASTCOL | ZLE_VIOPER
|
||||||
"vi-down-line-or-history", vidownlineorhistory, ZLE_LINEMOVE
|
"vi-down-line-or-history", vidownlineorhistory, ZLE_LINEMOVE
|
||||||
"vi-end-of-line", viendofline, ZLE_LASTCOL
|
"vi-end-of-line", viendofline, ZLE_LASTCOL
|
||||||
"vi-fetch-history", vifetchhistory, ZLE_LINEMOVE
|
"vi-fetch-history", vifetchhistory, ZLE_LINEMOVE
|
||||||
|
@ -188,6 +189,7 @@
|
||||||
"vi-swap-case", viswapcase, ZLE_LASTCOL
|
"vi-swap-case", viswapcase, ZLE_LASTCOL
|
||||||
"vi-undo-change", viundochange, ZLE_KEEPSUFFIX
|
"vi-undo-change", viundochange, ZLE_KEEPSUFFIX
|
||||||
"vi-unindent", viunindent, ZLE_LASTCOL | ZLE_VIOPER
|
"vi-unindent", viunindent, ZLE_LASTCOL | ZLE_VIOPER
|
||||||
|
"vi-up-case", viupcase, ZLE_LASTCOL | ZLE_VIOPER
|
||||||
"vi-up-line-or-history", viuplineorhistory, ZLE_LINEMOVE
|
"vi-up-line-or-history", viuplineorhistory, ZLE_LINEMOVE
|
||||||
"vi-yank", viyank, ZLE_LASTCOL | ZLE_VIOPER
|
"vi-yank", viyank, ZLE_LASTCOL | ZLE_VIOPER
|
||||||
"vi-yank-eol", viyankeol, 0
|
"vi-yank-eol", viyankeol, 0
|
||||||
|
|
|
@ -1374,8 +1374,11 @@ default_bindings(void)
|
||||||
bindkey(amap, "ge", refthingy(t_vibackwardwordend), NULL);
|
bindkey(amap, "ge", refthingy(t_vibackwardwordend), NULL);
|
||||||
bindkey(amap, "gE", refthingy(t_vibackwardblankwordend), NULL);
|
bindkey(amap, "gE", refthingy(t_vibackwardblankwordend), NULL);
|
||||||
bindkey(amap, "gg", refthingy(t_beginningofbufferorhistory), NULL);
|
bindkey(amap, "gg", refthingy(t_beginningofbufferorhistory), NULL);
|
||||||
bindkey(amap, "g~", refthingy(t_vioperswapcase), NULL);
|
bindkey(amap, "gu", refthingy(t_vidowncase), NULL);
|
||||||
|
bindkey(amap, "gU", refthingy(t_viupcase), NULL);
|
||||||
bindkey(amap, "g~~", NULL, "g~g~");
|
bindkey(amap, "g~~", NULL, "g~g~");
|
||||||
|
bindkey(amap, "guu", NULL, "gugu");
|
||||||
|
bindkey(amap, "gUU", NULL, "gUgU");
|
||||||
|
|
||||||
/* emacs mode: arrow keys */
|
/* emacs mode: arrow keys */
|
||||||
add_cursor_key(emap, TCUPCURSOR, t_uplineorhistory, 'A');
|
add_cursor_key(emap, TCUPCURSOR, t_uplineorhistory, 'A');
|
||||||
|
|
|
@ -729,6 +729,52 @@ vioperswapcase(UNUSED(char **args))
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**/
|
||||||
|
int
|
||||||
|
viupcase(UNUSED(char **args))
|
||||||
|
{
|
||||||
|
int oldcs, c2, ret = 1;
|
||||||
|
|
||||||
|
/* get the range */
|
||||||
|
startvichange(1);
|
||||||
|
if ((c2 = getvirange(0)) != -1) {
|
||||||
|
oldcs = zlecs;
|
||||||
|
/* covert the case of all letters within range */
|
||||||
|
while (zlecs < c2) {
|
||||||
|
zleline[zlecs] = ZC_toupper(zleline[zlecs]);
|
||||||
|
INCCS();
|
||||||
|
}
|
||||||
|
/* go back to the first line of the range */
|
||||||
|
zlecs = oldcs;
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
vichgflag = 0;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**/
|
||||||
|
int
|
||||||
|
vidowncase(UNUSED(char **args))
|
||||||
|
{
|
||||||
|
int oldcs, c2, ret = 1;
|
||||||
|
|
||||||
|
/* get the range */
|
||||||
|
startvichange(1);
|
||||||
|
if ((c2 = getvirange(0)) != -1) {
|
||||||
|
oldcs = zlecs;
|
||||||
|
/* convert the case of all letters within range */
|
||||||
|
while (zlecs < c2) {
|
||||||
|
zleline[zlecs] = ZC_tolower(zleline[zlecs]);
|
||||||
|
INCCS();
|
||||||
|
}
|
||||||
|
/* go back to the first line of the range */
|
||||||
|
zlecs = oldcs;
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
vichgflag = 0;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
int
|
int
|
||||||
virepeatchange(UNUSED(char **args))
|
virepeatchange(UNUSED(char **args))
|
||||||
|
|
Loading…
Reference in a new issue