diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/events.lua | 41 | ||||
-rw-r--r-- | core/ext/find.lua | 20 | ||||
-rw-r--r-- | core/ext/key_commands.lua | 41 | ||||
-rw-r--r-- | core/ext/key_commands_mac.lua | 41 | ||||
-rw-r--r-- | core/ext/key_commands_std.lua | 43 | ||||
-rw-r--r-- | core/ext/keys.lua | 21 | ||||
-rw-r--r-- | core/ext/menu.lua | 9 | ||||
-rw-r--r-- | core/ext/mime_types.lua | 2 | ||||
-rw-r--r-- | core/ext/pm.lua | 8 | ||||
-rw-r--r-- | core/ext/pm/buffer_browser.lua | 13 | ||||
-rw-r--r-- | core/ext/pm/ctags_browser.lua | 12 | ||||
-rw-r--r-- | core/ext/pm/file_browser.lua | 15 | ||||
-rw-r--r-- | core/ext/pm/find_browser.lua | 3 | ||||
-rw-r--r-- | core/ext/pm/macro_browser.lua | 4 | ||||
-rw-r--r-- | core/ext/pm/modules_browser.lua | 28 | ||||
-rw-r--r-- | core/ext/pm/project_browser.lua | 142 | ||||
-rw-r--r-- | core/file_io.lua | 67 | ||||
-rw-r--r-- | core/init.lua | 4 | ||||
-rw-r--r-- | core/locale.lua | 4 |
19 files changed, 292 insertions, 226 deletions
diff --git a/core/events.lua b/core/events.lua index f8c94cc4..afb119e0 100644 --- a/core/events.lua +++ b/core/events.lua @@ -97,7 +97,7 @@ function handle(event, ...) local handlers = events[plural] if not handlers then return end for _, f in ipairs(handlers) do - local result = f( unpack{...} ) + local result = f(unpack{...}) if result == true or result == false then return result end end end @@ -138,12 +138,12 @@ function keypress(code, shift, control, alt) end function menu_clicked(menu_item) local text, menu_id = menu_item:match('^(.+)|(%d+)$') - return handle( 'menu_clicked', text, tonumber(menu_id) ) + return handle('menu_clicked', text, tonumber(menu_id)) end -- Scintilla notifications. function char_added(n) - if n.ch < 256 then return handle( 'char_added', string.char(n.ch) ) end + if n.ch < 256 then return handle('char_added', string.char(n.ch)) end end function save_point_reached() return handle('save_point_reached') @@ -251,8 +251,8 @@ add_handler('view_new', buffer:set_sel_fore(1, 3355443) -- 0x33 | 0x33 << 8 | 0x33 << 16 buffer:set_sel_back(1, 10066329) -- 0x99 | 0x99 << 8 | 0x99 << 16 - buffer.margin_width_n[0] = 4 + 3 * -- line number margin - buffer:text_width(c.STYLE_LINENUMBER, '9') + buffer.margin_width_n[0] = -- line number margin + 4 + 3 * buffer:text_width(c.STYLE_LINENUMBER, '9') buffer.margin_width_n[1] = 0 -- marker margin invisible @@ -363,6 +363,8 @@ add_handler('char_added', end end) +local title_text = '%s %s Textadept (%s)' + --- -- [Local function] Sets the title of the Textadept window to the buffer's -- filename. @@ -370,8 +372,9 @@ add_handler('char_added', local function set_title(buffer) local buffer, textadept = buffer, textadept local filename = buffer.filename or textadept.locale.UNTITLED - local d = buffer.dirty and ' * ' or ' - ' - textadept.title = filename:match('[^/\\]+$')..d..'Textadept ('..filename..')' + local d = buffer.dirty and '*' or '-' + textadept.title = + string.format(title_text, filename:match('[^/\\]+$'), d, filename) end add_handler('save_point_reached', @@ -401,8 +404,10 @@ add_handler('save_point_left', -- @class table -- @name _error_details local _error_details = { - lua = { pattern = '^lua: ([^:]+):(%d+): (.+)$', - filename = 1, line = 2, message = 3 } + lua = { + pattern = '^lua: ([^:]+):(%d+): (.+)$', + filename = 1, line = 2, message = 3 + } } add_handler('double_click', @@ -412,8 +417,8 @@ add_handler('double_click', for _, error_detail in pairs(_error_details) do local captures = { line:match(error_detail.pattern) } if #captures > 0 then - textadept.io.open( captures[error_detail.filename] ) - _m.textadept.editing.goto_line( captures[error_detail.line] ) + textadept.io.open(captures[error_detail.filename]) + _m.textadept.editing.goto_line(captures[error_detail.line]) local msg = captures[error_detail.message] if msg then buffer:call_tip_show(buffer.current_pos, msg) end break @@ -450,8 +455,8 @@ local _braces = { -- () [] {} <> -- @param current_pos The position to match braces at. local function match_brace(current_pos) local buffer = buffer - if _braces[ buffer.char_at[current_pos] ] and - buffer:get_style_name( buffer.style_at[current_pos] ) == 'operator' then + if _braces[buffer.char_at[current_pos]] and + buffer:get_style_name(buffer.style_at[current_pos]) == 'operator' then local pos = buffer:brace_match(current_pos) if pos ~= -1 then buffer:brace_highlight(current_pos, pos) @@ -530,13 +535,13 @@ add_handler('quit', end end if any then - if cocoa_dialog( 'yesno-msgbox', { + if cocoa_dialog('yesno-msgbox', { title = locale.EVENTS_QUIT_TITLE, text = locale.EVENTS_QUIT_TEXT, ['informative-text'] = - string.format( locale.EVENTS_QUIT_MSG, table.concat(list, '\n') ), + string.format(locale.EVENTS_QUIT_MSG, table.concat(list, '\n')), ['no-newline'] = true - } ) ~= '2' then return false end + }) ~= '2' then return false end end textadept.io.save_session() return true @@ -554,7 +559,7 @@ end function error(...) local function handle_error(...) local textadept = textadept - local error_message = table.concat( {...} , '\n' ) + local error_message = table.concat({...} , '\n') local error_buffer for index, buffer in ipairs(textadept.buffers) do if buffer.shows_errors then @@ -572,7 +577,7 @@ function error(...) error_buffer:append_text(error_message..'\n') error_buffer:set_save_point() end - pcall( handle_error, unpack{...} ) -- prevent endless loops if this errors + pcall(handle_error, unpack{...}) -- prevent endless loops if this errors end textadept.print = error diff --git a/core/ext/find.lua b/core/ext/find.lua index 94371689..5def64e8 100644 --- a/core/ext/find.lua +++ b/core/ext/find.lua @@ -42,7 +42,7 @@ function find.find(text, next, flags, nowrap, wrapped) if find.lua then flags = flags + 8 end end if flags < 8 then - buffer:goto_pos( buffer[next and 'current_pos' or 'anchor'] + increment ) + buffer:goto_pos(buffer[next and 'current_pos' or 'anchor'] + increment) buffer:search_anchor() if next then result = buffer:search_next(flags, text) @@ -101,23 +101,23 @@ function find.replace(rtext) rtext = rtext:gsub('%%'..i, v) end end - local ret, rtext = pcall( rtext.gsub, rtext, '%%(%b())', + local ret, rtext = pcall(rtext.gsub, rtext, '%%(%b())', function(code) local locale = textadept.locale - local ret, val = pcall( loadstring('return '..code) ) + local ret, val = pcall(loadstring('return '..code)) if not ret then - cocoa_dialog( 'msgbox', { + cocoa_dialog('msgbox', { title = locale.FIND_ERROR_DIALOG_TITLE, text = locale.FIND_ERROR_DIALOG_TEXT, ['informative-text'] = val:gsub('"', '\\"') - } ) + }) error() end return val - end ) + end) if ret then rtext = rtext:gsub('\\037', '%%') -- unescape '%' - buffer:replace_target( rtext:gsub('\\[abfnrtv\\]', escapes) ) + buffer:replace_target(rtext:gsub('\\[abfnrtv\\]', escapes)) buffer:goto_pos(buffer.target_end + 1) -- 'find' text after this replacement else -- Since find is called after replace returns, have it 'find' the current @@ -138,10 +138,10 @@ function find.replace_all(ftext, rtext, flags) local textadept = textadept buffer:goto_pos(0) local count = 0 - while( find.find(ftext, true, flags, true) ) do + while(find.find(ftext, true, flags, true)) do find.replace(rtext) count = count + 1 end - textadept.statusbar_text = tostring(count)..' '.. - textadept.locale.FIND_REPLACEMENTS_MADE + textadept.statusbar_text = + string.format(textadept.locale.FIND_REPLACEMENTS_MADE, tostring(count)) end diff --git a/core/ext/key_commands.lua b/core/ext/key_commands.lua index 8985a1fa..6e3f0145 100644 --- a/core/ext/key_commands.lua +++ b/core/ext/key_commands.lua @@ -45,18 +45,22 @@ keys.cs = { t.find.focus } -- find/replace -- Recent files. local RECENT_FILES = 1 t.events.add_handler('user_list_selection', - function(type, text) if type == RECENT_FILES then t.io.open(text) end end) -keys.ar = { function() - local buffer = buffer - local list = '' - local sep = buffer.auto_c_separator - buffer.auto_c_separator = ('|'):byte() - for _, filename in ipairs(t.io.recent_files) do - list = filename..'|'..list + function(type, text) + if type == RECENT_FILES then t.io.open(text) end + end) +keys.ar = { + function() + local buffer = buffer + local files = {} + for _, filename in ipairs(t.io.recent_files) do + table.insert(files, 1, filename) + end + local sep = buffer.auto_c_separator + buffer.auto_c_separator = ('|'):byte() + buffer:user_list_show(RECENT_FILES, table.concat(files, '|')) + buffer.auto_c_separator = sep end - buffer:user_list_show( RECENT_FILES, list:sub(1, -2) ) - buffer.auto_c_separator = sep -end } +} -- Buffer/view commands. keys.an = { 'goto_buffer', v, 1, false } @@ -185,7 +189,10 @@ keys.cam = { m_macro.toggle_record } keys.csam = { m_macro.play } -- Project manager commands. -local function pm_activate(text) t.pm.entry_text = text t.pm.activate() end +local function pm_activate(text) + t.pm.entry_text = text + t.pm.activate() +end keys['c\t'] = { t.pm.focus } keys.ct.b = { pm_activate, 'buffers' } keys.ct.c = { pm_activate, 'ctags' } @@ -213,8 +220,10 @@ keys.cc = { t.command_entry.focus } local m_events = t.events keys.cab = { m_events.handle, 'call_tip_click', 1 } keys.caf = { m_events.handle, 'call_tip_click', 2 } -keys.ct.f = { function() - local buffer = buffer - buffer:toggle_fold( buffer:line_from_position(buffer.current_pos) ) -end } +keys.ct.f = { + function() + local buffer = buffer + buffer:toggle_fold(buffer:line_from_position(buffer.current_pos)) + end +} keys.f5 = { 'colourise', b, 0, -1 } diff --git a/core/ext/key_commands_mac.lua b/core/ext/key_commands_mac.lua index d4e0ed31..11378804 100644 --- a/core/ext/key_commands_mac.lua +++ b/core/ext/key_commands_mac.lua @@ -153,12 +153,17 @@ keys.cv = { } -- Project Manager -local function pm_activate(text) t.pm.entry_text = text t.pm.activate() end +local function pm_activate(text) + t.pm.entry_text = text + t.pm.activate() +end keys.sap = { function() if t.pm.width > 0 then t.pm.toggle_visible() end end } -keys.ap = { function() - if t.pm.width == 0 then t.pm.toggle_visible() end - t.pm.focus() -end } +keys.ap = { + function() + if t.pm.width == 0 then t.pm.toggle_visible() end + t.pm.focus() + end +} keys.cap = { c = { pm_activate, 'ctags' }, b = { pm_activate, 'buffers' }, @@ -171,18 +176,22 @@ keys.cap = { -- Recent files. local RECENT_FILES = 1 t.events.add_handler('user_list_selection', - function(type, text) if type == RECENT_FILES then t.io.open(text) end end) -keys.co = { function() - local buffer = buffer - local list = '' - local sep = buffer.auto_c_separator - buffer.auto_c_separator = ('|'):byte() - for _, filename in ipairs(t.io.recent_files) do - list = filename..'|'..list + function(type, text) + if type == RECENT_FILES then t.io.open(text) end + end) +keys.co = { + function() + local buffer = buffer + local files = {} + for _, filename in ipairs(t.io.recent_files) do + table.insert(files, 1, filename) + end + local sep = buffer.auto_c_separator + buffer.auto_c_separator = ('|'):byte() + buffer:user_list_show(RECENT_FILES, table.concat(files, '|')) + buffer.auto_c_separator = sep end - buffer:user_list_show( RECENT_FILES, list:sub(1, -2) ) - buffer.auto_c_separator = sep -end } +} -- Movement/selection commands keys.cf = { 'char_right', b } diff --git a/core/ext/key_commands_std.lua b/core/ext/key_commands_std.lua index 0e52ac98..499305f6 100644 --- a/core/ext/key_commands_std.lua +++ b/core/ext/key_commands_std.lua @@ -27,7 +27,7 @@ keys.clear_sequence = 'esc' local b, v = 'buffer', 'view' local t = textadept -keys.ct = {} -- Textadept command chain +keys.ct = {} -- Textadept command chain -- File keys.cn = { t.new_buffer } @@ -153,12 +153,17 @@ keys.cav = { } -- Project Manager -local function pm_activate(text) t.pm.entry_text = text t.pm.activate() end +local function pm_activate(text) + t.pm.entry_text = text + t.pm.activate() +end keys.csp = { function() if t.pm.width > 0 then t.pm.toggle_visible() end end } -keys.cp = { function() - if t.pm.width == 0 then t.pm.toggle_visible() end - t.pm.focus() -end } +keys.cp = { + function() + if t.pm.width == 0 then t.pm.toggle_visible() end + t.pm.focus() + end +} keys.cap = { c = { pm_activate, 'ctags' }, b = { pm_activate, 'buffers' }, @@ -171,15 +176,19 @@ keys.cap = { -- Recent files. local RECENT_FILES = 1 t.events.add_handler('user_list_selection', - function(type, text) if type == RECENT_FILES then t.io.open(text) end end) -keys.ao = { function() - local buffer = buffer - local list = '' - local sep = buffer.auto_c_separator - buffer.auto_c_separator = ('|'):byte() - for _, filename in ipairs(t.io.recent_files) do - list = filename..'|'..list + function(type, text) + if type == RECENT_FILES then t.io.open(text) end + end) +keys.ao = { + function() + local buffer = buffer + local files = {} + for _, filename in ipairs(t.io.recent_files) do + table.insert(files, 1, filename) + end + local sep = buffer.auto_c_separator + buffer.auto_c_separator = ('|'):byte() + buffer:user_list_show(RECENT_FILES, table.concat(files, '|')) + buffer.auto_c_separator = sep end - buffer:user_list_show( RECENT_FILES, list:sub(1, -2) ) - buffer.auto_c_separator = sep -end } +} diff --git a/core/ext/keys.lua b/core/ext/keys.lua index b9c17ab3..818479a9 100644 --- a/core/ext/keys.lua +++ b/core/ext/keys.lua @@ -111,7 +111,10 @@ local try_get_cmd1, try_get_cmd2, try_get_cmd3, try_get_cmd --- -- Clears the current key sequence. -function clear_key_sequence() keychain = {} textadept.statusbar_text = '' end +function clear_key_sequence() + keychain = {} + textadept.statusbar_text = '' +end --- -- [Local function] Handles Textadept keypresses. @@ -170,10 +173,12 @@ local function keypress(code, shift, control, alt) if ret then clear_key_sequence() if type(func) == 'function' then - local ret, retval = pcall( func, unpack(args) ) + local ret, retval = pcall(func, unpack(args)) if ret then if type(retval) == 'boolean' then return retval end - else textadept.events.error(retval) end -- error + else + textadept.events.error(retval) + end end return true else @@ -186,7 +191,9 @@ local function keypress(code, shift, control, alt) textadept.statusbar_text = textadept.locale.KEYS_INVALID return true end - else return true end + else + return true + end end end textadept.events.add_handler('keypress', keypress, 1) @@ -195,13 +202,13 @@ textadept.events.add_handler('keypress', keypress, 1) -- [Local function] Tries to get a key command based on the lexer and current -- scope. try_get_cmd1 = function(keys, lexer, scope) - return try_get_cmd( keys[lexer][scope] ) + return try_get_cmd(keys[lexer][scope]) end --- -- [Local function] Tries to get a key command based on the lexer. try_get_cmd2 = function(keys, lexer) - return try_get_cmd( keys[lexer] ) + return try_get_cmd(keys[lexer]) end --- @@ -234,7 +241,7 @@ try_get_cmd = function(active_table) return view[func], { view, unpack(active_table, 3) } end else - error( locale.KEYS_UNKNOWN_COMMAND..tostring(func) ) + error(locale.KEYS_UNKNOWN_COMMAND..tostring(func)) end end end diff --git a/core/ext/menu.lua b/core/ext/menu.lua index 44a70e2d..e7f57d5a 100644 --- a/core/ext/menu.lua +++ b/core/ext/menu.lua @@ -415,7 +415,10 @@ local m_mlines = _m.textadept.mlines local m_bookmarks = _m.textadept.bookmarks local m_macros = _m.textadept.macros -local function pm_activate(text) t.pm.entry_text = text t.pm.activate() end +local function pm_activate(text) + t.pm.entry_text = text + t.pm.activate() +end local function toggle_setting(setting) local state = buffer[setting] if type(state) == 'boolean' then @@ -579,10 +582,10 @@ t.events.add_handler('menu_clicked', end end if f and args then - local ret, retval = pcall( f, unpack(args) ) + local ret, retval = pcall(f, unpack(args)) if not ret then textadept.events.error(retval) end -- error else - error( l.MENU_UNKNOWN_COMMAND..tostring(func) ) + error(l.MENU_UNKNOWN_COMMAND..tostring(func)) end end end) diff --git a/core/ext/mime_types.lua b/core/ext/mime_types.lua index 2ad0a3ed..6d4ec37a 100644 --- a/core/ext/mime_types.lua +++ b/core/ext/mime_types.lua @@ -276,7 +276,7 @@ local function set_lexer_from_sh_bang() line = line:gsub('[\\/]', ' ') for word in line:gmatch('%S+') do if shebangs[word] then - buffer:set_lexer_language( shebangs[word] ) + buffer:set_lexer_language(shebangs[word]) return true end end diff --git a/core/ext/pm.lua b/core/ext/pm.lua index fa5d21d0..8122c419 100644 --- a/core/ext/pm.lua +++ b/core/ext/pm.lua @@ -66,7 +66,7 @@ local pm = textadept.pm -- are expanded, this function is called again to get that level of data. function pm.get_contents_for(full_path, expanding) for _, browser in pairs(pm.browsers) do - if browser.matches( full_path[1] ) then + if browser.matches(full_path[1]) then return browser.get_contents_for(full_path, expanding) end end @@ -79,7 +79,7 @@ end -- @see pm.get_contents_for function pm.perform_action(selected_item) for _, browser in pairs(pm.browsers) do - if browser.matches( selected_item[1] ) then + if browser.matches(selected_item[1]) then return browser.perform_action(selected_item) end end @@ -98,7 +98,7 @@ end -- @see pm.get_contents_for function pm.get_context_menu(selected_item) for _, browser in pairs(pm.browsers) do - if browser.matches( selected_item[1] ) then + if browser.matches(selected_item[1]) then return browser.get_context_menu(selected_item) end end @@ -113,7 +113,7 @@ end -- @see pm.get_contents_for function pm.perform_menu_action(menu_item, menu_id, selected_item) for _, browser in pairs(pm.browsers) do - if browser.matches( selected_item[1] ) then + if browser.matches(selected_item[1]) then return browser.perform_menu_action(menu_item, menu_id, selected_item) end end diff --git a/core/ext/pm/buffer_browser.lua b/core/ext/pm/buffer_browser.lua index f4822226..73b09d55 100644 --- a/core/ext/pm/buffer_browser.lua +++ b/core/ext/pm/buffer_browser.lua @@ -23,8 +23,11 @@ end function perform_action(selected_item) local index = selected_item[2] - local buffer = textadept.buffers[ tonumber(index) ] - if buffer then view:goto_buffer(index) view:focus() end + local buffer = textadept.buffers[tonumber(index)] + if buffer then + view:goto_buffer(index) + view:focus() + end end local ID = { NEW = 1, OPEN = 2, SAVE = 3, SAVEAS = 4, CLOSE = 5 } @@ -47,13 +50,13 @@ function perform_menu_action(menu_item, menu_id, selected_item) elseif menu_id == ID.OPEN then textadept.io.open() elseif menu_id == ID.SAVE then - view:goto_buffer( tonumber( selected_item[2] ) ) + view:goto_buffer(tonumber(selected_item[2])) buffer:save() elseif menu_id == ID.SAVEAS then - view:goto_buffer( tonumber( selected_item[2] ) ) + view:goto_buffer(tonumber(selected_item[2])) buffer:save_as() elseif menu_id == ID.CLOSE then - view:goto_buffer( tonumber( selected_item[2] ) ) + view:goto_buffer(tonumber(selected_item[2])) buffer:close() end textadept.pm.activate() diff --git a/core/ext/pm/ctags_browser.lua b/core/ext/pm/ctags_browser.lua index 196eba5c..e1b4586d 100644 --- a/core/ext/pm/ctags_browser.lua +++ b/core/ext/pm/ctags_browser.lua @@ -112,7 +112,7 @@ function get_contents_for(full_path, expanding) tags = {} current_file = nil current_dir = '' -- ctags file will specify absolute paths - os.execute( 'ctags -f '..FILE_OUT..' '..(buffer.filename or '') ) + os.execute('ctags -f '..FILE_OUT..' '..(buffer.filename or '')) f = io.open(FILE_OUT) if not f then return {} end elseif not expanding then @@ -182,16 +182,16 @@ function get_contents_for(full_path, expanding) end entry.text = name -- The following keys are ignored by caller. - entry.filepath = filepath:sub(1, 1) == '/' and - filepath or current_dir..filepath + entry.filepath = + filepath:sub(1, 1) == '/' and filepath or current_dir..filepath entry.pattern = pattern entry.line_num = line_num if not entry.set then tags[name] = entry end else - print( string.format(locale.PM_BROWSER_CTAGS_BAD_EXT, file_ext) ) + print(string.format(locale.PM_BROWSER_CTAGS_BAD_EXT, file_ext)) end else - print( string.format(locale.PM_BROWSER_CTAGS_UNMATCHED, line) ) + print(string.format(locale.PM_BROWSER_CTAGS_UNMATCHED, line)) end end end @@ -217,7 +217,7 @@ function perform_action(selected_item) buffer:goto_line(line) else error( - string.format(textadept.locale.PM_BROWSER_CTAGS_NOT_FOUND, item.text) ) + string.format(textadept.locale.PM_BROWSER_CTAGS_NOT_FOUND, item.text)) end elseif item.line_num then textadept.io.open(item.filepath) diff --git a/core/ext/pm/file_browser.lua b/core/ext/pm/file_browser.lua index 17ae3be1..c658b6c0 100644 --- a/core/ext/pm/file_browser.lua +++ b/core/ext/pm/file_browser.lua @@ -58,17 +58,18 @@ function perform_menu_action(menu_item, menu_id, selected_item) elseif menu_id == ID.FILE_INFO then local date_format = '%D %T' local attr = lfs.attributes(filepath) - local out = string.format( locale.PM_BROWSER_FILE_DATA, - attr.mode, attr.size, attr.uid, attr.gid, attr.dev, - os.date(date_format, attr.access), - os.date(date_format, attr.modification), - os.date(date_format, attr.change) ) - cocoa_dialog( 'textbox', { + local out = + string.format(locale.PM_BROWSER_FILE_DATA, + attr.mode, attr.size, attr.uid, attr.gid, attr.dev, + os.date(date_format, attr.access), + os.date(date_format, attr.modification), + os.date(date_format, attr.change)) + cocoa_dialog('textbox', { ['informative-text'] = string.format(locale.PM_BROWSER_FILE_INFO_TEXT, filepath), text = out, button1 = locale.PM_BROWSER_FILE_INFO_OK, editable = false - } ) + }) end end diff --git a/core/ext/pm/find_browser.lua b/core/ext/pm/find_browser.lua index f722664e..a8722e78 100644 --- a/core/ext/pm/find_browser.lua +++ b/core/ext/pm/find_browser.lua @@ -59,7 +59,8 @@ function get_contents_for(full_path, expanding) p = io.popen('grep -'..opts..' "'..search_string..'" "'.. search_directory..'"') for line in p:lines() do - local filename, line_num, line_text = line:match('^([^:]+):(%d+):%s-(.+)$') + local filename, line_num, line_text = + line:match('^([^:]+):(%d+):%s-(.+)$') if filename and line_num and line_text then if not find_matches[filename] then find_matches[filename] = { diff --git a/core/ext/pm/macro_browser.lua b/core/ext/pm/macro_browser.lua index e1394e5c..c2892fa7 100644 --- a/core/ext/pm/macro_browser.lua +++ b/core/ext/pm/macro_browser.lua @@ -19,7 +19,7 @@ function get_contents_for() end function perform_action(selected_item) - _m.textadept.macros.play( selected_item[2] ) + _m.textadept.macros.play(selected_item[2]) view:focus() end @@ -33,7 +33,7 @@ end function perform_menu_action(menu_item, menu_id, selected_item) local m_macros = _m.textadept.macros if menu_id == ID.DELETE then - m_macros.delete( selected_item[2] ) + m_macros.delete(selected_item[2]) end textadept.pm.activate() end diff --git a/core/ext/pm/modules_browser.lua b/core/ext/pm/modules_browser.lua index 95a5bd9f..4fc97206 100644 --- a/core/ext/pm/modules_browser.lua +++ b/core/ext/pm/modules_browser.lua @@ -123,15 +123,17 @@ end function perform_menu_action(menu_item, menu_id, selected_item) local locale = textadept.locale if menu_id == ID.NEW then - local status, module_name = cocoa_dialog( 'standard-inputbox', { - ['title'] = locale.PM_BROWSER_MODULE_NEW_TITLE, - ['informative-text'] = locale.PM_BROWSER_MODULE_NEW_INFO_TEXT - } ):match('^(%d)%s+([^\n]+)%s+$') + local status, module_name = + cocoa_dialog('standard-inputbox', { + ['title'] = locale.PM_BROWSER_MODULE_NEW_TITLE, + ['informative-text'] = locale.PM_BROWSER_MODULE_NEW_INFO_TEXT + }):match('^(%d)%s+([^\n]+)%s+$') if status ~= '1' then return end - local status, lang_name = cocoa_dialog( 'standard-inputbox', { - ['title'] = locale.PM_BROWSER_MODULE_NEW_LANG_TITLE, - ['informative-text'] = locale.PM_BROWSER_MODULE_NEW_LANG_INFO_TEXT - } ):match('^(%d)%s+([^\n]+)%s+$') + local status, lang_name = + cocoa_dialog('standard-inputbox', { + ['title'] = locale.PM_BROWSER_MODULE_NEW_LANG_TITLE, + ['informative-text'] = locale.PM_BROWSER_MODULE_NEW_LANG_INFO_TEXT + }):match('^(%d)%s+([^\n]+)%s+$') if status ~= '1' then return end local module_dir = _HOME..'/modules/'..module_name if lfs.mkdir(module_dir) then @@ -151,22 +153,22 @@ function perform_menu_action(menu_item, menu_id, selected_item) f:write(out) f:close() else - cocoa_dialog( 'ok-msgbox', { + cocoa_dialog('ok-msgbox', { ['text'] = locale.PM_BROWSER_MODULE_NEW_ERROR, ['informative-text'] = locale.PM_BROWSER_MODULE_NEW_ERROR_TEXT, ['no-cancel'] = true - } ) + }) return end elseif menu_id == ID.DELETE then local module_name = selected_item[2] - if cocoa_dialog( 'yesno-msgbox', { + if cocoa_dialog('yesno-msgbox', { ['text'] = locale.PM_BROWSER_MODULE_DELETE_TITLE, ['informative-text'] = - string.format( locale.PM_BROWSER_MODULE_DELETE_TEXT, module_name ), + string.format(locale.PM_BROWSER_MODULE_DELETE_TEXT, module_name), ['no-cancel'] = true, ['no-newline'] = true - } ) == '1' then + }) == '1' then local function remove_directory(dirpath) for name in lfs.dir(dirpath) do if not name:match('^%.%.?$') then os.remove(dirpath..'/'..name) end diff --git a/core/ext/pm/project_browser.lua b/core/ext/pm/project_browser.lua index 2dab8deb..30c6a847 100644 --- a/core/ext/pm/project_browser.lua +++ b/core/ext/pm/project_browser.lua @@ -69,7 +69,7 @@ end --- Opens the selected project file. function perform_action(selected_item) - textadept.io.open( selected_item[#selected_item] ) + textadept.io.open(selected_item[#selected_item]) view:focus() end @@ -101,11 +101,12 @@ function perform_menu_action(menu_item, menu_id, selected_item) if menu_id == ID.NEW then -- Close all open files and prompt the user to save a project file. if textadept.io.close_all() then - local file = cocoa_dialog( 'filesave', { - title = locale.PM_BROWSER_PROJECT_NEW_TITLE, - ['with-directory'] = (buffer.filename or ''):match('.+[/\\]'), - ['no-newline'] = true - } ) + local file = + cocoa_dialog('filesave', { + title = locale.PM_BROWSER_PROJECT_NEW_TITLE, + ['with-directory'] = (buffer.filename or ''):match('.+[/\\]'), + ['no-newline'] = true + }) if #file > 0 then project_file = file project_root = {} @@ -116,11 +117,12 @@ function perform_menu_action(menu_item, menu_id, selected_item) elseif menu_id == ID.OPEN then -- Close all open files and prompt the user for a project file to open. if textadept.io.close_all() then - local file = cocoa_dialog( 'fileselect', { - title = locale.PM_BROWSER_PROJECT_OPEN_TITLE, - ['with-directory'] = (buffer.filename or ''):match('.+[/\\]'), - ['no-newline'] = true - } ) + local file = + cocoa_dialog('fileselect', { + title = locale.PM_BROWSER_PROJECT_OPEN_TITLE, + ['with-directory'] = (buffer.filename or ''):match('.+[/\\]'), + ['no-newline'] = true + }) if #file > 0 then load_project(file) refresh_view() @@ -139,11 +141,12 @@ function perform_menu_action(menu_item, menu_id, selected_item) -- If a project is open, prompts the user to save the new file. if project_file then local dir = get_live_parent_folder(selected_item) - local file = cocoa_dialog( 'filesave', { - title = locale.PM_BROWSER_PROJECT_NEW_FILE_TITLE, - ['with-directory'] = dir or project_file:match('.+[/\\]'), - ['no-newline'] = true - } ) + local file = + cocoa_dialog('filesave', { + title = locale.PM_BROWSER_PROJECT_NEW_FILE_TITLE, + ['with-directory'] = dir or project_file:match('.+[/\\]'), + ['no-newline'] = true + }) if #file > 0 then local function add_file_to(pfolder) local exists = false @@ -162,17 +165,20 @@ function perform_menu_action(menu_item, menu_id, selected_item) -- caution them about unexpected behavior and ask to save in the -- project root instead. if dir and file:match('^(.+)[/\\]') ~= dir then - local ret = cocoa_dialog( 'yesno-msgbox', { - text = locale.PM_BROWSER_PROJECT_NEW_FILE_LIVE_FOLDER_TITLE, - ['informative-text'] = - locale.PM_BROWSER_PROJECT_NEW_FILE_LIVE_FOLDER_TEXT, - ['no-newline'] = true - } ) + local ret = + cocoa_dialog('yesno-msgbox', { + text = locale.PM_BROWSER_PROJECT_NEW_FILE_LIVE_FOLDER_TITLE, + ['informative-text'] = + locale.PM_BROWSER_PROJECT_NEW_FILE_LIVE_FOLDER_TEXT, + ['no-newline'] = true + }) if ret == '1' then add_file_to(project_root) end if ret == '3' then return end end end - local f = io.open(file, 'w') f:write('') f:close() + local f = io.open(file, 'w') + f:write('') + f:close() update_project() refresh_view() end @@ -186,14 +192,15 @@ function perform_menu_action(menu_item, menu_id, selected_item) -- Files are added if they do not already exist in the project. This does -- not always apply when live folders are in a project. if project_file then - local files = cocoa_dialog( 'fileselect', { - title = locale.PM_BROWSER_PROJECT_ADD_FILES_TITLE, - text = locale.PM_BROWSER_PROJECT_ADD_FILES_TEXT, - -- in Windows, dialog:get_filenames() is unavailable; only allow single - -- selection - ['select-multiple'] = not WIN32 or nil, - ['with-directory'] = (buffer.filename or project_file):match('.+[/\\]') - } ) + local files = + cocoa_dialog('fileselect', { + title = locale.PM_BROWSER_PROJECT_ADD_FILES_TITLE, + text = locale.PM_BROWSER_PROJECT_ADD_FILES_TEXT, + -- in Windows, dialog:get_filenames() is unavailable; only allow single + -- selection + ['select-multiple'] = not WIN32 or nil, + ['with-directory'] = (buffer.filename or project_file):match('.+[/\\]') + }) if #files > 0 then local function add_files_to(pfolder) for file in files:gmatch('[^\n]+') do @@ -210,12 +217,12 @@ function perform_menu_action(menu_item, menu_id, selected_item) if not project_folder.is_live_folder then add_files_to(project_folder) else - if cocoa_dialog( 'yesno-msgbox', { + if cocoa_dialog('yesno-msgbox', { text = locale.PM_BROWSER_PROJECT_ADD_FILES_LIVE_FOLDER_TITLE, ['informative-text'] = locale.PM_BROWSER_PROJECT_ADD_FILES_LIVE_FOLDER_TEXT, ['no-newline'] = true, - } ) == '1' then add_files_to(project_root) end + }) == '1' then add_files_to(project_root) end end end end @@ -227,16 +234,17 @@ function perform_menu_action(menu_item, menu_id, selected_item) -- The directory is added if it does not already exist in the project. This -- does not always apply when live folders are in a project. if project_file then - local ret, name = cocoa_dialog( 'standard-inputbox', { - ['informative-text'] = locale.PM_BROWSER_PROJECT_NEW_DIR_TITLE, - ['no-newline'] = true - } ):match('^(%d)\n([^\n]+)$') + local ret, name = + cocoa_dialog('standard-inputbox', { + ['informative-text'] = locale.PM_BROWSER_PROJECT_NEW_DIR_TITLE, + ['no-newline'] = true + }):match('^(%d)\n([^\n]+)$') if ret == '1' and name and #name > 0 then local project_folder = get_parent_folder(selected_item) if not project_folder.is_live_folder then if not project_folder[name] then project_folder[name] = {} end else - lfs.mkdir( get_live_parent_folder(selected_item)..'/'..name ) + lfs.mkdir(get_live_parent_folder(selected_item)..'/'..name) end update_project() refresh_view() @@ -251,13 +259,14 @@ function perform_menu_action(menu_item, menu_id, selected_item) -- The directory is added if it does not already exist in the project. This -- does not always apply when live folders are in a project. if project_file then - local dir = cocoa_dialog( 'fileselect', { - title = locale.PM_BROWSER_PROJECT_ADD_DIR_TITLE, - text = locale.PM_BROWSER_PROJECT_ADD_DIR_TEXT, - ['select-only-directories'] = true, - ['with-directory'] = (buffer.filename or ''):match('.+[/\\]'), - ['no-newline'] = true - } ) + local dir = + cocoa_dialog('fileselect', { + title = locale.PM_BROWSER_PROJECT_ADD_DIR_TITLE, + text = locale.PM_BROWSER_PROJECT_ADD_DIR_TEXT, + ['select-only-directories'] = true, + ['with-directory'] = (buffer.filename or ''):match('.+[/\\]'), + ['no-newline'] = true + }) if #dir > 0 then local function add_directory_to(pfolder) if not pfolder[dir] then @@ -270,12 +279,12 @@ function perform_menu_action(menu_item, menu_id, selected_item) if not project_folder.is_live_folder then add_directory_to(project_folder) else - if cocoa_dialog( 'yesno-msgbox', { + if cocoa_dialog('yesno-msgbox', { text = locale.PM_BROWSER_PROJECT_ADD_DIR_LIVE_FOLDER_TITLE, ['informative-text'] = locale.PM_BROWSER_PROJECT_ADD_DIR_LIVE_FOLDER_TEXT, ['no-newline'] = true, - } ) == '1' then add_directory_to(project_root) end + }) == '1' then add_directory_to(project_root) end end end end @@ -294,12 +303,13 @@ function perform_menu_action(menu_item, menu_id, selected_item) else -- file for i, file in ipairs(project_folder) do if file == item then - local ret = cocoa_dialog( 'yesno-msgbox', { - text = locale.PM_BROWSER_PROJECT_DELETE_FILE_TITLE, - ['informative-text'] = - locale.PM_BROWSER_PROJECT_DELETE_FILE_TEXT, - ['no-newline'] = true - } ) + local ret = + cocoa_dialog('yesno-msgbox', { + text = locale.PM_BROWSER_PROJECT_DELETE_FILE_TITLE, + ['informative-text'] = + locale.PM_BROWSER_PROJECT_DELETE_FILE_TEXT, + ['no-newline'] = true + }) if ret == '2' then os.remove(file) end if ret == '3' then return end table.remove(project_folder, i) @@ -321,16 +331,17 @@ function perform_menu_action(menu_item, menu_id, selected_item) table.remove(selected_item, #selected_item) local parent_folder = get_parent_folder(selected_item) if item_is_dir and not parent_folder.is_live_folder then - local ret = cocoa_dialog( 'yesno-msgbox', { - text = locale.PM_BROWSER_PROJECT_DELETE_DIR_TITLE, - ['informative-text'] = locale.PM_BROWSER_PROJECT_DELETE_DIR_TEXT, - ['no-newline'] = true - } ) + local ret = + cocoa_dialog('yesno-msgbox', { + text = locale.PM_BROWSER_PROJECT_DELETE_DIR_TITLE, + ['informative-text'] = locale.PM_BROWSER_PROJECT_DELETE_DIR_TEXT, + ['no-newline'] = true + }) if ret == '2' then remove_directory(item) end if ret == '3' then return end parent_folder[item] = nil else - if cocoa_dialog( 'msgbox', { + if cocoa_dialog('msgbox', { text = locale.PM_BROWSER_PROJECT_DELETE_LIVE_FILE_TITLE, ['informative-text'] = locale.PM_BROWSER_PROJECT_DELETE_LIVE_FILE_TEXT, @@ -338,7 +349,7 @@ function perform_menu_action(menu_item, menu_id, selected_item) button1 = locale.PM_BROWSER_PROJECT_DELETE_LIVE_FILE_BUTTON1, button2 = locale.PM_BROWSER_PROJECT_DELETE_LIVE_FILE_BUTTON2, button3 = locale.PM_BROWSER_PROJECT_DELETE_LIVE_FILE_BUTTON3 - } ) ~= '2' then return end + }) ~= '2' then return end if item_is_dir then remove_directory(item) else os.remove(item) end end end @@ -349,10 +360,11 @@ function perform_menu_action(menu_item, menu_id, selected_item) elseif menu_id == ID.RENAME_FILE then -- If a project is open, prompts the user for a new file/directory name. if project_file then - local ret, name = cocoa_dialog( 'standard-inputbox', { - ['informative-text'] = locale.PM_BROWSER_PROJECT_RENAME_FILE_TEXT, - ['no-newline'] = true - } ):match('^(%d)\n([^\n]+)$') + local ret, name = + cocoa_dialog('standard-inputbox', { + ['informative-text'] = locale.PM_BROWSER_PROJECT_RENAME_FILE_TEXT, + ['no-newline'] = true + }):match('^(%d)\n([^\n]+)$') if ret == '1' and name and #name > 0 then local oldname = selected_item[#selected_item] local newname = oldname:match('^.+[/\\]')..name @@ -457,7 +469,7 @@ get_live_parent_folder = function(selected_item) local dir = nil if get_parent_folder(selected_item).is_live_folder then if lfs.attributes( - selected_item[#selected_item], 'mode' ) == 'directory' then + selected_item[#selected_item], 'mode') == 'directory' then dir = selected_item[#selected_item] else dir = selected_item[#selected_item - 1] diff --git a/core/file_io.lua b/core/file_io.lua index 44fbe444..943bc6f0 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -28,7 +28,7 @@ local function open_helper(filename) local buffer = textadept.new_buffer() local f, err = io.open(filename) if f then - buffer:set_text( f:read('*all') ) + buffer:set_text(f:read('*all')) buffer:empty_undo_buffer() f:close() end @@ -45,14 +45,15 @@ end -- @usage textadept.io.open(filename) function open(filenames) local locale = textadept.locale - filenames = filenames or cocoa_dialog( 'fileselect', { - title = locale.IO_OPEN_TITLE, - text = locale.IO_OPEN_TEXT, - -- in Windows, dialog:get_filenames() is unavailable; only allow single - -- selection - ['select-multiple'] = not WIN32 or nil, - ['with-directory'] = (buffer.filename or ''):match('.+[/\\]') - } ) + filenames = + filenames or cocoa_dialog('fileselect', { + title = locale.IO_OPEN_TITLE, + text = locale.IO_OPEN_TEXT, + -- in Windows, dialog:get_filenames() is unavailable; only allow single + -- selection + ['select-multiple'] = not WIN32 or nil, + ['with-directory'] = (buffer.filename or ''):match('.+[/\\]') + }) for filename in filenames:gmatch('[^\n]+') do open_helper(filename) end end @@ -67,7 +68,7 @@ function reload(buffer) local f, err = io.open(buffer.filename) if f then local pos = buffer.current_pos - buffer:set_text( f:read('*all') ) + buffer:set_text(f:read('*all')) buffer.current_pos = pos buffer:set_save_point() f:close() @@ -103,12 +104,13 @@ end function save_as(buffer, filename) textadept.check_focused_buffer(buffer) if not filename then - filename = cocoa_dialog( 'filesave', { - title = textadept.locale.IO_SAVE_TITLE, - ['with-directory'] = (buffer.filename or ''):match('.+[/\\]'), - ['with-file'] = (buffer.filename or ''):match('[^/\\]+$'), - ['no-newline'] = true - } ) + filename = + cocoa_dialog('filesave', { + title = textadept.locale.IO_SAVE_TITLE, + ['with-directory'] = (buffer.filename or ''):match('.+[/\\]'), + ['with-file'] = (buffer.filename or ''):match('[^/\\]+$'), + ['no-newline'] = true + }) end if #filename > 0 then buffer.filename = filename @@ -141,12 +143,12 @@ end function close(buffer) local locale = textadept.locale textadept.check_focused_buffer(buffer) - if buffer.dirty and cocoa_dialog( 'yesno-msgbox', { + if buffer.dirty and cocoa_dialog('yesno-msgbox', { title = locale.IO_CLOSE_TITLE, text = locale.IO_CLOSE_TEXT, ['informative-text'] = locale.IO_CLOSE_MSG, ['no-newline'] = true - } ) ~= '2' then return false end + }) ~= '2' then return false end buffer:delete() return true end @@ -197,20 +199,19 @@ function load_session(filename, only_pm) local buffer = buffer buffer._anchor, buffer._current_pos = anchor, current_pos buffer._first_visible_line = first_visible_line - buffer:line_scroll( 0, - buffer:visible_from_doc_line(first_visible_line) ) + buffer:line_scroll(0, + buffer:visible_from_doc_line(first_visible_line)) buffer:set_sel(anchor, current_pos) elseif line:match('^%s*split%d:') then local level, num, type, size = line:match('^(%s*)split(%d): (%S+) (%d+)') - local view = - splits[#level] and splits[#level][ tonumber(num) ] or view + local view = splits[#level] and splits[#level][tonumber(num)] or view splits[#level + 1] = { view:split(type == 'true') } splits[#level + 1][1].size = tonumber(size) -- could be 1 or 2 elseif line:match('^%s*view%d:') then local level, num, buf_idx = line:match('^(%s*)view(%d): (%d+)$') - local view = splits[#level][ tonumber(num) ] or view - view:goto_buffer( tonumber(buf_idx) ) + local view = splits[#level][tonumber(num)] or view + view:goto_buffer(tonumber(buf_idx)) elseif line:match('^current_view:') then local view_idx, buf_idx = line:match('^current_view: (%d+)') current_view = tonumber(view_idx) or 1 @@ -252,11 +253,12 @@ function save_session(filename) local current = buffer.doc_pointer == textadept.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' + 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, buffer.filename) + buffer_line:format(buffer[anchor] or 0, + buffer[current_pos] or 0, + buffer[first_visible_line] or 0, buffer.filename) buffer_indices[buffer.doc_pointer] = idx - offset else offset = offset + 1 -- don't save untitled files in session @@ -294,7 +296,7 @@ function save_session(filename) session[#session + 1] = ("current_view: %d"):format(current_view) -- Write out other things. local size = textadept.size - session[#session + 1] = ("size: %d %d"):format( size[1], size[2] ) + session[#session + 1] = ("size: %d %d"):format(size[1], size[2]) local pm = textadept.pm session[#session + 1] = ("pm: %d %s"):format(pm.width, pm.entry_text) -- Write the session. @@ -302,7 +304,10 @@ function save_session(filename) if not user_dir then return end local ta_session = user_dir..'/.ta_session' local f = io.open(filename or ta_session, 'w') - if f then f:write( table.concat(session, '\n') ) f:close() end + if f then + f:write(table.concat(session, '\n')) + f:close() + end end --- @@ -327,7 +332,7 @@ function read_api_file(filename, word_chars) line:match('(['..word_chars..']+)%s*(%b())(.*)$') if func and params and desc then if not api[func] then api[func] = {} end - api[func][ #api[func] + 1 ] = { params, desc } + api[func][#api[func] + 1] = { params, desc } end end f:close() diff --git a/core/init.lua b/core/init.lua index 57d06a3d..8a7b96de 100644 --- a/core/init.lua +++ b/core/init.lua @@ -35,7 +35,7 @@ end -- Displays a CocoaDialog of a specified type with given arguments returning -- the result. -- @param kind The CocoaDialog type. --- @param ... A table of key, value arguments. Each key is a --key switch with +-- @param opts A table of key, value arguments. Each key is a --key switch with -- a "value" value. If value is nil, it is omitted and just the switch is -- used. -- @return string CocoaDialog result. @@ -57,7 +57,7 @@ function cocoa_dialog(kind, opts) return lua_dialog.run(args) else local cocoa_dialog = '/CocoaDialog.app/Contents/MacOS/CocoaDialog ' - local p = io.popen( _HOME..cocoa_dialog..table.concat(args, ' ') ) + local p = io.popen(_HOME..cocoa_dialog..table.concat(args, ' ')) local out = p:read('*all') p:close() return out diff --git a/core/locale.lua b/core/locale.lua index 930f1151..ae89ae18 100644 --- a/core/locale.lua +++ b/core/locale.lua @@ -84,8 +84,8 @@ FIND_NO_RESULTS = 'No results found' FIND_ERROR_DIALOG_TITLE = 'Error' -- An error occured: FIND_ERROR_DIALOG_TEXT = 'An error occured' --- replacement(s) made -FIND_REPLACEMENTS_MADE = 'replacement(s) made' +-- "%d replacement(s) made" +FIND_REPLACEMENTS_MADE = '%d replacement(s) made' -- core/ext/keys.lua |