From 3aa3f9f30142ea40dc20cb0aba462fdc5ac0da64 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Thu, 14 Oct 2010 21:09:46 -0400 Subject: Code formatting changes. --- modules/textadept/editing.lua | 9 +++--- modules/textadept/find.lua | 21 ++++++------ modules/textadept/menu.lua | 35 ++++++++++---------- modules/textadept/mime_types.lua | 17 +++++----- modules/textadept/session.lua | 15 ++++----- modules/textadept/snapopen.lua | 21 ++++++------ modules/textadept/snippets.lua | 69 +++++++++++++++++++--------------------- 7 files changed, 89 insertions(+), 98 deletions(-) (limited to 'modules') diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index 7a8080bb..b9f00382 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -228,11 +228,10 @@ end function goto_line(line) local buffer = buffer if not line then - line = - gui.dialog('standard-inputbox', - '--title', locale.M_TEXTADEPT_EDITING_GOTO_TITLE, - '--text', locale.M_TEXTADEPT_EDITING_GOTO_TEXT, - '--no-newline') + line = gui.dialog('standard-inputbox', + '--title', locale.M_TEXTADEPT_EDITING_GOTO_TITLE, + '--text', locale.M_TEXTADEPT_EDITING_GOTO_TEXT, + '--no-newline') line = tonumber(line:match('%-?%d+$')) if not line or line < 0 then return end end diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index a1f873fe..80f24a4e 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -74,13 +74,12 @@ local function find_(text, next, flags, nowrap, wrapped) end else -- find in files - local utf8_dir = - gui.dialog('fileselect', - '--title', locale.FIND_IN_FILES_TITLE, - '--select-only-directories', - '--with-directory', - (buffer.filename or ''):match('^.+[/\\]') or '', - '--no-newline') + local utf8_dir = gui.dialog('fileselect', + '--title', locale.FIND_IN_FILES_TITLE, + '--select-only-directories', + '--with-directory', + (buffer.filename or ''):match('^.+[/\\]') or '', + '--no-newline') if #utf8_dir > 0 then if not find.lua then text = text:gsub('([().*+?^$%%[%]-])', '%%%1') end if not find.match_case then text = text:lower() end @@ -264,8 +263,8 @@ local function replace_all(ftext, rtext, flags) local s, e = anchor, current_pos if s > e then s, e = e, s end buffer:insert_text(e, '\n') - local end_marker = - buffer:marker_add(buffer:line_from_position(e + 1), MARK_FIND) + local end_marker = buffer:marker_add(buffer:line_from_position(e + 1), + MARK_FIND) buffer:goto_pos(s) local pos = find_(ftext, true, flags, true) while pos ~= -1 and @@ -282,8 +281,8 @@ local function replace_all(ftext, rtext, flags) buffer:set_sel(anchor, current_pos) buffer:marker_delete_handle(end_marker) end - gui.statusbar_text = - string.format(locale.FIND_REPLACEMENTS_MADE, tostring(count)) + gui.statusbar_text = string.format(locale.FIND_REPLACEMENTS_MADE, + tostring(count)) buffer:end_undo_action() end events.connect('replace_all', replace_all) diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index af71519d..589c3205 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -345,14 +345,14 @@ local actions = { [ID.CLOSE_ALL] = { io.close_all }, [ID.LOAD_SESSION] = { function() - local utf8_filename = - gui.dialog('fileselect', - '--title', l.MENU_LOAD_SESSION_TITLE, - '--with-directory', - (_SESSIONFILE or ''):match('.+[/\\]') or '', - '--with-file', - (_SESSIONFILE or ''):match('[^/\\]+$') or '', - '--no-newline') + local session_file = _SESSIONFILE or '' + local utf8_filename = gui.dialog('fileselect', + '--title', l.MENU_LOAD_SESSION_TITLE, + '--with-directory', + session_file:match('.+[/\\]') or '', + '--with-file', + session_file:match('[^/\\]+$') or '', + '--no-newline') if #utf8_filename > 0 then _m.textadept.session.load(utf8_filename:iconv(_CHARSET, 'UTF-8')) end @@ -360,14 +360,14 @@ local actions = { }, [ID.SAVE_SESSION] = { function() - local utf8_filename = - gui.dialog('filesave', - '--title', l.MENU_SAVE_SESSION_TITLE, - '--with-directory', - (_SESSIONFILE or ''):match('.+[/\\]') or '', - '--with-file', - (_SESSIONFILE or ''):match('[^/\\]+$') or '', - '--no-newline') + local session_file = _SESSIONFILE or '' + local utf8_filename = gui.dialog('filesave', + '--title', l.MENU_SAVE_SESSION_TITLE, + '--with-directory', + session_file:match('.+[/\\]') or '', + '--with-file', + session_file:match('[^/\\]+$') or '', + '--no-newline') if #utf8_filename > 0 then _m.textadept.session.save(utf8_filename:iconv(_CHARSET, 'UTF-8')) end @@ -499,8 +499,7 @@ events.connect('menu_clicked', function(menu_id) local active_table = actions[menu_id] if menu_id >= ID.LEXER_START and menu_id < ID.LEXER_START + 99 then - active_table = - { set_lexer, lexer_menu[menu_id - ID.LEXER_START + 1][1] } + active_table = { set_lexer, lexer_menu[menu_id - ID.LEXER_START + 1][1] } end local f, args if active_table and #active_table > 0 then diff --git a/modules/textadept/mime_types.lua b/modules/textadept/mime_types.lua index 5d19228c..4908708f 100644 --- a/modules/textadept/mime_types.lua +++ b/modules/textadept/mime_types.lua @@ -282,15 +282,14 @@ events.connect('reset_after', -- Prompts the user to select a lexer from a filtered list for the current -- buffer. function select_lexer() - local out = - gui.dialog('filteredlist', - '--title', locale.MT_SELECT_LEXER, - '--button1', 'gtk-ok', - '--button2', 'gtk-cancel', - '--no-newline', - '--string-output', - '--columns', 'Name', - '--items', lexers) + local out = gui.dialog('filteredlist', + '--title', locale.MT_SELECT_LEXER, + '--button1', 'gtk-ok', + '--button2', 'gtk-cancel', + '--no-newline', + '--string-output', + '--columns', 'Name', + '--items', lexers) local response, lexer = out:match('([^\n]+)\n([^\n]+)$') if response and response ~= 'gtk-cancel' then buffer:set_lexer(lexer) end end diff --git a/modules/textadept/session.lua b/modules/textadept/session.lua index 057ea449..59e3009a 100644 --- a/modules/textadept/session.lua +++ b/modules/textadept/session.lua @@ -91,7 +91,7 @@ function load(filename) '--title', locale.M_SESSION_FILES_NOT_FOUND_TITLE, '--text', locale.M_SESSION_FILES_NOT_FOUND_TEXT, '--informative-text', - string.format('%s', table.concat(not_found, '\n'))) + string.format('%s', table.concat(not_found, '\n'))) end return true end @@ -117,11 +117,11 @@ function save(filename) local current = buffer.doc_pointer == gui.focused_doc_pointer local anchor = current and 'anchor' or '_anchor' local current_pos = current and 'current_pos' or '_current_pos' - local first_visible_line = - current and 'first_visible_line' or '_first_visible_line' - session[#session + 1] = - buffer_line:format(buffer[anchor] or 0, buffer[current_pos] or 0, - buffer[first_visible_line] or 0, filename) + local top_line = current and 'first_visible_line' or '_first_visible_line' + session[#session + 1] = buffer_line:format(buffer[anchor] or 0, + buffer[current_pos] or 0, + buffer[top_line] or 0, + filename) end end -- Write out split views. @@ -161,8 +161,7 @@ function save(filename) local size = gui.size session[#session + 1] = ("size: %d %d"):format(size[1], size[2]) -- Write the session. - local f = - io.open(filename or _SESSIONFILE or DEFAULT_SESSION, 'wb') + local f = io.open(filename or _SESSIONFILE or DEFAULT_SESSION, 'wb') if f then f:write(table.concat(session, '\n')) f:close() diff --git a/modules/textadept/snapopen.lua b/modules/textadept/snapopen.lua index da4581d3..62320835 100644 --- a/modules/textadept/snapopen.lua +++ b/modules/textadept/snapopen.lua @@ -15,13 +15,13 @@ module('_m.textadept.snapopen', package.seeall) -- -- ## Examples -- --- local snapopen = _m.textadept.snapopen +-- local snapopen = _m.textadept.snapopen.open -- -- -- Show all files in PATHS. -- snapopen() -- -- -- Show all files in the current file's directory. --- snapopen(buffer.filename:match('^.+[/\\]'), nil, true) +-- snapopen(buffer.filename:match('^(.+)[/\\]'), nil, true) -- -- -- Show all Lua files in PATHS. -- snapopen(nil, '!%.lua$') @@ -110,16 +110,15 @@ function open(paths, filter, exclusive, depth) gui.dialog('ok-msgbox', '--title', locale.M_SNAPOPEN_LIMIT_EXCEEDED_TITLE, '--informative-text', - string.format(locale.M_SNAPOPEN_LIMIT_EXCEEDED_TEXT, MAX, MAX)) + string.format(locale.M_SNAPOPEN_LIMIT_EXCEEDED_TEXT, MAX, MAX)) end - local out = - gui.dialog('filteredlist', - '--title', locale.IO_OPEN_TITLE, - '--button1', 'gtk-ok', - '--button2', 'gtk-cancel', - '--no-newline', - '--columns', 'File', - '--items', list) + local out = gui.dialog('filteredlist', + '--title', locale.IO_OPEN_TITLE, + '--button1', 'gtk-ok', + '--button2', 'gtk-cancel', + '--no-newline', + '--columns', 'File', + '--items', list) local response, index = out:match('^(%d+)[\r\n]+(%d+)') if response == '1' then io.open_file(list[tonumber(index) + 1]) end end diff --git a/modules/textadept/snippets.lua b/modules/textadept/snippets.lua index e8af7ac1..0c1b5e8b 100644 --- a/modules/textadept/snippets.lua +++ b/modules/textadept/snippets.lua @@ -163,9 +163,8 @@ local function unescape(s) return s:gsub('%%([%%`%)|#])', '%1') end local function snippet_info() 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 @@ -174,8 +173,8 @@ end -- @return string result from the code run. local function run_lua_code(code) code = unhandle_escapes(code) - local env = - setmetatable({ selected_text = buffer:get_sel_text() }, { __index = _G }) + local env = setmetatable({ selected_text = buffer:get_sel_text() }, + { __index = _G }) local _, val = pcall(setfenv(loadstring('return '..code), env)) return val or '' end @@ -201,29 +200,29 @@ local function next_tab_stop() 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, 1) - end) + local function transform_mirror(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, 1) + end + s_text = s_text:gsub('%%'..index..'(%b())', transform_mirror) -- Regular mirror. s_text = s_text:gsub('()%%'..index, - function(pos) - for mirror, e in s_text:gmatch('%%%d+(%b())()') do - local s = mirror:find('|') - if s and pos > s and pos < e then return nil end -- inside transform - end - return ph_text - end) + function(pos) + for mirror, e in s_text:gmatch('%%%d+(%b())()') do + local s = mirror:find('|') + -- If inside transform, do not do anything. + if s and pos > s and pos < e then return nil end + end + return ph_text + end) buffer:set_sel(s_start, s_end) buffer:replace_sel(s_text) @@ -344,14 +343,13 @@ 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 @@ -464,9 +462,8 @@ function _show_style() local lexer = buffer:get_lexer() local style_num = buffer.style_at[buffer.current_pos] local style = buffer:get_style_name(style_num) - local text = - string.format(locale.M_TEXTADEPT_SNIPPETS_SHOW_STYLE, lexer, style, - style_num) + local text = string.format(locale.M_TEXTADEPT_SNIPPETS_SHOW_STYLE, lexer, + style, style_num) buffer:call_tip_show(buffer.current_pos, text) end -- cgit v1.2.3