From a985bd4d2b4e1fcfad8f9a8eca4123a104669d80 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Tue, 23 Dec 2008 12:14:06 -0500 Subject: Added option for smart_paste() to reindent text; modules/textadept/editing.lua --- modules/textadept/editing.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'modules') 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 -- cgit v1.2.3