aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/textadept/editing.lua65
-rw-r--r--modules/textadept/lsnippets.lua124
-rw-r--r--modules/textadept/macros.lua50
-rw-r--r--modules/textadept/mlines.lua4
-rw-r--r--modules/textadept/snippets.lua121
5 files changed, 201 insertions, 163 deletions
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index 04e9a1a1..47166cf5 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -70,9 +70,7 @@ local comment_strings = {
textadept.events.add_handler('char_added',
function(c) -- matches characters specified in char_matches
- if char_matches[c] then
- buffer:insert_text( -1, char_matches[c] )
- end
+ if char_matches[c] then buffer:insert_text(-1, char_matches[c]) end
end)
-- local functions
@@ -106,7 +104,7 @@ end
function autocomplete_word(word_chars)
local buffer = buffer
local caret, length = buffer.current_pos, buffer.length
- local completions, c_list_str = {}, ''
+ local completions, c_list = {}, {}
local buffer_text = buffer:get_text(length)
local root = buffer_text:sub(1, caret):match('['..word_chars..']+$')
if not root or #root == 0 then return end
@@ -115,12 +113,12 @@ function autocomplete_word(word_chars)
local s, e = buffer_text:find('^['..word_chars..']+', match_pos + 1)
local match = buffer_text:sub(s, e)
if not completions[match] and #match > #root then
- c_list_str = c_list_str..match..' '
+ c_list[#c_list + 1] = match
completions[match] = true
end
match_pos = buffer:find(root, 1048580, match_pos + 1)
end
- if #c_list_str > 0 then buffer:auto_c_show( #root, c_list_str:sub(1, -2) ) end
+ if #c_list > 0 then buffer:auto_c_show(#root, table.concat(c_list, ' ')) end
end
---
@@ -134,12 +132,12 @@ function autocomplete_word_from_dict(dict)
if #root == 0 then return end
local f = io.open(dict)
if not f then return end
- local c_list_str = ''
+ local c_list = {}
for line in f:lines() do
- if line:match('^'..root) then c_list_str = c_list_str..line..' ' end
+ if line:match('^'..root) then c_list[#c_list + 1] = line end
end
f:close()
- if #c_list_str > 0 then buffer:auto_c_show( #root, c_list_str:sub(1, -2) ) end
+ if #c_list > 0 then buffer:auto_c_show(#root, table.concat(c_list, ' ')) end
end
---
@@ -205,7 +203,7 @@ textadept.events.add_handler('call_tip_click',
function block_comment(comment)
local buffer = buffer
if not comment then
- comment = comment_strings[ buffer:get_lexer_language() ]
+ comment = comment_strings[buffer:get_lexer_language()]
if not comment then return end
end
local caret, anchor = buffer.current_pos, buffer.anchor
@@ -236,12 +234,13 @@ end
function goto_line(line)
local buffer, locale = buffer, textadept.locale
if not line then
- line = cocoa_dialog( 'standard-inputbox', {
- title = locale.M_TEXTADEPT_EDITING_GOTO_TITLE,
- text = locale.M_TEXTADEPT_EDITING_GOTO_TEXT,
- ['no-newline'] = true
- } )
- line = tonumber( line:match('%-?%d+$') )
+ line =
+ cocoa_dialog('standard-inputbox', {
+ title = locale.M_TEXTADEPT_EDITING_GOTO_TITLE,
+ text = locale.M_TEXTADEPT_EDITING_GOTO_TEXT,
+ ['no-newline'] = true
+ })
+ line = tonumber(line:match('%-?%d+$'))
if not line or line < 0 then return end
end
buffer:ensure_visible_enforce_policy(line - 1)
@@ -328,10 +327,12 @@ function smart_paste(action, reindent)
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)
+ 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)
@@ -367,7 +368,7 @@ function transpose_chars()
else
buffer:char_right()
end
- buffer:insert_text( -1, string.char(char) )
+ buffer:insert_text(-1, string.char(char))
buffer:end_undo_action()
buffer:goto_pos(caret)
end
@@ -384,7 +385,7 @@ function squeeze(char)
while buffer.char_at[s] == char do s = s - 1 end
while buffer.char_at[e] == char do e = e + 1 end
buffer:set_sel(s + 1, e)
- buffer:replace_sel( string.char(char) )
+ buffer:replace_sel(string.char(char))
end
---
@@ -392,7 +393,10 @@ end
function join_lines()
local buffer = buffer
buffer:begin_undo_action()
- buffer:line_end() buffer:clear() buffer:add_text(' ') squeeze()
+ buffer:line_end()
+ buffer:clear()
+ buffer:add_text(' ')
+ squeeze()
buffer:end_undo_action()
end
@@ -471,21 +475,21 @@ function select_enclosed(str)
local buffer = buffer
if str then
buffer:search_anchor()
- local s = buffer:search_prev( 0, enclosure[str].left )
- local e = buffer:search_next( 0, enclosure[str].right )
+ local s = buffer:search_prev(0, enclosure[str].left)
+ local e = buffer:search_next(0, enclosure[str].right)
if s and e then buffer:set_sel(s + 1, e) end
else
-- TODO: ignore enclosures in comment scopes?
s, e = buffer.anchor, buffer.current_pos
if s > e then s, e = e, s end
- local char = string.char( buffer.char_at[s - 1] )
+ local char = string.char(buffer.char_at[s - 1])
if s ~= e and char_matches[char] then
s, e = s - 2, e + 1 -- don't match the same enclosure
end
while s >= 0 do
- char = string.char( buffer.char_at[s] )
+ char = string.char(buffer.char_at[s])
if char_matches[char] then
- local _, e = buffer:find( char_matches[char], 0, e )
+ local _, e = buffer:find(char_matches[char], 0, e)
if e then buffer:set_sel(s + 1, e - 1) break end
end
s = s - 1
@@ -510,7 +514,8 @@ end
-- Selects the current line.
function select_line()
local buffer = buffer
- buffer:home() buffer:line_end_extend()
+ buffer:home()
+ buffer:line_end_extend()
end
---
@@ -657,7 +662,7 @@ get_preceding_number = function()
local caret = buffer.current_pos
local char = buffer.char_at[caret - 1]
local txt = ''
- while tonumber( string.char(char) ) do
+ while tonumber(string.char(char)) do
txt = txt..string.char(char)
caret = caret - 1
char = buffer.char_at[caret - 1]
diff --git a/modules/textadept/lsnippets.lua b/modules/textadept/lsnippets.lua
index ad64c886..47819ae5 100644
--- a/modules/textadept/lsnippets.lua
+++ b/modules/textadept/lsnippets.lua
@@ -108,10 +108,10 @@ function insert(s_text)
local caret = buffer.current_pos
local lexer, style, start, s_name
if not s_text then
- lexer = buffer:get_lexer_language()
- style = buffer:get_style_name( buffer.style_at[caret] )
+ lexer = buffer:get_lexer_language()
+ style = buffer:get_style_name(buffer.style_at[caret])
buffer:word_left_extend()
- start = buffer.current_pos
+ start = buffer.current_pos
s_name = buffer:get_sel_text()
end
if s_name then
@@ -133,13 +133,14 @@ function insert(s_text)
-- Execute Lua and shell code.
s_text = s_text:gsub('%%(%b())', run_lua_code)
- s_text = s_text:gsub('`([^`]+)`',
- function(code)
- local p = io.popen(code)
- local out = p:read('*all'):sub(1, -2)
- p:close()
- return out
- end)
+ s_text =
+ s_text:gsub('`([^`]+)`',
+ function(code)
+ local p = io.popen(code)
+ local out = p:read('*all'):sub(1, -2)
+ p:close()
+ return out
+ end)
-- Initialize the new snippet. If one is running, push it onto the stack.
if snippet.index then snippet_stack[#snippet_stack + 1] = snippet end
@@ -154,7 +155,8 @@ function insert(s_text)
end
-- Insert the snippet and set a mark defining the end of it.
- buffer:replace_sel(s_text) buffer:add_text('\n')
+ buffer:replace_sel(s_text)
+ buffer:add_text('\n')
local line = buffer:line_from_position(buffer.current_pos)
snippet.end_marker = buffer:marker_add(line, MARK_SNIPPET)
buffer:marker_set_back(MARK_SNIPPET, MARK_SNIPPET_COLOR)
@@ -195,23 +197,25 @@ function next()
local ph_text = buffer:text_range(snippet.ph_pos, caret)
-- Transform mirror.
- s_text = s_text:gsub('%%'..index..'(%b())',
- function(mirror)
- local pattern, replacement = mirror:match('^%(([^|]+)|(.+)%)$')
- if not pattern and not replacement then return ph_text end
- return ph_text:gsub( unhandle_escapes(pattern),
- function(...)
- local arg = {...}
- local repl = replacement:gsub('%%(%d)',
- function(i) return arg[ tonumber(i) ] or '' end)
- return repl:gsub('#(%b())', run_lua_code)
- end )
- end)
+ s_text =
+ s_text:gsub('%%'..index..'(%b())',
+ function(mirror)
+ local pattern, replacement = mirror:match('^%(([^|]+)|(.+)%)$')
+ if not pattern and not replacement then return ph_text end
+ return ph_text:gsub(unhandle_escapes(pattern),
+ function(...)
+ local arg = {...}
+ local repl = replacement:gsub('%%(%d)',
+ function(i) return arg[tonumber(i)] or '' end)
+ return repl:gsub('#(%b())', run_lua_code)
+ end)
+ end)
-- Regular mirror.
s_text = s_text:gsub('%%'..index, ph_text)
- buffer:set_sel(s_start, s_end) buffer:replace_sel(s_text)
+ buffer:set_sel(s_start, s_end)
+ buffer:replace_sel(s_text)
s_start, s_end = snippet_info()
buffer:end_undo_action()
end
@@ -223,8 +227,9 @@ function next()
if next_item and not next_item:find('|') then -- placeholder
s, e = buffer:find('%'..index..next_item, 0, s_start)
next_item = next_item:gsub('#(%b())', run_lua_code)
- next_item = unhandle_escapes( next_item:sub(2, -2) )
- buffer:set_sel(s, e) buffer:replace_sel(next_item)
+ next_item = unhandle_escapes(next_item:sub(2, -2))
+ buffer:set_sel(s, e)
+ buffer:replace_sel(next_item)
buffer:set_sel(s, s + #next_item)
else -- use the first mirror as a placeholder
s, e = buffer:find('%'..index..'[^(]', 2097152, s_start) -- regexp
@@ -234,17 +239,25 @@ function next()
if e then e = e + 1 end
end
if not s then snippet.index = index + 1 return next() end
- buffer:set_sel(s, e - 1) buffer:replace_sel('')
+ buffer:set_sel(s, e - 1)
+ buffer:replace_sel('')
end
snippet.ph_pos = s
snippet.index = index
else
- s_text = unescape( unhandle_escapes( s_text:gsub('%%0', '%%__caret') ) )
- buffer:set_sel(s_start, s_end) buffer:replace_sel(s_text)
+ s_text = unescape(unhandle_escapes(s_text:gsub('%%0', '%%__caret')))
+ buffer:set_sel(s_start, s_end)
+ buffer:replace_sel(s_text)
s_start, s_end = snippet_info()
- if s_end then buffer:goto_pos(s_end + 1) buffer:delete_back() end
+ if s_end then
+ buffer:goto_pos(s_end + 1)
+ buffer:delete_back()
+ end
local s, e = buffer:find('%__caret', 4, s_start)
- if s and s <= s_end then buffer:set_sel(s, e) buffer:replace_sel('') end
+ if s and s <= s_end then
+ buffer:set_sel(s, e)
+ buffer:replace_sel('')
+ end
buffer:marker_delete_handle(snippet.end_marker)
snippet = #snippet_stack > 0 and table.remove(snippet_stack) or {}
end
@@ -261,7 +274,8 @@ function prev()
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)
+ buffer:set_sel(s_start, s_end)
+ buffer:replace_sel(s_text)
snippet.index = index - 2
next()
end
@@ -276,9 +290,11 @@ function cancel_current()
local s_start, s_end = snippet_info()
buffer:begin_undo_action()
if s_start and s_end then
- buffer:set_sel(s_start, s_end) buffer:replace_sel('')
+ buffer:set_sel(s_start, s_end)
+ buffer:replace_sel('')
s_start, s_end = snippet_info()
- buffer:goto_pos(s_end + 1) buffer:delete_back()
+ buffer:goto_pos(s_end + 1)
+ buffer:delete_back()
end
if snippet.prev_sel_text then buffer:add_text(snippet.prev_sel_text) end
buffer:end_undo_action()
@@ -291,24 +307,22 @@ end
-- Global snippets and snippets in the current lexer and style are used.
function list()
local buffer = buffer
- local list, list_str = {}, ''
+ local list = {}
local function add_snippets(snippets)
for s_name in pairs(snippets) do list[#list + 1] = s_name end
end
local snippets = _G.snippets
add_snippets(snippets)
local lexer = buffer:get_lexer_language()
- local style = buffer:get_style_name( buffer.style_at[buffer.current_pos] )
- if snippets[lexer] and type( snippets[lexer] ) == 'table' then
- add_snippets( snippets[lexer] )
- if snippets[lexer][style] then add_snippets( snippets[lexer][style] ) end
+ local style = buffer:get_style_name(buffer.style_at[buffer.current_pos])
+ if snippets[lexer] and type(snippets[lexer]) == 'table' then
+ add_snippets(snippets[lexer])
+ if snippets[lexer][style] then add_snippets(snippets[lexer][style]) end
end
table.sort(list)
- local sep = string.char(buffer.auto_c_separator)
- for _, v in ipairs(list) do list_str = list_str..v..sep end
- list_str = list_str:sub(1, -2)
local caret = buffer.current_pos
- buffer:auto_c_show(caret - buffer:word_start_position(caret, true), list_str)
+ buffer:auto_c_show(caret - buffer:word_start_position(caret, true),
+ table.concat(list, string.char(buffer.auto_c_separator)))
end
---
@@ -318,8 +332,9 @@ function show_style()
local lexer = buffer:get_lexer_language()
local style_num = buffer.style_at[buffer.current_pos]
local style = buffer:get_style_name(style_num)
- local text = string.format(
- textadept.locale.M_TEXTADEPT_SNIPPETS_SHOW_STYLE, lexer, style, style_num )
+ local text =
+ string.format(textadept.locale.M_TEXTADEPT_SNIPPETS_SHOW_STYLE, lexer,
+ style, style_num)
buffer:call_tip_show(buffer.current_pos, text)
end
@@ -330,8 +345,9 @@ end
snippet_info = function()
local buffer = buffer
local s = snippet.start_pos
- local e = buffer:position_from_line(
- buffer:marker_line_from_handle(snippet.end_marker) ) - 1
+ local e =
+ buffer:position_from_line(
+ buffer:marker_line_from_handle(snippet.end_marker)) - 1
if e >= s then return s, e, buffer:text_range(s, e) end
end
@@ -339,9 +355,9 @@ end
-- [Local function] Runs the given Lua code.
run_lua_code = function(code)
code = unhandle_escapes(code)
- local env = setmetatable(
- { selected_text = buffer:get_sel_text() }, { __index = _G } )
- local _, val = pcall( setfenv( loadstring('return '..code), env ) )
+ local env =
+ setmetatable({ selected_text = buffer:get_sel_text() }, { __index = _G })
+ local _, val = pcall(setfenv(loadstring('return '..code), env))
return val or ''
end
@@ -351,7 +367,9 @@ end
-- '%%' is the escape character used.
handle_escapes = function(s)
return s:gsub('%%([%%`%)|#])',
- function(char) return ("\\%03d"):format( char:byte() ) end)
+ function(char)
+ return ("\\%03d"):format(char:byte())
+ end)
end
---
@@ -359,7 +377,9 @@ end
-- a given string.
unhandle_escapes = function(s)
return s:gsub('\\(%d%d%d)',
- function(value) return '%'..string.char(value) end)
+ function(value)
+ return '%'..string.char(value)
+ end)
end
---
diff --git a/modules/textadept/macros.lua b/modules/textadept/macros.lua
index 70be5ef4..978a3482 100644
--- a/modules/textadept/macros.lua
+++ b/modules/textadept/macros.lua
@@ -64,11 +64,12 @@ function stop_recording()
buffer:stop_record()
recording = false
local textadept, locale = textadept, textadept.locale
- local ret, macro_name = cocoa_dialog( 'standard-inputbox', {
- ['informative-text'] = locale.M_TEXTADEPT_MACRO_SAVE_TITLE,
- text = locale.M_TEXTADEPT_MACRO_SAVE_TEXT,
- ['no-newline'] = true
- } ):match('^(%d)\n([^\n]+)$')
+ local ret, macro_name =
+ cocoa_dialog('standard-inputbox', {
+ ['informative-text'] = locale.M_TEXTADEPT_MACRO_SAVE_TITLE,
+ text = locale.M_TEXTADEPT_MACRO_SAVE_TEXT,
+ ['no-newline'] = true
+ }):match('^(%d)\n([^\n]+)$')
if ret == '1' and macro_name and #macro_name > 0 then
for _, command in ipairs(current) do
@@ -99,17 +100,18 @@ end
function play(macro_name)
if not macro_name then
local locale = textadept.locale
- local macro_list = ''
- for name in pairs(list) do macro_list = macro_list..'"'..name..'"'..' ' end
- if #macro_list > 0 then
+ local macros = {}
+ for name, _ in pairs(list) do macros[#macros + 1] = name end
+ if #macros > 0 then
local ret
- ret, macro_name = cocoa_dialog( 'standard-dropdown', {
- title = locale.M_TEXTADEPT_MACRO_SELECT_TITLE,
- text = locale.M_TEXTADEPT_MACRO_SELECT_TEXT,
- items = macro_list,
- ['string-output'] = true,
- ['no-newline'] = true
- } ):match('^([^\n]+)\n([^\n]+)$')
+ ret, macro_name =
+ cocoa_dialog('standard-dropdown', {
+ title = locale.M_TEXTADEPT_MACRO_SELECT_TITLE,
+ text = locale.M_TEXTADEPT_MACRO_SELECT_TEXT,
+ items = '"'..table.concat(macros, '" "')..'"',
+ ['string-output'] = true,
+ ['no-newline'] = true
+ }):match('^([^\n]+)\n([^\n]+)$')
if ret == 'Cancel' then return end
end
end
@@ -118,7 +120,7 @@ function play(macro_name)
local buffer, bf = buffer, textadept.buffer_functions
for _, command in ipairs(macro) do
local cmd, wParam, lParam = unpack(command)
- local _, _, p1_type, p2_type = unpack( bf[cmd] )
+ local _, _, p1_type, p2_type = unpack(bf[cmd])
if p2_type == 7 and p1_type == 0 or p1_type == 2 then -- single string param
buffer[cmd](buffer, lParam)
else
@@ -143,16 +145,18 @@ end
-- @param filename The absolute path to the file to save the macros to.
function save(filename)
if not filename then filename = MACRO_FILE end
- local f = assert( io.open(filename, 'w') )
+ local f = assert(io.open(filename, 'w'))
for name, macro in pairs(list) do
f:write(name, '\n')
for _, command in ipairs(macro) do
local msg, wParam, lParam = unpack(command)
if type(lParam) == 'string' then
- lParam = lParam:gsub( '[\t\n\r\f]',
- { ['\t'] = '\\t', ['\n'] = '\\n', ['\r'] = '\\r', ['\f'] = '\\f' } )
+ lParam =
+ lParam:gsub('[\t\n\r\f]',
+ { ['\t'] = '\\t', ['\n'] = '\\n', ['\r'] = '\\r',
+ ['\f'] = '\\f' })
end
- f:write( ("%s\t%s\t%s\n"):format(msg, wParam, lParam) )
+ f:write(("%s\t%s\t%s\n"):format(msg, wParam, lParam))
end
f:write('\n')
end
@@ -178,8 +182,10 @@ function load(filename)
else
local cmd, wParam, lParam = line:match('^([^\t]+)\t([^\t]+)\t(.*)$')
if cmd and wParam and lParam then
- lParam = lParam:gsub( '\\[tnrf]',
- { ['\\t'] = '\t', ['\\n'] = '\n', ['\\r'] = '\r', ['\\f'] = '\f' } )
+ lParam =
+ lParam:gsub('\\[tnrf]',
+ { ['\\t'] = '\t', ['\\n'] = '\n', ['\\r'] = '\r',
+ ['\\f'] = '\f' })
local num = wParam:match('^-?%d+$')
if num then wParam = tonumber(num) end
num = lParam:match('^-?%d+$')
diff --git a/modules/textadept/mlines.lua b/modules/textadept/mlines.lua
index c0963b8d..ce1997ce 100644
--- a/modules/textadept/mlines.lua
+++ b/modules/textadept/mlines.lua
@@ -105,10 +105,10 @@ end
function update()
local buffer = buffer
local curr_line = buffer:line_from_position(buffer.current_pos)
- local curr_col = buffer.column[buffer.current_pos]
+ local curr_col = buffer.column[buffer.current_pos]
buffer:begin_undo_action()
if mlines[curr_line] then
- local s = buffer:find_column( curr_line, mlines[curr_line].start_col )
+ local s = buffer:find_column(curr_line, mlines[curr_line].start_col)
local e = buffer:find_column(curr_line, curr_col)
local delta = e - s
local txt = ''
diff --git a/modules/textadept/snippets.lua b/modules/textadept/snippets.lua
index 01e42986..ec8cd11a 100644
--- a/modules/textadept/snippets.lua
+++ b/modules/textadept/snippets.lua
@@ -59,11 +59,11 @@ function insert(snippet_arg)
local sel_text = buffer:get_sel_text()
if not snippet_arg then
orig_pos = buffer.current_pos buffer:word_left_extend()
- new_pos = buffer.current_pos
- lexer = buffer:get_lexer_language()
- style = buffer.style_at[orig_pos]
- scope = buffer:get_style_name(style)
- s_name = buffer:get_sel_text()
+ new_pos = buffer.current_pos
+ lexer = buffer:get_lexer_language()
+ style = buffer.style_at[orig_pos]
+ scope = buffer:get_style_name(style)
+ s_name = buffer:get_sel_text()
else
if buffer.current_pos > buffer.anchor then
buffer.current_pos, buffer.anchor = buffer.anchor, buffer.current_pos
@@ -96,10 +96,10 @@ function insert(snippet_arg)
_DEBUG('s_text escaped:\n'..s_text)
-- Replace Lua code return.
- local env = setmetatable( { selected_text = sel_text }, { __index = _G } )
+ local env = setmetatable({ selected_text = sel_text }, { __index = _G })
s_text = s_text:gsub('$(%b())',
function(s)
- local f = loadstring( 'return '..s:sub(2, -2) )
+ local f = loadstring('return '..s:sub(2, -2))
setfenv(f, env)
local ret, val = pcall(f)
if ret then return val or '' end
@@ -120,17 +120,17 @@ function insert(snippet_arg)
if snippet.index then snippet_stack[#snippet_stack + 1] = snippet end
snippet = {}
- snippet.index = 0
+ snippet.index = 0
snippet.start_pos = buffer.current_pos
- snippet.cursor = nil
- snippet.sel_text = sel_text
+ snippet.cursor = nil
+ snippet.sel_text = sel_text
-- Make a table of placeholders and tab stops.
local patt, patt2 = '($%b{})', '^%${(%d+):.*}$'
local s, _, item = s_text:find(patt)
while item do
local num = item:match(patt2)
- if num then snippet[ tonumber(num) ] = unescape(item) end
+ if num then snippet[tonumber(num)] = unescape(item) end
local i = s + 1
s, _, item = s_text:find(patt, i)
end
@@ -154,7 +154,7 @@ function insert(snippet_arg)
count = count + 1
i = s_text:find('\n', i + 1)
until i == nil
- match_indention( buffer:line_from_position(orig_pos), count )
+ match_indention(buffer:line_from_position(orig_pos), count)
else
buffer:goto_pos(orig_pos)
end
@@ -192,35 +192,36 @@ next_snippet_item = function()
-- Regex mirror.
patt = '%${'..snippet.index..'/(.-)/(.-)/([iomxneus]*)}'
- s_text = s_text:gsub(patt,
- function(pattern, replacement, options)
- local script = [[
- li = %q(last_item)
- rep = %q(replacement)
- li =~ /pattern/options
- if data = $~
- rep.gsub!(/\#\{(.+?)\}/) do
- expr = $1.gsub(/\$(\d\d?)/, 'data[\1]')
- eval expr
+ s_text =
+ s_text:gsub(patt,
+ function(pattern, replacement, options)
+ local script = [[
+ li = %q(last_item)
+ rep = %q(replacement)
+ li =~ /pattern/options
+ if data = $~
+ rep.gsub!(/\#\{(.+?)\}/) do
+ expr = $1.gsub(/\$(\d\d?)/, 'data[\1]')
+ eval expr
+ end
+ puts rep.gsub(/\$(\d\d?)/) { data[$1.to_i] }
end
- puts rep.gsub(/\$(\d\d?)/) { data[$1.to_i] }
- end
- ]]
- pattern = unescape(pattern)
- replacement = unescape(replacement)
- script = script:gsub('last_item', last_item)
- script = script:gsub('pattern', pattern)
- script = script:gsub('options', options)
- script = script:gsub('replacement', replacement)
- _DEBUG('script:\n'..script)
-
- local p = io.popen("ruby 2>&1 <<'_EOF'\n"..script..'\n_EOF')
- local out = p:read('*all')
- p:close()
- _DEBUG('regex out:\n'..out)
- if out:sub(-1) == '\n' then out = out:sub(1, -2) end -- chomp
- return out
- end)
+ ]]
+ pattern = unescape(pattern)
+ replacement = unescape(replacement)
+ script = script:gsub('last_item', last_item)
+ script = script:gsub('pattern', pattern)
+ script = script:gsub('options', options)
+ script = script:gsub('replacement', replacement)
+ _DEBUG('script:\n'..script)
+
+ local p = io.popen("ruby 2>&1 <<'_EOF'\n"..script..'\n_EOF')
+ local out = p:read('*all')
+ p:close()
+ _DEBUG('regex out:\n'..out)
+ if out:sub(-1) == '\n' then out = out:sub(1, -2) end -- chomp
+ return out
+ end)
_DEBUG('patterns replaced:\n'..s_text)
-- Plain text mirror.
@@ -305,7 +306,8 @@ function cancel_current()
local s_start, s_end = snippet_text()
if s_start and s_end then
buffer:set_sel(s_start, s_end)
- buffer:replace_sel('') join_lines()
+ buffer:replace_sel('')
+ join_lines()
end
if snippet.sel_text then
buffer:add_text(snippet.sel_text)
@@ -323,7 +325,7 @@ end
-- Global snippets and snippets in the current lexer and scope are used.
function list()
local buffer = buffer
- local list, list_str = {}, ''
+ local list = {}
local function add_snippets(snippets)
for s_name in pairs(snippets) do table.insert(list, s_name) end
@@ -335,17 +337,15 @@ function list()
local lexer = buffer:get_lexer_language()
local style = buffer.style_at[buffer.current_pos]
local scope = buffer:get_style_name(style)
- if snippets[lexer] and type( snippets[lexer] ) == 'table' then
- add_snippets( snippets[lexer] )
- if snippets[lexer][scope] then add_snippets( snippets[lexer][scope] ) end
+ if snippets[lexer] and type(snippets[lexer]) == 'table' then
+ add_snippets(snippets[lexer])
+ if snippets[lexer][scope] then add_snippets(snippets[lexer][scope]) end
end
end
-
table.sort(list)
- local sep = string.char(buffer.auto_c_separator)
- for _, v in pairs(list) do list_str = list_str..v..sep end
- list_str = list_str:sub(1, -2) -- chop
- buffer:auto_c_show(0, list_str)
+
+ buffer:auto_c_show(0,
+ table.concat(list, string.char(buffer.auto_c_separator)))
end
---
@@ -355,8 +355,9 @@ function show_scope()
local buffer = buffer
local lexer = buffer:get_lexer_language()
local scope = buffer.style_at[buffer.current_pos]
- local text = string.format(
- textadept.locale.M_TEXTADEPT_SNIPPETS_SHOW_STYLE, lexer, style, style_num )
+ local text =
+ string.format(textadept.locale.M_TEXTADEPT_SNIPPETS_SHOW_STYLE, lexer,
+ style, style_num)
buffer:call_tip_show(buffer.current_pos, text)
end
@@ -367,8 +368,9 @@ end
snippet_text = function()
local buffer = buffer
local s = snippet.start_pos
- local e = buffer:position_from_line(
- buffer:marker_line_from_handle(snippet.end_marker) ) - 1
+ local e =
+ buffer:position_from_line(
+ buffer:marker_line_from_handle(snippet.end_marker) ) - 1
if e >= s then return s, e, buffer:text_range(s, e) end
end
@@ -377,7 +379,9 @@ end
-- equivalents.
escape = function(text)
return text:gsub('\\([$/}`])',
- function(char) return ("\\%03d"):format( char:byte() ) end)
+ function(char)
+ return ("\\%03d"):format(char:byte())
+ end)
end
---
@@ -385,7 +389,9 @@ end
-- equivalents.
unescape = function(text)
return text:gsub('\\(%d%d%d)',
- function(value) return '\\'..string.char(value) end)
+ function(value)
+ return '\\'..string.char(value)
+ end)
end
---
@@ -416,7 +422,8 @@ end
-- This is used to remove the empty line containing the end of snippet marker.
join_lines = function()
local buffer = buffer
- buffer:line_down() buffer:vc_home()
+ buffer:line_down()
+ buffer:vc_home()
if buffer.column[buffer.current_pos] == 0 then buffer:vc_home() end
buffer:home_extend()
if #buffer:get_sel_text() > 0 then buffer:delete_back() end