mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-27 16:50:58 +01:00
Merge of trunk updates workers/20708 and workers/22854.
This commit is contained in:
parent
298de9ddb1
commit
4beedf221e
2 changed files with 40 additions and 1 deletions
|
|
@ -794,8 +794,10 @@ not used. Hence it is still possible to call tt(executed-named-cmd) and
|
|||
similar functions while reading a value.
|
||||
)
|
||||
tindex(replace-string)
|
||||
tindex(replace-string-again)
|
||||
tindex(replace-pattern)
|
||||
item(tt(replace-string), tt(replace-pattern))(
|
||||
xitem(tt(replace-string), tt(replace-pattern))
|
||||
item(tt(replace-string-again), tt(replace-pattern-again))(
|
||||
The function tt(replace-string) implements two widgets.
|
||||
If defined under the same name as the function, it prompts for two
|
||||
strings; the first (source) string will be replaced by the second
|
||||
|
|
@ -814,6 +816,20 @@ replaced by the var(N)th parenthesised expression matched. The form
|
|||
`tt(\{)var(N)tt(})' may be used to protect the digit from following
|
||||
digits.
|
||||
|
||||
By default the previous source or replacement string will not be offered
|
||||
for editing. However, this feature can be activated by setting the style
|
||||
tt(edit-previous) in the context tt(:zle:)var(widget) (for example,
|
||||
tt(:zle:replace-string)) to tt(true). In addition, a positive
|
||||
numeric argument forces the previous values to be offered, a negative or
|
||||
zero argument forces them not to be.
|
||||
|
||||
The function tt(replace-string-again) can be used to repeat the
|
||||
previous replacement; no prompting is done. As with tt(replace-string), if
|
||||
the name of the widget contains the word `tt(pattern)', pattern matching
|
||||
is performed, else a literal string replacement. Note that the
|
||||
previous source and replacement text are the same whether pattern or string
|
||||
matching is used.
|
||||
|
||||
For example, starting from the line:
|
||||
|
||||
example(print This line contains fan and fond)
|
||||
|
|
|
|||
23
Functions/Zle/replace-string
Normal file
23
Functions/Zle/replace-string
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
emulate -L zsh
|
||||
setopt extendedglob
|
||||
|
||||
autoload -U read-from-minibuffer replace-string-again
|
||||
|
||||
local p1="Replace: " p2=" with: "
|
||||
# Saving curwidget is necessary to avoid the widget name being overwritten.
|
||||
local REPLY previous curwidget=$WIDGET
|
||||
|
||||
if (( ${+NUMERIC} )); then
|
||||
(( $NUMERIC > 0 )) && previous=1
|
||||
else
|
||||
zstyle -t ":zle:$WIDGET" edit-previous && previous=1
|
||||
fi
|
||||
|
||||
read-from-minibuffer $p1 ${previous:+$_replace_string_src} || return 1
|
||||
_replace_string_src=$REPLY
|
||||
|
||||
read-from-minibuffer "$p1$_replace_string_src$p2" \
|
||||
${previous:+$_replace_string_rep} || return 1
|
||||
_replace_string_rep=$REPLY
|
||||
|
||||
replace-string-again $curwidget
|
||||
Loading…
Add table
Add a link
Reference in a new issue