aboutsummaryrefslogtreecommitdiff
path: root/modules/textadept
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2007-09-20 16:11:35 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2007-09-20 16:11:35 -0400
commitaab557ed9d32478863eaed94adc622a58a7d7f7d (patch)
tree66b16b95e2681422179df59f7ee73a5496a20c75 /modules/textadept
parentda893c1dd57b19879ec40df066b6b074dd3a5afc (diff)
downloadtextadept-aab557ed9d32478863eaed94adc622a58a7d7f7d.tar.gz
textadept-aab557ed9d32478863eaed94adc622a58a7d7f7d.zip
Snippet "snapshots" enable backtracking; /modules/textadept/lsnippets.lua
Diffstat (limited to 'modules/textadept')
-rw-r--r--modules/textadept/lsnippets.lua18
1 files changed, 18 insertions, 0 deletions
diff --git a/modules/textadept/lsnippets.lua b/modules/textadept/lsnippets.lua
index 0e1ad0a7..7a8a4e13 100644
--- a/modules/textadept/lsnippets.lua
+++ b/modules/textadept/lsnippets.lua
@@ -139,6 +139,7 @@ function insert(s_text)
-- Initialize the new snippet. If one is running, push it onto the stack.
if snippet.index then snippet_stack[#snippet_stack + 1] = snippet end
snippet = {}
+ snippet.snapshots = {}
snippet.start_pos = start or caret
snippet.prev_sel_text = buffer:get_sel_text()
snippet.index, snippet.max_index = 0, 0
@@ -182,6 +183,7 @@ function next()
if not s_text then cancel_current() return end
local index = snippet.index
+ snippet.snapshots[index] = s_text
if index > 0 then
buffer:begin_undo_action()
local caret = math.max(buffer.anchor, buffer.current_pos)
@@ -240,6 +242,22 @@ function next()
end
---
+-- Goes back to the previous placeholder or tab stop, reverting changes made to
+-- subsequent ones.
+function prev()
+ if not snippet.index then return end
+ local buffer = buffer
+ local index = snippet.index
+ if index > 1 then
+ local s_start, s_end = snippet_info()
+ local s_text = snippet.snapshots[index - 2]
+ buffer:set_sel(s_start, s_end) buffer:replace_sel(s_text)
+ snippet.index = index - 2
+ next()
+ end
+end
+
+---
-- Cancels the active snippet, reverting to the state before its activation,
-- and restores the previous running snippet (if any).
function cancel_current()