diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/._m.luadoc | 5 | ||||
-rw-r--r-- | core/.command_entry.luadoc | 12 | ||||
-rw-r--r-- | core/.find.luadoc | 17 | ||||
-rw-r--r-- | core/args.lua | 18 | ||||
-rw-r--r-- | core/events.lua | 86 | ||||
-rw-r--r-- | core/file_io.lua | 131 | ||||
-rw-r--r-- | core/gui.lua | 24 | ||||
-rw-r--r-- | core/init.lua | 8 | ||||
-rw-r--r--[-rwxr-xr-x] | core/locale.conf | 0 |
9 files changed, 153 insertions, 148 deletions
diff --git a/core/._m.luadoc b/core/._m.luadoc index d5f52a94..c8665fad 100644 --- a/core/._m.luadoc +++ b/core/._m.luadoc @@ -34,6 +34,11 @@ module('_m') -- [m_cpp]: ../modules/_m.cpp.html -- [m_lua]: ../modules/_m.lua.html -- +-- For language modules that have a `set_buffer_properties` function, that +-- function is called each time a file with that language is opened. This is +-- useful for setting `buffer.use_tabs`, `buffer.tab_width`, etc. for different +-- languages. +-- -- Note: While language-specific modules can only be used by files of that -- language, they persist in Textadept's Lua state. Because of this, it is not -- recommended to set global functions or variables and depend on them, as they diff --git a/core/.command_entry.luadoc b/core/.command_entry.luadoc index 93615f22..e474fa13 100644 --- a/core/.command_entry.luadoc +++ b/core/.command_entry.luadoc @@ -37,6 +37,18 @@ module('gui.command_entry') -- `modules/textadept/find.lua` for the implementation. -- -- [inc_search]: ../modules/gui.find.html#incremental +-- +-- ## Events +-- +-- The following is a list of all command entry events generated in +-- `event_name(arguments)` format: +-- +-- * **command\_entry\_command** (command)<br /> +-- Called when a command is entered into the Command Entry. +-- - command: the string command. +-- * **command\_entry\_keypress** (code)<br /> +-- Called when a key is pressed in the Command Entry. +-- - code: the key code (according to `<gdk/gdkkeysyms.h>`). --- Focuses the command entry. function focus() end diff --git a/core/.find.luadoc b/core/.find.luadoc index e47eafd9..038d3943 100644 --- a/core/.find.luadoc +++ b/core/.find.luadoc @@ -47,6 +47,23 @@ module('gui.find') -- names of `textadept-find-entry` and `textadept-replace-entry` respectively. -- -- [gtkrc]: http://library.gnome.org/devel/gtk/unstable/gtk-Resource-Files.html. +-- +-- ## Events +-- +-- The following is a list of all find events generated in +-- `event_name(arguments)` format: +-- +-- * **find** (text, next)<br /> +-- Called when attempting to finding text via the Find dialog box. +-- - text: the text to search for. +-- - next: flat indicating whether or not the search direction is forward. +-- * **replace** (text)<br /> +-- Called when the found text is selected and asked to be replaced. +-- - text: the text to replace the selected text with. +-- * **replace\_all** (find\_text, repl\_text)<br /> +-- Called when all occurances of found text are to be replaced. +-- - find\_text: the text to search for. +-- - repl\_text: the text to replace found text with. --- Displays and focuses the find/replace dialog. function focus() end diff --git a/core/args.lua b/core/args.lua index cd1b682f..9535fa63 100644 --- a/core/args.lua +++ b/core/args.lua @@ -3,6 +3,18 @@ --- Processes command line arguments for Textadept. module('args', package.seeall) +-- Markdown: +-- +-- ## Events +-- +-- The following is a list of all arg events generated in +-- `event_name(arguments)` format: +-- +-- * **arg\_none** ()<br /> +-- Called when no command line args have been passed to Textadept on init. + +local arg = arg + -- Contains registered command line switches. -- @class table -- @name switches @@ -17,8 +29,7 @@ local switches = {} -- @param description Description of the switch. function register(switch1, switch2, narg, f, description) local t = { f, narg, description } - switches[switch1] = t - switches[switch2] = t + switches[switch1], switches[switch2] = t, t end --- @@ -47,6 +58,7 @@ function process() if no_args then events.emit('arg_none') end end +-- Shows all registered command line switches in a help dialog. local function show_help() local line = "%s [%d args] -- %s" local help = {} @@ -64,7 +76,6 @@ register('-h', '--help', 0, show_help, 'Displays this') -- For Windows, create arg table from single command line string (arg[0]). if WIN32 and #arg[0] > 0 then - local lpeg = require 'lpeg' local P, C = lpeg.P, lpeg.C local param = P('"') * C((1 - P('"'))^0) * '"' + C((1 - P(' '))^1) local params = lpeg.match(lpeg.Ct(param * (P(' ')^1 * param)^0), arg[0]) @@ -79,7 +90,6 @@ for i = 1, #arg do break end end -local lfs = require 'lfs' if not lfs.attributes(userhome) then lfs.mkdir(userhome) end if not lfs.attributes(userhome..'/init.lua') then local f = io.open(userhome..'/init.lua', 'w') diff --git a/core/events.lua b/core/events.lua index 2157f58d..a0cc2bdd 100644 --- a/core/events.lua +++ b/core/events.lua @@ -74,7 +74,7 @@ module('events', package.seeall) -- -- [buffer_user_list_show]: ../modules/buffer.html#buffer:user_list_show -- --- The following is a list of all Textadept events generated in +-- The following is a list of gui events generated in -- `event_name(arguments)` format: -- -- * **buffer\_new** ()<br /> @@ -91,46 +91,25 @@ module('events', package.seeall) -- Called right before another [view][view] is switched to. -- * **view\_after\_switch** ()<br /> -- Called right after [view][view] was switched to. --- * **reset\_before()**<br /> +-- * **reset\_before** ()<br /> -- Called before resetting the Lua state during a call to [`reset()`][reset]. --- * **reset\_after()**<br /> +-- * **reset\_after** ()<br /> -- Called after resetting the Lua state during a call to [`reset()`][reset]. -- * **quit** ()<br /> -- Called when quitting Textadept.<br /> -- Note: Any quit handlers added must be inserted at index 1 because the -- default quit handler in `core/events.lua` returns `true`, which ignores all -- subsequent handlers. --- * **keypress** (code, shift, control, alt)<br /> --- Called when a key is pressed. --- - code: the key code (according to `<gdk/gdkkeysyms.h>`). --- - shift: flag indicating whether or not the Shift key is pressed. --- - control: flag indicating whether or not the Control key is pressed. --- - alt: flag indicating whether or not the Alt/Apple key is pressed. --- <br /> --- Note: The Alt-Option key in Mac OSX is not available. --- * **menu\_clicked** (menu\_id)<br /> --- Called when a menu item is selected. --- - menu\_id: the numeric ID of the menu item set in --- [`gui.gtkmenu()`][gui_gtkmenu]. --- * **find** (text, next)<br /> --- Called when attempting to finding text via the Find dialog box. --- - text: the text to search for. --- - next: flat indicating whether or not the search direction is forward. --- * **replace** (text)<br /> --- Called when the found text is selected and asked to be replaced. --- - text: the text to replace the selected text with. --- * **replace\_all** (find\_text, repl\_text)<br /> --- Called when all occurances of found text are to be replaced. --- - find\_text: the text to search for. --- - repl\_text: the text to replace found text with. --- * **command\_entry\_keypress** (code)<br /> --- Called when a key is pressed in the Command Entry. --- - code: the key code (according to `<gdk/gdkkeysyms.h>`). +-- * **error** (text)<br /> +-- Called when an error occurs in the C code. +-- - text: The error text. +-- * **appleevent\_odoc** (uri)<br /> +-- Called when Mac OSX instructs Textadept to open a document. +-- - uri: The URI to open. -- -- [buffer]: ../modules/buffer.html -- [view]: ../modules/view.html -- [reset]: ../modules/_G.html#reset --- [gui_gtkmenu]: ../modules/gui.html#gtkmenu -- -- ## Example -- @@ -231,7 +210,7 @@ connect('view_new', local buffer = buffer local c = _SCINTILLA.constants - -- allow redefinitions of these Scintilla key commands + -- Allow redefinitions of these Scintilla key commands. local ctrl_keys = { '[', ']', '/', '\\', 'Z', 'Y', 'X', 'C', 'V', 'A', 'L', 'T', 'D', 'U' } @@ -244,9 +223,9 @@ connect('view_new', end if _THEME and #_THEME > 0 then - local ret, errmsg = pcall(dofile, _THEME..'/view.lua') - if ret then return end - io.stderr:write(errmsg) + local ok, err = pcall(dofile, _THEME..'/view.lua') + if ok then return end + io.stderr:write(err) end end) @@ -258,14 +237,14 @@ connect('buffer_new', local function run() local buffer = buffer - -- lexer + -- Lexer. buffer:set_lexer_language('lpeg') buffer:private_lexer_call(SETDIRECTFUNCTION, buffer.direct_function) buffer:private_lexer_call(SETDIRECTPOINTER, buffer.direct_pointer) buffer:private_lexer_call(SETLEXERLANGUAGE, 'container') buffer.style_bits = 8 - -- properties + -- Properties. buffer.property['textadept.home'] = _HOME buffer.property['lexer.lpeg.home'] = _LEXERPATH buffer.property['lexer.lpeg.script'] = _HOME..'/lexers/lexer.lua' @@ -273,21 +252,21 @@ connect('buffer_new', buffer.property['lexer.lpeg.color.theme'] = _THEME..'/lexer.lua' end - -- buffer + -- Buffer. buffer.code_page = _SCINTILLA.constants.SC_CP_UTF8 if _THEME and #_THEME > 0 then - local ret, errmsg = pcall(dofile, _THEME..'/buffer.lua') - if ret then return end - io.stderr:write(errmsg) + local ok, err = pcall(dofile, _THEME..'/buffer.lua') + if ok then return end + io.stderr:write(err) end end - -- normally when an error occurs, a new buffer is created with the error + -- Normally when an error occurs, a new buffer is created with the error -- message, but if an error occurs here, this event would be called again -- and again, erroring each time resulting in an infinite loop; print error - -- to stderr instead - local ret, errmsg = pcall(run) - if not ret then io.stderr:write(errmsg) end + -- to stderr instead. + local ok, err = pcall(run) + if not ok then io.stderr:write(err) end end) -- Sets the title of the Textadept window to the buffer's filename. @@ -313,17 +292,13 @@ connect('save_point_left', end) connect('uri_dropped', - function(utf8_uris) - local lfs = require 'lfs' - for utf8_uri in utf8_uris:gmatch('[^\r\n\f]+') do + function(utf8_uris) -- open uri(s) + for utf8_uri in utf8_uris:gmatch('[^\r\n]+') do if utf8_uri:find('^file://') then - utf8_uri = utf8_uri:match('^file://([^\r\n\f]+)') + utf8_uri = utf8_uri:match('^file://([^\r\n]+)') utf8_uri = utf8_uri:gsub('%%(%x%x)', function(hex) return string.char(tonumber(hex, 16)) end) - if WIN32 then - utf8_uri = utf8_uri:sub(2, -1) -- ignore leading '/' - utf8_uri = utf8_uri:gsub('/', '\\') - end + if WIN32 then utf8_uri = utf8_uri:sub(2, -1) end -- ignore leading '/' local uri = utf8_uri:iconv(_CHARSET, 'UTF-8') if lfs.attributes(uri).mode ~= 'directory' then io.open_file(utf8_uri) @@ -353,8 +328,7 @@ connect('update_ui', connect('margin_click', function(margin, modifiers, position) -- toggles folding - local line = buffer:line_from_position(position) - buffer:toggle_fold(line) + buffer:toggle_fold(buffer:line_from_position(position)) end) connect('buffer_new', function() set_title(buffer) end) @@ -405,15 +379,13 @@ connect('reset_after', function() gui.statusbar_text = 'Lua reset' end) connect('quit', function() -- prompts for confirmation if any buffers are dirty - local any = false local list = {} for _, buffer in ipairs(_BUFFERS) do if buffer.dirty then list[#list + 1] = buffer.filename or buffer._type or L('Untitled') - any = true end end - if any and + if #list > 0 and gui.dialog('msgbox', '--title', L('Quit without saving?'), '--text', L('The following buffers are unsaved:'), diff --git a/core/file_io.lua b/core/file_io.lua index 74d5b71f..fded1499 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -42,7 +42,7 @@ module('io', package.seeall) -- -- ## Events -- --- The following is a list of all File I/O events generated in +-- The following is a list of all file I/O events generated in -- `event_name(arguments)` format: -- -- * **file\_opened** (filename) <br /> @@ -55,8 +55,6 @@ module('io', package.seeall) -- Called when a file is saved under another filename. -- - filename: the other filename encoded in UTF-8. -local lfs = require 'lfs' - --- -- List of recently opened files. -- @class table @@ -84,13 +82,13 @@ local function detect_encoding(text) if b1 == 239 and b2 == 187 and b3 == 191 then return 'UTF-8', string.char(239, 187, 191) elseif b1 == 254 and b2 == 255 then - return 'UTF-16BE', boms[encoding] + return 'UTF-16BE', boms['UTF-16BE'] elseif b1 == 255 and b2 == 254 then - return 'UTF-16LE', boms[encoding] + return 'UTF-16LE', boms['UTF-16LE'] elseif b1 == 0 and b2 == 0 and b3 == 254 and b4 == 255 then - return 'UTF-32BE', boms[encoding] + return 'UTF-32BE', boms['UTF-32BE'] elseif b1 == 255 and b2 == 254 and b3 == 0 and b4 == 0 then - return 'UTF-32LE', boms[encoding] + return 'UTF-32LE', boms['UTF-32LE'] else local chunk = #text > 65536 and text:sub(1, 65536) or text if chunk:find('\0') then return 'binary' end -- binary file @@ -116,9 +114,9 @@ local function open_helper(utf8_filename) if not utf8_filename then return end utf8_filename = utf8_filename:gsub('^file://', '') if WIN32 then utf8_filename = utf8_filename:gsub('/', '\\') end - for index, buffer in ipairs(_BUFFERS) do + for i, buffer in ipairs(_BUFFERS) do if utf8_filename == buffer.filename then - view:goto_buffer(index) + view:goto_buffer(i) return end end @@ -126,58 +124,54 @@ local function open_helper(utf8_filename) local text local filename = utf8_filename:iconv(_CHARSET, 'UTF-8') local f, err = io.open(filename, 'rb') - if f then - text = f:read('*all') - f:close() - if not text then return end -- filename exists, but can't read it - else - error(err) - end + if not f then error(err) end + text = f:read('*all') + f:close() + if not text then return end -- filename exists, but can't read it local buffer = new_buffer() - if text then - -- Tries to detect character encoding and convert text from it to UTF-8. - local encoding, encoding_bom = detect_encoding(text) - if encoding ~= 'binary' then - if encoding then - if encoding_bom then text = text:sub(#encoding_bom + 1, -1) end - text = text:iconv('UTF-8', encoding) - else - -- Try list of encodings. - for _, try_encoding in ipairs(try_encodings) do - local ret, conv = pcall(string.iconv, text, 'UTF-8', try_encoding) - if ret then - encoding = try_encoding - text = conv - break - end + -- Tries to detect character encoding and convert text from it to UTF-8. + local encoding, encoding_bom = detect_encoding(text) + if encoding ~= 'binary' then + if encoding then + if encoding_bom then text = text:sub(#encoding_bom + 1, -1) end + text = text:iconv('UTF-8', encoding) + else + -- Try list of encodings. + for _, try_encoding in ipairs(try_encodings) do + local ret, conv = pcall(string.iconv, text, 'UTF-8', try_encoding) + if ret then + encoding = try_encoding + text = conv + break end - if not encoding then error(L('Encoding conversion failed.')) end end - else - encoding = nil - end - local c = _SCINTILLA.constants - buffer.encoding, buffer.encoding_bom = encoding, encoding_bom - buffer.code_page = encoding and c.SC_CP_UTF8 or 0 - -- Tries to set the buffer's EOL mode appropriately based on the file. - local s, e = text:find('\r\n?') - if s and e then - buffer.eol_mode = (s == e and c.SC_EOL_CR or c.SC_EOL_CRLF) - else - buffer.eol_mode = c.SC_EOL_LF + if not encoding then error(L('Encoding conversion failed.')) end end - buffer:add_text(text, #text) - buffer:goto_pos(0) - buffer:empty_undo_buffer() - buffer.modification_time = lfs.attributes(filename).modification + else + encoding = nil + end + local c = _SCINTILLA.constants + buffer.encoding, buffer.encoding_bom = encoding, encoding_bom + buffer.code_page = encoding and c.SC_CP_UTF8 or 0 + -- Tries to set the buffer's EOL mode appropriately based on the file. + local s, e = text:find('\r\n?') + if s and e then + buffer.eol_mode = (s == e and c.SC_EOL_CR or c.SC_EOL_CRLF) + else + buffer.eol_mode = c.SC_EOL_LF end + buffer:add_text(text, #text) + buffer:goto_pos(0) + buffer:empty_undo_buffer() + buffer.modification_time = lfs.attributes(filename).modification buffer.filename = utf8_filename buffer:set_save_point() events.emit('file_opened', utf8_filename) - for index, file in ipairs(recent_files) do + -- Add file to recent files list, eliminating duplicates. + for i, file in ipairs(recent_files) do if file == utf8_filename then - table.remove(recent_files, index) + table.remove(recent_files, i) break end end @@ -200,7 +194,7 @@ function open_file(utf8_filenames) for filename in utf8_filenames:gmatch('[^\n]+') do open_helper(filename) end end --- LuaDoc is in core/.buffer.lua. +-- LuaDoc is in core/.buffer.luadoc. local function reload(buffer) gui.check_focused_buffer(buffer) if not buffer.filename then return end @@ -222,7 +216,7 @@ local function reload(buffer) buffer.modification_time = lfs.attributes(filename).modification end --- LuaDoc is in core/.buffer.lua. +-- LuaDoc is in core/.buffer.luadoc. local function set_encoding(buffer, encoding) gui.check_focused_buffer(buffer) if not buffer.encoding then error(L('Cannot change binary file encoding')) end @@ -239,7 +233,7 @@ local function set_encoding(buffer, encoding) buffer.encoding, buffer.encoding_bom = encoding, boms[encoding] end --- LuaDoc is in core/.buffer.lua. +-- LuaDoc is in core/.buffer.luadoc. local function save(buffer) gui.check_focused_buffer(buffer) if not buffer.filename then return buffer:save_as() end @@ -251,18 +245,15 @@ local function save(buffer) end local filename = buffer.filename:iconv(_CHARSET, 'UTF-8') local f, err = io.open(filename, 'wb') - if f then - f:write(text) - f:close() - buffer:set_save_point() - buffer.modification_time = lfs.attributes(filename).modification - else - error(err) - end + if not f then error(err) end + f:write(text) + f:close() + buffer:set_save_point() + buffer.modification_time = lfs.attributes(filename).modification if buffer._type then buffer._type = nil end end --- LuaDoc is in core/.buffer.lua. +-- LuaDoc is in core/.buffer.luadoc. local function save_as(buffer, utf8_filename) gui.check_focused_buffer(buffer) if not utf8_filename then @@ -287,15 +278,15 @@ end function save_all() local current_buffer = buffer local current_index - for index, buffer in ipairs(_BUFFERS) do - view:goto_buffer(index) - if buffer == current_buffer then current_index = index end + for i, buffer in ipairs(_BUFFERS) do + view:goto_buffer(i) + if buffer == current_buffer then current_index = i end if buffer.filename and buffer.dirty then buffer:save() end end view:goto_buffer(current_index) end --- LuaDoc is in core/.buffer.lua. +-- LuaDoc is in core/.buffer.luadoc. local function close(buffer) gui.check_focused_buffer(buffer) if buffer.dirty and @@ -325,8 +316,7 @@ function close_all() view:goto_buffer(#_BUFFERS) if not buffer:close() then return false end end - buffer:close() -- the last one - return true + return buffer:close() -- the last one end -- Prompts the user to reload the current file if it has been modified outside @@ -338,6 +328,7 @@ local function update_modified_file() local attributes = lfs.attributes(filename) if not attributes or not buffer.modification_time then return end if buffer.modification_time < attributes.modification then + buffer.modification_time = attributes.modification if gui.dialog('yesno-msgbox', '--title', L('Reload?'), '--text', L('Reload modified file?'), @@ -347,8 +338,6 @@ local function update_modified_file() '--no-cancel', '--no-newline') == '1' then buffer:reload() - else - buffer.modification_time = attributes.modification end end end diff --git a/core/gui.lua b/core/gui.lua index ef9892cc..2e184beb 100644 --- a/core/gui.lua +++ b/core/gui.lua @@ -3,7 +3,7 @@ local L = _G.locale.localize local gui = _G.gui --- LuaDoc is in core/.gui.lua. +-- LuaDoc is in core/.gui.luadoc. function gui.check_focused_buffer(buffer) if type(buffer) ~= 'table' or not buffer.doc_pointer then error(L('Buffer argument expected.'), 2) @@ -12,18 +12,17 @@ function gui.check_focused_buffer(buffer) end end --- LuaDoc is in core/.gui.lua. +-- LuaDoc is in core/.gui.luadoc. function gui._print(buffer_type, ...) local function safe_print(...) - local message = table.concat({...}, '\t') local message_buffer, message_buffer_index local message_view, message_view_index - for index, buffer in ipairs(_BUFFERS) do + for i, buffer in ipairs(_BUFFERS) do if buffer._type == buffer_type then - message_buffer, message_buffer_index = buffer, index - for jndex, view in ipairs(_VIEWS) do + message_buffer, message_buffer_index = buffer, i + for j, view in ipairs(_VIEWS) do if view.doc_pointer == message_buffer.doc_pointer then - message_view, message_view_index = view, jndex + message_view, message_view_index = view, j break end end @@ -42,16 +41,17 @@ function gui._print(buffer_type, ...) else gui.goto_view(message_view_index, true) end - message_buffer:append_text(message..'\n') + message_buffer:append_text(table.concat({...}, '\t')) + message_buffer:append_text('\n') message_buffer:set_save_point() end - pcall(safe_print, ...) -- prevent endless loops if this errors + pcall(safe_print, ...) -- prevent endless loops on error end --- LuaDoc is in core/.gui.lua. +-- LuaDoc is in core/.gui.luadoc. function gui.print(...) gui._print(L('[Message Buffer]'), ...) end --- LuaDoc is in core/.gui.lua. +-- LuaDoc is in core/.gui.luadoc. function gui.switch_buffer() local items = {} for _, buffer in ipairs(_BUFFERS) do @@ -68,5 +68,5 @@ function gui.switch_buffer() '--columns', 'Name', 'File', '--items', items) local ok, i = response:match('(%-?%d+)\n(%d+)$') - if ok and ok ~= '2' then view:goto_buffer(tonumber(i) + 1, true) end + if ok == '1' then view:goto_buffer(tonumber(i) + 1, true) end end diff --git a/core/init.lua b/core/init.lua index 6f2dbedb..6cd82211 100644 --- a/core/init.lua +++ b/core/init.lua @@ -27,12 +27,12 @@ if not _THEME:find('[/\\]') then if not lfs.attributes(_THEME) then _THEME = _HOME..'/themes/'..theme end end --- LuaDoc is in core/._G.lua. +-- LuaDoc is in core/._G.luadoc. function _G.user_dofile(filename) if lfs.attributes(_USERHOME..'/'..filename) then - local ret, errmsg = pcall(dofile, _USERHOME..'/'..filename) - if not ret then gui.print(errmsg) end - return ret + local ok, err = pcall(dofile, _USERHOME..'/'..filename) + if not ok then gui.print(err) end + return ok end return false end diff --git a/core/locale.conf b/core/locale.conf index 2f87cfbc..2f87cfbc 100755..100644 --- a/core/locale.conf +++ b/core/locale.conf |