1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-29 17:31:02 +01:00

27604: substitution using regular expressions

This commit is contained in:
Peter Stephenson 2010-01-18 12:47:09 +00:00
parent 8890e6e19f
commit c508c6e368
4 changed files with 78 additions and 11 deletions

View file

@ -13,7 +13,7 @@ if [[ -z $_replace_string_src ]]; then
return 1
fi
if [[ $curwidget = *pattern* ]]; then
if [[ $curwidget = *(pattern|regex)* ]]; then
local rep2
# The following horror is so that an & preceded by an even
# number of backslashes is active, without stripping backslashes,
@ -38,8 +38,14 @@ if [[ $curwidget = *pattern* ]]; then
rep=${match[5]}
done
rep2+=$rep
LBUFFER=${LBUFFER//(#bm)$~_replace_string_src/${(e)rep2}}
RBUFFER=${RBUFFER//(#bm)$~_replace_string_src/${(e)rep2}}
if [[ $curwidget = *regex* ]]; then
autoload -U regexp-replace
regexp-replace LBUFFER $_replace_string_src $rep2
regexp-replace RBUFFER $_replace_string_src $rep2
else
LBUFFER=${LBUFFER//(#bm)$~_replace_string_src/${(e)rep2}}
RBUFFER=${RBUFFER//(#bm)$~_replace_string_src/${(e)rep2}}
fi
else
LBUFFER=${LBUFFER//$_replace_string_src/$_replace_string_rep}
RBUFFER=${RBUFFER//$_replace_string_src/$_replace_string_rep}