diff options
author | 2013-11-10 15:28:34 -0500 | |
---|---|---|
committer | 2013-11-10 15:28:34 -0500 | |
commit | 38ea16b279aa4f5b355a01040415f67ed2888d8c (patch) | |
tree | 115ea2bd0384fdfcafc2368ccfa13593c697a599 | |
parent | 016a8056f01221faa5ccee3581e488bd98650401 (diff) | |
download | textadept-38ea16b279aa4f5b355a01040415f67ed2888d8c.tar.gz textadept-38ea16b279aa4f5b355a01040415f67ed2888d8c.zip |
Store the full Lua pattern match in "%0" for use in replacement text.
-rw-r--r-- | doc/06_AdeptEditing.md | 2 | ||||
-rw-r--r-- | modules/textadept/find.lua | 3 |
2 files changed, 3 insertions, 2 deletions
diff --git a/doc/06_AdeptEditing.md b/doc/06_AdeptEditing.md index 9356f0e6..d4857e2f 100644 --- a/doc/06_AdeptEditing.md +++ b/doc/06_AdeptEditing.md @@ -150,7 +150,7 @@ renders the entire line eligible for moving. Replace pane. In addition to offering the usual find and replace with "Match Case" and "Whole Word" options and find/replace history, Textadept supports finding with [Lua patterns][] and replacing with Lua captures and even Lua code! -For example: replacing all `(%w+)` with `%(string.upper('%1'))` upper cases all +For example: replacing all `%w+` with `%(string.upper('%0'))` upper cases all words in the buffer. Replacement text only recognizes Lua captures (`%`_`n`_) from a Lua pattern search, but always allows embedded Lua code enclosed in `%()`. diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index ed8950f0..76897309 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -144,6 +144,7 @@ local function find_(text, next, flags, no_wrap, wrapped) M.captures = {table.unpack(caps, next and 3 or 4)} if #caps > 0 and caps[2] >= caps[1] then pos, e = s + caps[next and 1 or 3] - 1, s + caps[2] + M.captures[0] = buffer:text_range(pos, e) buffer:set_sel(e, pos) end end @@ -259,7 +260,7 @@ local function replace(rtext) buffer:target_from_selection() rtext = rtext:gsub('%%%%', '\\037') -- escape '%%' if M.captures then - for i = 1, #M.captures do + for i = 0, #M.captures do rtext = rtext:gsub('%%'..i, (M.captures[i]:gsub('%%', '%%%%'))) end end |