diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/args.lua | 2 | ||||
-rw-r--r-- | core/events.lua | 77 | ||||
-rw-r--r-- | core/file_io.lua | 21 | ||||
-rw-r--r-- | core/gui.lua | 25 |
4 files changed, 62 insertions, 63 deletions
diff --git a/core/args.lua b/core/args.lua index 15b614d3..e6db7696 100644 --- a/core/args.lua +++ b/core/args.lua @@ -9,7 +9,7 @@ local M = {} -- ## Arg Events -- -- + `'arg_none'` --- Called when no command line arguments are passed to Textadept on startup. +-- Emitted when no command line arguments are passed to Textadept on startup. module('args')]] local arg = arg diff --git a/core/events.lua b/core/events.lua index 21cadcf5..51644644 100644 --- a/core/events.lua +++ b/core/events.lua @@ -24,16 +24,16 @@ local M = {} -- event like a keypress if it has already been handled. -- -- @field APPLEEVENT_ODOC (string) --- Called when Mac OSX tells Textadept to open a document. +-- Emitted when Mac OSX tells Textadept to open a document. -- Arguments: -- -- * _`uri`_: The UTF-8-encoded URI to open. -- @field AUTO_C_CHAR_DELETED (string) --- Called when deleting a character while the autocompletion list is active. +-- Emitted when deleting a character while the autocompletion list is active. -- @field AUTO_C_RELEASE (string) --- Called when canceling the autocompletion list. +-- Emitted when canceling the autocompletion list. -- @field AUTO_C_SELECTION (string) --- Called when selecting an item in the autocompletion list and before +-- Emitted when selecting an item in the autocompletion list and before -- inserting the selection. -- Automatic insertion can be cancelled by calling -- [`buffer:auto_c_cancel()`][] before returning from the event handler. @@ -43,30 +43,30 @@ local M = {} -- * _`position`_: The position in the buffer of the beginning of the -- autocompleted word. -- @field BUFFER_AFTER_SWITCH (string) --- Called right after switching to another buffer. +-- Emitted right after switching to another buffer. -- Emitted by [`view:goto_buffer()`][]. -- @field BUFFER_BEFORE_SWITCH (string) --- Called right before switching to another buffer. +-- Emitted right before switching to another buffer. -- Emitted by [`view:goto_buffer()`][]. -- @field BUFFER_DELETED (string) --- Called after deleting a buffer. +-- Emitted after deleting a buffer. -- Emitted by [`buffer:delete()`][]. -- @field BUFFER_NEW (string) --- Called after creating a new buffer. +-- Emitted after creating a new buffer. -- Emitted on startup and by [`buffer.new()`][]. -- @field CALL_TIP_CLICK (string) --- Called when clicking on a calltip. +-- Emitted when clicking on a calltip. -- Arguments: -- -- * _`position`_: `1` if the up arrow was clicked, 2 if the down arrow was -- clicked, and 0 otherwise. -- @field CHAR_ADDED (string) --- Called after adding an ordinary text character to the buffer. +-- Emitted after adding an ordinary text character to the buffer. -- Arguments: -- -- * _`ch`_: The text character byte. -- @field COMMAND_ENTRY_KEYPRESS (string) --- Called when pressing a key in the Command Entry. +-- Emitted when pressing a key in the Command Entry. -- If any handler returns `true`, the key is not inserted into the entry. -- Arguments: -- @@ -76,7 +76,7 @@ local M = {} -- * _`alt`_: The "Alt"/"Option" modifier key is held down. -- * _`meta`_: The "Control" modifier key on Mac OSX is held down. -- @field DOUBLE_CLICK (string) --- Called after double-clicking the mouse button. +-- Emitted after double-clicking the mouse button. -- Arguments: -- -- * _`position`_: The position in the buffer double-clicked. @@ -89,32 +89,32 @@ local M = {} -- `_SCINTILLA.constants.SCMOD_CTRL`, the "Control" modifier is reported as -- *both* "Control" and "Alt" due to a Scintilla limitation with GTK+. -- @field DWELL_END (string) --- Called after a `DWELL_START` when the mouse moves, a key is pressed, etc. +-- Emitted after a `DWELL_START` when the mouse moves, a key is pressed, etc. -- Arguments: -- -- * _`position`_: The position in the buffer closest to *x* and *y*. -- * _`x`_: The x-coordinate of the mouse in the view. -- * _`y`_: The y-coordinate of the mouse in the view. -- @field DWELL_START (string) --- Called after keeping the mouse stationary for the [dwell period][] +-- Emitted after keeping the mouse stationary for the [dwell period][] -- Arguments: -- -- * _`position`_: The position in the buffer closest to *x* and *y*. -- * _`x`_: The x-coordinate of the mouse in the view. -- * _`y`_: The y-coordinate of the mouse in the view. -- @field ERROR (string) --- Called when an error occurs. +-- Emitted when an error occurs. -- Arguments: -- -- * _`text`_: The error text. -- @field FIND (string) --- Called to find text via the Find dialog box. +-- Emitted to find text via the Find dialog box. -- Arguments: -- -- * _`text`_: The text to search for. -- * _`next`_: Whether or not to search forward. -- @field HOTSPOT_CLICK (string) --- Called when clicking on text that is in a style with the hotspot attribute +-- Emitted when clicking on text that is in a style with the hotspot attribute -- set. -- Arguments: -- @@ -127,7 +127,7 @@ local M = {} -- `_SCINTILLA.constants.SCMOD_CTRL`, the "Control" modifier is reported as -- *both* "Control" and "Alt" due to a Scintilla limitation with GTK+. -- @field HOTSPOT_DOUBLE_CLICK (string) --- Called when double-clicking on text that is in a style with the hotspot +-- Emitted when double-clicking on text that is in a style with the hotspot -- attribute set. -- Arguments: -- @@ -140,13 +140,13 @@ local M = {} -- `_SCINTILLA.constants.SCMOD_CTRL`, the "Control" modifier is reported as -- *both* "Control" and "Alt" due to a Scintilla limitation with GTK+. -- @field HOTSPOT_RELEASE_CLICK (string) --- Called after releasing the mouse after clicking on text that was in a style --- with the hotspot attribute set. +-- Emitted after releasing the mouse after clicking on text that was in a +-- style with the hotspot attribute set. -- Arguments: -- -- * _`position`_: The position in the buffer unclicked. -- @field INDICATOR_CLICK (string) --- Called when clicking the mouse on text that has an indicator. +-- Emitted when clicking the mouse on text that has an indicator. -- Arguments: -- -- * _`position`_: The position in the buffer clicked. @@ -158,13 +158,13 @@ local M = {} -- `_SCINTILLA.constants.SCMOD_CTRL`, the "Control" modifier is reported as -- *both* "Control" and "Alt" due to a Scintilla limitation with GTK+. -- @field INDICATOR_RELEASE (string) --- Called after releasing the mouse after clicking on text that had an +-- Emitted after releasing the mouse after clicking on text that had an -- indicator. -- Arguments: -- -- * _`position`_: The position in the buffer unclicked. -- @field KEYPRESS (string) --- Called when pressing a key. +-- Emitted when pressing a key. -- If any handler returns `true`, the key is not inserted into the buffer. -- Arguments: -- @@ -174,7 +174,7 @@ local M = {} -- * _`alt`_: The "Alt"/"Option" modifier key is held down. -- * _`meta`_: The "Control" modifier key on Mac OSX is held down. -- @field MARGIN_CLICK (string) --- Called when clicking the mouse inside a margin. +-- Emitted when clicking the mouse inside a margin. -- Arguments: -- -- * _`margin`_: The margin number clicked. @@ -188,58 +188,59 @@ local M = {} -- `_SCINTILLA.constants.SCMOD_CTRL`, the "Control" modifier is reported as -- *both* "Control" and "Alt" due to a Scintilla limitation with GTK+. -- @field MENU_CLICKED (string) --- Called after selecting a menu item. +-- Emitted after selecting a menu item. -- Arguments: -- -- * _`menu_id`_: The numeric ID of the menu item set in [`gui.menu()`][]. -- @field QUIT (string) --- Called when quitting Textadept. +-- Emitted when quitting Textadept. -- When connecting to this event, connect with an index of 1 or the handler -- will be ignored. -- Emitted by [`quit()`][]. -- @field REPLACE (string) --- Called to replace selected (found) text. +-- Emitted to replace selected (found) text. -- Arguments: -- -- * _`text`_: The text to replace the selected text with. -- @field REPLACE_ALL (string) --- Called to replace all occurrences of found text. +-- Emitted to replace all occurrences of found text. -- Arguments: -- -- * _`find_text`_: The text to search for. -- * _`repl_text`_: The text to replace found text with. -- @field RESET_AFTER (string) --- Called after resetting the Lua state. +-- Emitted after resetting the Lua state. -- Emitted by [`reset()`][]. -- @field RESET_BEFORE (string) --- Called before resetting the Lua state. +-- Emitted before resetting the Lua state. -- Emitted by [`reset()`][]. -- @field SAVE_POINT_LEFT (string) --- Called after leaving a save point. +-- Emitted after leaving a save point. -- @field SAVE_POINT_REACHED (string) --- Called after reaching a save point. +-- Emitted after reaching a save point. -- @field UPDATE_UI (string) --- Called when the text, styling, or selection range in the buffer changes. +-- Emitted when the text, styling, or selection range in the buffer changes. -- @field URI_DROPPED (string) --- Called after dragging and dropping a URI such as a file name onto the view. +-- Emitted after dragging and dropping a URI such as a file name onto the +-- view. -- Arguments: -- -- * _`text`_: The UTF-8-encoded URI text. -- @field USER_LIST_SELECTION (string) --- Called after selecting an item in a user list. +-- Emitted after selecting an item in a user list. -- Arguments: -- -- * _`list_type`_: The *list_type* from [`buffer:user_list_show()`][]. -- * _`text`_: The text of the selection. -- * _`position`_: The position in the buffer the list was displayed at. -- @field VIEW_NEW (string) --- Called after creating a new view. +-- Emitted after creating a new view. -- Emitted on startup and by [`view:split()`][]. -- @field VIEW_BEFORE_SWITCH (string) --- Called right before switching to another view. +-- Emitted right before switching to another view. -- Emitted by [`gui.goto_view()`][]. -- @field VIEW_AFTER_SWITCH (string) --- Called right after switching to another view. +-- Emitted right after switching to another view. -- Emitted by [`gui.goto_view()`][]. -- -- [`buffer:auto_c_cancel()`]: buffer.html#auto_c_cancel diff --git a/core/file_io.lua b/core/file_io.lua index 5314d51d..c6fc45ba 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -25,13 +25,13 @@ -- [`string.iconv()`]: string.html#iconv -- [`_CHARSET`]: _G.html#_CHARSET -- @field _G.events.FILE_OPENED (string) --- Called when opening a file in a new buffer. +-- Emitted when opening a file in a new buffer. -- Emitted by [`open_file()`](#open_file). -- Arguments: -- -- * _`filename`_: The UTF-8-encoded filename. -- @field _G.events.FILE_BEFORE_SAVE (string) --- Called right before saving a file to disk. +-- Emitted right before saving a file to disk. -- Emitted by [`buffer:save()`][]. -- Arguments: -- @@ -39,7 +39,7 @@ -- -- [`buffer:save()`]: buffer.html#save -- @field _G.events.FILE_AFTER_SAVE (string) --- Called right after saving a file to disk. +-- Emitted right after saving a file to disk. -- Emitted by [`buffer:save()`][]. -- Arguments: -- @@ -47,7 +47,7 @@ -- -- [`buffer:save()`]: buffer.html#save -- @field _G.events.FILE_SAVED_AS (string) --- Called after saving a file under a different filename. +-- Emitted after saving a file under a different filename. -- Emitted by [`buffer:save_as()`][]. -- Arguments: -- @@ -79,10 +79,8 @@ io.recent_files = {} -- @class table -- @name boms io.boms = { - ['UTF-16BE'] = string.char(254, 255), - ['UTF-16LE'] = string.char(255, 254), - ['UTF-32BE'] = string.char(0, 0, 254, 255), - ['UTF-32LE'] = string.char(255, 254, 0, 0) + ['UTF-16BE'] = '\254\255', ['UTF-16LE'] = '\255\254', + ['UTF-32BE'] = '\0\0\254\255', ['UTF-32LE'] = '\255\254\0\0' } -- Attempt to detect the encoding of the given text. @@ -93,7 +91,7 @@ io.boms = { local function detect_encoding(text) local b1, b2, b3, b4 = string.byte(text, 1, 4) if b1 == 239 and b2 == 187 and b3 == 191 then - return 'UTF-8', string.char(239, 187, 191) + return 'UTF-8', '\239\187\191' elseif b1 == 254 and b2 == 255 then return 'UTF-16BE', io.boms['UTF-16BE'] elseif b1 == 255 and b2 == 254 then @@ -102,9 +100,8 @@ local function detect_encoding(text) return 'UTF-32BE', io.boms['UTF-32BE'] elseif b1 == 255 and b2 == 254 and b3 == 0 and b4 == 0 then return 'UTF-32LE', io.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 + elseif text:sub(1, 65536):find('\0') then + return 'binary' end return nil end diff --git a/core/gui.lua b/core/gui.lua index 3687aae0..1d0a782b 100644 --- a/core/gui.lua +++ b/core/gui.lua @@ -69,7 +69,7 @@ function gui.print(...) gui._print(_L['[Message Buffer]'], ...) end -- Convenience function for `gui.dialog('filteredlist', ...)` with "Ok" and -- "Cancel" buttons that returns the text or index of the selection depending on -- the boolean value of *int_return*. --- *title* is the title of the dialog,*columns* is a list of column names, and +-- *title* is the title of the dialog, *columns* is a list of column names, and -- *items* is a list of items to show. -- @param title The title for the filtered list dialog. -- @param columns A column name or list of column names. @@ -253,7 +253,7 @@ function gui.select_theme() reset() end -local events, events_connect = events, events.connect +local events, events_connect, events_emit = events, events.connect, events.emit -- Sets default properties for a Scintilla window. events_connect(events.VIEW_NEW, function() @@ -275,7 +275,7 @@ events_connect(events.VIEW_NEW, function() local ok, err = pcall(dofile, THEME..'/view.lua') if not ok then io.stderr:write(err) end end) -events_connect(events.VIEW_NEW, function() events.emit(events.UPDATE_UI) end) +events_connect(events.VIEW_NEW, function() events_emit(events.UPDATE_UI) end) local SETDIRECTFUNCTION = _SCINTILLA.properties.direct_function[1] local SETDIRECTPOINTER = _SCINTILLA.properties.doc_pointer[2] @@ -345,7 +345,7 @@ events_connect(events.URI_DROPPED, function(utf8_uris) end end) events_connect(events.APPLEEVENT_ODOC, function(uri) - return events.emit(events.URI_DROPPED, 'file://'..uri) + return events_emit(events.URI_DROPPED, 'file://'..uri) end) local string_format = string.format @@ -360,7 +360,7 @@ events_connect(events.UPDATE_UI, function() local lexer = buffer:private_lexer_call(GETLEXERLANGUAGE) local eol = EOLs[buffer.eol_mode + 1] local tabs = string_format('%s %d', buffer.use_tabs and _L['Tabs:'] or - _L['Spaces:'], buffer.tab_width) + _L['Spaces:'], buffer.tab_width) local enc = buffer.encoding or '' local text = not CURSES and '%s %d/%d %s %d %s %s %s %s' or '%s %d/%d %s %d %s %s %s %s' @@ -374,7 +374,7 @@ events_connect(events.MARGIN_CLICK, function(margin, pos, modifiers) end) -- Updates the statusbar and titlebar for a new Scintilla document. -events_connect(events.BUFFER_NEW, function() events.emit(events.UPDATE_UI) end) +events_connect(events.BUFFER_NEW, function() events_emit(events.UPDATE_UI) end) events_connect(events.BUFFER_NEW, function() set_title(buffer) end) -- Save buffer properties. @@ -396,7 +396,7 @@ events_connect(events.BUFFER_AFTER_SWITCH, function() local buffer = buffer if not buffer._folds then return end -- Restore fold state. - for _, i in ipairs(buffer._folds) do buffer:toggle_fold(i) end + for i = 1, #buffer._folds do buffer:toggle_fold(buffer._folds[i]) end -- Restore view state. buffer:set_sel(buffer._anchor, buffer._current_pos) buffer:line_scroll(0, @@ -407,13 +407,13 @@ end) -- Updates titlebar and statusbar. events_connect(events.BUFFER_AFTER_SWITCH, function() set_title(buffer) - events.emit(events.UPDATE_UI) + events_emit(events.UPDATE_UI) end) -- Updates titlebar and statusbar. events_connect(events.VIEW_AFTER_SWITCH, function() set_title(buffer) - events.emit(events.UPDATE_UI) + events_emit(events.UPDATE_UI) end) events_connect(events.RESET_AFTER, @@ -457,13 +457,14 @@ local size The functions below are Lua C functions. --- --- Displays a *kind* [gtdialog][1] with the given string arguments to pass to +-- Displays a *kind* [gtdialog][] with the given string arguments to pass to -- the dialog and returns a formatted string of the dialog's output. -- Table arguments containing strings are allowed and expanded in place. This is -- useful for filtered list dialogs with many items. --- For more information on gtdialog, see [http://foicica.com/gtdialog][1]. +-- For more information on gtdialog, see [http://foicica.com/gtdialog][]. -- --- [1]: http://foicica.com/gtdialog +-- [gtdialog]: http://foicica.com/gtdialog/02_Usage.html +-- [http://foicica.com/gtdialog]: http://foicica.com/gtdialog -- @param kind The kind of gtdialog. -- @param ... Parameters to the gtdialog. -- @return string gtdialog result. |