aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2008-12-23 12:14:06 -0500
committermitchell <70453897+667e-11@users.noreply.github.com>2008-12-23 12:14:06 -0500
commita985bd4d2b4e1fcfad8f9a8eca4123a104669d80 (patch)
treeed9c3565f01d7d01acc76a154a1dc7aec250787c
parenta981e9f30da8ebf9d2c082196631e5daca8cf6a7 (diff)
downloadtextadept-a985bd4d2b4e1fcfad8f9a8eca4123a104669d80.tar.gz
textadept-a985bd4d2b4e1fcfad8f9a8eca4123a104669d80.zip
Added option for smart_paste() to reindent text; modules/textadept/editing.lua
-rw-r--r--modules/textadept/editing.lua10
1 files changed, 9 insertions, 1 deletions
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index a9947b73..ab113f1e 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -306,8 +306,9 @@ end
-- @param action If given, specifies whether to cycle through the kill-ring in
-- normal or reverse order. A value of 'cycle' cycles through normally,
-- 'reverse' in reverse.
+-- @param reindent Flag indicating whether or not to reindent the pasted text.
-- @see scroll_kill_ring
-function smart_paste(action)
+function smart_paste(action, reindent)
local buffer = buffer
local anchor, caret = buffer.anchor, buffer.current_pos
if caret < anchor then anchor = caret end
@@ -326,6 +327,13 @@ function smart_paste(action)
txt = kill_ring[kill_ring.pos]
if txt then
+ if reindent then
+ local indent = buffer.line_indentation[
+ buffer:line_from_position(buffer.current_pos) ]
+ local padding = string.rep(buffer.use_tabs and '\t' or ' ',
+ buffer.use_tabs and indent / buffer.tab_width or indent)
+ txt = txt:gsub('\n', '\n'..padding)
+ end
buffer:replace_sel(txt)
if action then buffer.anchor = anchor end -- cycle
end