diff options
36 files changed, 533 insertions, 506 deletions
diff --git a/core/._G.lua b/core/._G.lua new file mode 100644 index 00000000..2d78dc2e --- /dev/null +++ b/core/._G.lua @@ -0,0 +1,74 @@ +-- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. +-- This is a DUMMY FILE used for making LuaDoc for built-in functions in the +-- _G table. + +--- Extends Lua's _G table to provide extra functions and fields. +module('_G') + +-- Markdown: +-- ## Fields +-- +-- * `_HOME`: Path to the directory containing Textadept. +-- * `_LEXERPATH`: Paths to lexers, formatted like +-- [`package.path`][package_path]. +-- * `_RELEASE`: The Textadept release version. +-- * `_THEME`: The [theme][theme] file to use. +-- * `_USERHOME`: Path to the user's `~/.textadept/`. +-- * `_CHARSET`: The character set encoding of the filesystem. This is used in +-- [File I/O][file_io]. +-- * `RESETTING`: If [`reset()`][reset] has been called, +-- this flag is `true` while the Lua state is being re-initialized. +-- * `WIN32`: If Textadept is running on Windows, this flag is `true`. +-- * `MAC`: If Textadept is running on Mac OSX, this flag is `true`. +-- +-- [package_path]: http://www.lua.org/manual/5.1/manual.html#pdf-package.path +-- [theme]: ../manual/6_Startup.html +-- [file_io]: ../modules/io.html +-- [reset]: ../modules/_G.html#reset + +--- +-- Command line parameters. +-- @class table +-- @name arg +arg = {} + + +--- +-- A numerically indexed table of open buffers in Textadept. +-- @class table +-- @name _BUFFERS +_BUFFERS = {} + +--- +-- A numerically indexed table of views in Textadept. +-- @class table +-- @name _VIEWS +_VIEWS = {} + +--- +-- Creates a new buffer. +-- Activates the 'buffer_new' signal. +-- @return the new buffer. +function new_buffer() end + +--- +-- Resets the Lua state by reloading all init scripts. +-- Language-specific modules for opened files are NOT reloaded. Re-opening the +-- files that use them will reload those modules. +-- This function is useful for modifying init scripts (such as key_commands.lua) +-- on the fly without having to restart Textadept. +-- A global RESETTING variable is set to true when re-initing the Lua State. Any +-- scripts that need to differentiate between startup and reset can utilize this +-- variable. +function reset() end + +--- Quits Textadept. +function quit() end + +--- +-- Calls 'dofile' on the given filename in the user's Textadept directory. +-- This is typically used for loading user files like key commands or snippets. +-- Errors are printed to the Textadept message buffer. +-- @param filename The name of the file (not path). +-- @return true if successful; false otherwise. +function user_dofile(filename) end diff --git a/core/._m.lua b/core/._m.lua index e50885a6..7cd677eb 100644 --- a/core/._m.lua +++ b/core/._m.lua @@ -55,7 +55,7 @@ module('_m') -- are placed at the end of files, like `commands.lua` in language-specific -- modules. -- --- [key_commands]: ../modules/textadept.keys.html +-- [key_commands]: ../modules/keys.html --- -- This module contains no functions. diff --git a/core/.buffer.lua b/core/.buffer.lua index e76edcf7..579c70f0 100644 --- a/core/.buffer.lua +++ b/core/.buffer.lua @@ -15,8 +15,8 @@ module('buffer') -- * `dirty`: Flag indicating whether or not the buffer has been modified since -- it was last saved. -- * `filename`: The absolute path to the file associated with this buffer. It --- is encoded in UTF-8. Use [`textadept.iconv()`][textadept_iconv] for --- charset conversions. +-- is encoded in UTF-8. Use [`string.iconv()`][string_iconv] for charset +-- conversions. -- * `encoding`: The encoding of the file on the hard disk. It will be nil if -- the file is a binary file. -- * `encoding_bom`: The byte-order mark of the file encoding (if any). @@ -336,7 +336,7 @@ module('buffer') -- * `x_offset`: The horizontal scroll position. -- * `zoom`: The zoom level added to all font sizes. +: magnify, -: reduce. -- --- [textadept_iconv]: ../modules/textadept.html#iconv +-- [string_iconv]: ../modules/string.html#iconv -- [color]: http://scintilla.org/ScintillaDoc.html#colour --- diff --git a/core/.command_entry.lua b/core/.command_entry.lua index 3c5749d9..030add89 100644 --- a/core/.command_entry.lua +++ b/core/.command_entry.lua @@ -1,10 +1,10 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -- This is a DUMMY FILE used for making LuaDoc for built-in functions in the --- global textadept.command_entry table. +-- global gui.command_entry table. --- -- Textadept's Command entry. -module('textadept.command_entry') +module('gui.command_entry') -- Markdown: -- ## Fields @@ -22,11 +22,11 @@ module('textadept.command_entry') -- `Tab` key to display a list of available completions. Use the arrow keys to -- make a selection and press `Enter` to insert it. -- --- Note: Use [`textadept.print()`][textadept_print] instead of the global --- `print()` function. The former prints to a new buffer, the latter to standard --- out (`STDOUT`). +-- Note: Use [`gui.print()`][gui_print] instead of the global `print()` +-- function. The former prints to a new buffer, the latter to standard out +-- (`STDOUT`). -- --- [textadept_print]: ../modules/textadept.html#print +-- [gui_print]: ../modules/gui.html#print -- -- ## Extending -- @@ -34,7 +34,7 @@ module('textadept.command_entry') -- example of this is [incremental search][inc_search]. See `core/ext/find.lua` -- for the implementation. -- --- [inc_search]: ../modules/textadept.find.html#incremental +-- [inc_search]: ../modules/gui.find.html#incremental --- Focuses the command entry. function focus() end diff --git a/core/.find.lua b/core/.find.lua index bcab94fc..87cbf257 100644 --- a/core/.find.lua +++ b/core/.find.lua @@ -1,10 +1,10 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -- This is a DUMMY FILE used for making LuaDoc for built-in functions in the --- global textadept.find table. +-- global gui.find table. --- -- Textadept's integrated find/replace dialog. -module('textadept.find') +module('gui.find') -- Markdown: -- ## Fields diff --git a/core/.textadept.lua b/core/.gui.lua index 5fe9776d..04869e70 100644 --- a/core/.textadept.lua +++ b/core/.gui.lua @@ -1,10 +1,9 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -- This is a DUMMY FILE used for making LuaDoc for built-in functions in the --- global textadept table. +-- global gui table. ---- --- The core textadept table. -module('textadept') +--- The core gui table. +module('gui') -- Markdown: -- ## Fields @@ -18,27 +17,6 @@ module('textadept') -- * `statusbar_text`: The text displayed by the statusbar (write-only). -- * `docstatusbar_text`: The text displayed by the doc statusbar (write-only). -- * `size`: The size of the Textadept window (`{ width, height}`). --- * `constants`: Table containing Scintilla constants. --- * `buffer_functions`: Table containing Scintilla functions. --- * `buffer_properties`: Table containing Scintilla set/get functions. - ---- --- A numerically indexed table of open buffers in Textadept. --- @class table --- @name buffers -buffers = {} - ---- --- A numerically indexed table of views in Textadept. --- @class table --- @name views -views = {} - ---- --- Creates a new buffer. --- Activates the 'buffer_new' signal. --- @return the new buffer. -function new_buffer() end --- -- Goes to the specified view. @@ -69,29 +47,6 @@ function get_split_table() end function gtkmenu(menu_table) end --- --- Converts a string from one character set to another using iconv(). --- Valid character sets are ones GLib's g_convert() accepts, typically GNU --- iconv's character sets. --- @param text The text to convert. --- @param to The character set to convert to. --- @param from The character set to convert from. -function iconv(text, to, from) end - ---- --- Resets the Lua state by reloading all init scripts. --- Language-specific modules for opened files are NOT reloaded. Re-opening the --- files that use them will reload those modules. --- This function is useful for modifying init scripts (such as key_commands.lua) --- on the fly without having to restart Textadept. --- A global RESETTING variable is set to true when re-initing the Lua State. Any --- scripts that need to differentiate between startup and reset can utilize this --- variable. -function reset() end - ---- Quits Textadept. -function quit() end - ---- -- Checks if the buffer being indexed is the currently focused buffer. -- This is necessary because any buffer actions are performed in the focused -- views' buffer, which may not be the buffer being indexed. Throws an error @@ -107,8 +62,8 @@ function check_focused_buffer(buffer) end -- buffer, and prints to it. -- @param buffer_type String type of message buffer. -- @param ... Message strings. --- @usage textadept._print(locale.ERROR_BUFFER, error_message) --- @usage textadept._print(locale.MESSAGE_BUFFER, message) +-- @usage gui._print(locale.ERROR_BUFFER, error_message) +-- @usage gui._print(locale.MESSAGE_BUFFER, message) function _print(buffer_type, ...) end --- @@ -127,11 +82,3 @@ function switch_buffer() end -- Each argument is like a string in Lua's 'arg' table. -- @return string CocoaDialog result. function dialog(kind, ...) end - ---- --- Calls 'dofile' on the given filename in the user's Textadept directory. --- This is typically used for loading user files like key commands or snippets. --- Errors are printed to the Textadept message buffer. --- @param filename The name of the file (not path). --- @return true if successful; false otherwise. -function user_dofile(filename) end diff --git a/core/.iconv.lua b/core/.iconv.lua new file mode 100644 index 00000000..86ca54c9 --- /dev/null +++ b/core/.iconv.lua @@ -0,0 +1,15 @@ +-- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. +-- This is a DUMMY FILE used for making LuaDoc for built-in functions in the +-- string table. + +--- Extends Lua's string package to provide character set conversions. +module('string') + +--- +-- Converts a string from one character set to another using iconv(). +-- Valid character sets are ones GLib's g_convert() accepts, typically GNU +-- iconv's character sets. +-- @param text The text to convert. +-- @param to The character set to convert to. +-- @param from The character set to convert from. +function iconv(text, to, from) end diff --git a/core/events.lua b/core/events.lua index 900ccbb3..d80857f6 100644 --- a/core/events.lua +++ b/core/events.lua @@ -1,6 +1,5 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -local textadept = _G.textadept local locale = _G.locale --- @@ -93,11 +92,9 @@ module('events', package.seeall) -- * **view\_after\_switch** ()<br /> -- Called right after [view][view] was switched to. -- * **reset\_before()**<br /> --- Called before resetting the Lua state during a call to --- [`textadept.reset()`][textadept_reset]. +-- Called before resetting the Lua state during a call to [`reset()`][reset]. -- * **reset\_after()**<br /> --- Called after resetting the Lua state during a call to --- [`textadept.reset()`][textadept_reset]. +-- 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 @@ -114,7 +111,7 @@ module('events', package.seeall) -- * **menu\_clicked** (menu\_id)<br /> -- Called when a menu item is selected. -- - menu\_id: the numeric ID of the menu item set in --- [`textadept.gtkmenu()`][textadept_gtkmenu]. +-- [`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. @@ -132,15 +129,15 @@ module('events', package.seeall) -- -- [buffer]: ../modules/buffer.html -- [view]: ../modules/view.html --- [textadept_reset]: ../modules/textadept.html#reset --- [textadept_gtkmenu]: ../modules/textadept.html#gtkmenu +-- [reset]: ../modules/_G.html#reset +-- [gui_gtkmenu]: ../modules/gui.html#gtkmenu -- -- ## Example -- -- The following Lua code generates and handles a custom `my_event` event: -- -- function my_event_handler(message) --- textadept.print(message) +-- gui.print(message) -- end -- -- events.connect('my_event', my_event_handler) @@ -187,7 +184,7 @@ local connect = connect local emit = emit --- Map of Scintilla notifications to their handlers. -local c = textadept.constants +local c = _SCINTILLA.constants local scnnotifications = { [c.SCN_CHARADDED] = { 'char_added', 'ch' }, [c.SCN_SAVEPOINTREACHED] = { 'save_point_reached' }, @@ -219,7 +216,7 @@ end connect('view_new', function() -- sets default properties for a Scintilla window local buffer = buffer - local c = textadept.constants + local c = _SCINTILLA.constants -- lexer buffer.style_bits = 8 @@ -260,7 +257,7 @@ connect('buffer_new', buffer:set_lexer_language('container') -- buffer - buffer.code_page = textadept.constants.SC_CP_UTF8 + buffer.code_page = _SCINTILLA.constants.SC_CP_UTF8 if _THEME and #_THEME > 0 then local ret, errmsg = pcall(dofile, _THEME..'/buffer.lua') @@ -282,7 +279,7 @@ local function set_title(buffer) local buffer = buffer local filename = buffer.filename or buffer._type or locale.UNTITLED local dirty = buffer.dirty and '*' or '-' - textadept.title = + gui.title = string.format('%s %s Textadept (%s)', filename:match('[^/\\]+$'), dirty, filename) end @@ -308,7 +305,7 @@ connect('uri_dropped', 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) end -- ignore leading '/' - local uri = textadept.iconv(utf8_uri, _CHARSET, 'UTF-8') + local uri = utf8_uri:iconv(_CHARSET, 'UTF-8') if lfs.attributes(uri).mode ~= 'directory' then io.open_file(utf8_uri) end @@ -332,7 +329,7 @@ connect('update_ui', local tabs = (buffer.use_tabs and locale.STATUS_TABS or locale.STATUS_SPACES)..buffer.indent local enc = buffer.encoding or '' - textadept.docstatusbar_text = + gui.docstatusbar_text = locale.DOCSTATUSBAR_TEXT:format(line, max, col, lexer, eol, tabs, enc) end) @@ -355,7 +352,7 @@ connect('buffer_before_switch', buffer._folds = {} local folds = buffer._folds local level, expanded = buffer.fold_level, buffer.fold_expanded - local header_flag = textadept.constants.SC_FOLDLEVELHEADERFLAG + local header_flag = _SCINTILLA.constants.SC_FOLDLEVELHEADERFLAG local test = 2 * header_flag for i = 0, buffer.line_count do if level[i] % test >= header_flag and not expanded[i] then @@ -393,21 +390,21 @@ connect('quit', function() -- prompts for confirmation if any buffers are dirty local any = false local list = {} - for _, buffer in ipairs(textadept.buffers) do + for _, buffer in ipairs(_BUFFERS) do if buffer.dirty then list[#list + 1] = buffer.filename or buffer._type or locale.UNTITLED any = true end end if any and - textadept.dialog('msgbox', - '--title', locale.EVENTS_QUIT_TITLE, - '--text', locale.EVENTS_QUIT_TEXT, - '--informative-text', - string.format('%s', table.concat(list, '\n')), - '--button1', 'gtk-cancel', - '--button2', locale.EVENTS_QUIT_BUTTON2, - '--no-newline') ~= '2' then + gui.dialog('msgbox', + '--title', locale.EVENTS_QUIT_TITLE, + '--text', locale.EVENTS_QUIT_TEXT, + '--informative-text', + string.format('%s', table.concat(list, '\n')), + '--button1', 'gtk-cancel', + '--button2', locale.EVENTS_QUIT_BUTTON2, + '--no-newline') ~= '2' then return false end return true @@ -420,10 +417,10 @@ if MAC then connect('buffer_new', function() buffer.paste = function() - local clipboard_text = textadept.clipboard_text + local clipboard_text = gui.clipboard_text if #clipboard_text > 0 then buffer:replace_sel(clipboard_text) end end end) end -connect('error', function(...) textadept._print(locale.ERROR_BUFFER, ...) end) +connect('error', function(...) gui._print(locale.ERROR_BUFFER, ...) end) diff --git a/core/ext/command_entry.lua b/core/ext/command_entry.lua index c29a2180..296244f4 100644 --- a/core/ext/command_entry.lua +++ b/core/ext/command_entry.lua @@ -1,19 +1,18 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -local textadept = _G.textadept local locale = _G.locale events.connect('command_entry_command', function(command) -- execute a Lua command local f, err = loadstring(command) if err then error(err) end - textadept.command_entry.focus() -- toggle focus to hide + gui.command_entry.focus() -- toggle focus to hide f() end) events.connect('command_entry_keypress', function(code) - local ce = textadept.command_entry + local ce = gui.command_entry local KEYSYMS = keys.KEYSYMS if KEYSYMS[code] == 'esc' then ce.focus() -- toggle focus to hide @@ -32,11 +31,11 @@ events.connect('command_entry_keypress', end if path == 'buffer' then if o == ':' then - for f in pairs(textadept.buffer_functions) do + for f in pairs(_SCINTILLA.functions) do if f:find('^'..prefix) then cmpls[#cmpls + 1] = f end end else - for p in pairs(textadept.buffer_properties) do + for p in pairs(_SCINTILLA.properties) do if p:find('^'..prefix) then cmpls[#cmpls + 1] = p end end end diff --git a/core/ext/find.lua b/core/ext/find.lua index 9aebaaee..eafef5ed 100644 --- a/core/ext/find.lua +++ b/core/ext/find.lua @@ -1,9 +1,8 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -local textadept = _G.textadept local locale = _G.locale local events = _G.events -local find = textadept.find +local find = gui.find local lfs = require 'lfs' @@ -41,7 +40,7 @@ local function find_(text, next, flags, nowrap, wrapped) end if not flags then - local find, c = find, textadept.constants + local find, c = find, _SCINTILLA.constants flags = 0 if find.match_case then flags = flags + c.SCFIND_MATCHCASE end if find.whole_word then flags = flags + c.SCFIND_WHOLEWORD end @@ -76,19 +75,18 @@ local function find_(text, next, flags, nowrap, wrapped) else -- find in files local utf8_dir = - textadept.dialog('fileselect', - '--title', locale.FIND_IN_FILES_TITLE, - '--select-only-directories', - '--with-directory', - (buffer.filename or ''):match('^.+[/\\]') or '', - '--no-newline') + 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 if find.whole_word then text = '[^%W_]'..text..'[^%W_]' end local match_case = find.match_case local whole_word = find.whole_word - local iconv = textadept.iconv local format = string.format local matches = { 'Find: '..text } function search_file(file) @@ -98,7 +96,7 @@ local function find_(text, next, flags, nowrap, wrapped) if not match_case then optimized_line = line:lower() end if whole_word then optimized_line = ' '..line..' ' end if string.find(optimized_line, text) then - file = iconv(file, 'UTF-8', _CHARSET) + file = file:iconv('UTF-8', _CHARSET) matches[#matches + 1] = format('%s:%s:%s', file, line_num, line) end line_num = line_num + 1 @@ -117,15 +115,14 @@ local function find_(text, next, flags, nowrap, wrapped) end end end - local dir = iconv(utf8_dir, _CHARSET, 'UTF-8') + local dir = utf8_dir:iconv(_CHARSET, 'UTF-8') search_dir(dir) if #matches == 1 then matches[2] = locale.FIND_NO_RESULTS end matches[#matches + 1] = '' if buffer._type ~= locale.FIND_FILES_FOUND_BUFFER then previous_view = view end - textadept._print(locale.FIND_FILES_FOUND_BUFFER, - table.concat(matches, '\n')) + gui._print(locale.FIND_FILES_FOUND_BUFFER, table.concat(matches, '\n')) end return end @@ -137,16 +134,16 @@ local function find_(text, next, flags, nowrap, wrapped) else buffer:goto_pos(buffer.length) end - textadept.statusbar_text = locale.FIND_SEARCH_WRAPPED + gui.statusbar_text = locale.FIND_SEARCH_WRAPPED result = find_(text, next, flags, true, true) if result == -1 then - textadept.statusbar_text = locale.FIND_NO_RESULTS + gui.statusbar_text = locale.FIND_NO_RESULTS buffer:line_scroll(0, first_visible_line) buffer:goto_pos(anchor) end return result elseif result ~= -1 and not wrapped then - textadept.statusbar_text = '' + gui.statusbar_text = '' end return result @@ -158,7 +155,7 @@ events.connect('find', find_) -- Flags other than SCFIND_MATCHCASE are ignored. -- @param text The text to find. local function find_incremental(text) - local c = textadept.constants + local c = _SCINTILLA.constants local flags = find.match_case and c.SCFIND_MATCHCASE or 0 --if find.lua then flags = flags + 8 end buffer:goto_pos(find.incremental_start or 0) @@ -169,8 +166,8 @@ end function find.find_incremental() find.incremental = true find.incremental_start = buffer.current_pos - textadept.command_entry.entry_text = '' - textadept.command_entry.focus() + gui.command_entry.entry_text = '' + gui.command_entry.focus() end events.connect('command_entry_keypress', @@ -179,7 +176,7 @@ events.connect('command_entry_keypress', if code == 0xff1b then -- escape find.incremental = nil elseif code < 256 or code == 0xff08 then -- character or backspace - local text = textadept.command_entry.entry_text + local text = gui.command_entry.entry_text if code == 0xff08 then find_incremental(text:sub(1, -2)) else @@ -222,11 +219,11 @@ local function replace(rtext) function(code) local ret, val = pcall(loadstring('return '..code)) if not ret then - textadept.dialog('ok-msgbox', - '--title', locale.FIND_ERROR_DIALOG_TITLE, - '--text', locale.FIND_ERROR_DIALOG_TEXT, - '--informative-text', val:gsub('"', '\\"'), - '--no-cancel') + gui.dialog('ok-msgbox', + '--title', locale.FIND_ERROR_DIALOG_TITLE, + '--text', locale.FIND_ERROR_DIALOG_TEXT, + '--informative-text', val:gsub('"', '\\"'), + '--no-cancel') error() end return val @@ -285,7 +282,7 @@ local function replace_all(ftext, rtext, flags) buffer:set_sel(anchor, current_pos) buffer:marker_delete_handle(end_marker) end - textadept.statusbar_text = + gui.statusbar_text = string.format(locale.FIND_REPLACEMENTS_MADE, tostring(count)) buffer:end_undo_action() end @@ -304,7 +301,7 @@ local function goto_file(pos, line_num) buffer:marker_set_back(MARK_FIND, MARK_FIND_COLOR) buffer:marker_add(line_num, MARK_FIND) buffer:goto_pos(buffer.current_pos) - if #textadept.views == 1 then + if #_VIEWS == 1 then _, previous_view = view:split(false) -- horizontal else local clicked_view = view @@ -312,7 +309,7 @@ local function goto_file(pos, line_num) if buffer._type == locale.FIND_FILES_FOUND_BUFFER then -- there are at least two find in files views; find one of those views -- that the file was not selected from and focus it - for _, v in ipairs(textadept.views) do + for _, v in ipairs(_VIEWS) do if v ~= clicked_view then previous_view = v v:focus() @@ -332,9 +329,9 @@ events.connect('double_click', goto_file) -- LuaDoc is in core/.find.lua. function find.goto_file_in_list(next) local orig_view = view - for _, buffer in ipairs(textadept.buffers) do + for _, buffer in ipairs(_BUFFERS) do if buffer._type == locale.FIND_FILES_FOUND_BUFFER then - for _, view in ipairs(textadept.views) do + for _, view in ipairs(_VIEWS) do if view.doc_pointer == buffer.doc_pointer then view:focus() local orig_line = buffer:line_from_position(buffer.current_pos) diff --git a/core/ext/key_commands.lua b/core/ext/key_commands.lua index 93f02713..310db7aa 100644 --- a/core/ext/key_commands.lua +++ b/core/ext/key_commands.lua @@ -1,6 +1,5 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -local textadept = _G.textadept local locale = _G.locale local events = _G.events @@ -34,11 +33,11 @@ module('keys', package.seeall) -- -- pressing control, shift, alt and 'a' yields: 'Ctrl+Shift+Alt+A' -- -- For key values less than 255, Lua's [`string.char()`][string_char] is used to --- determine the key's string representation. Otherwise, the `KEYSYMS` lookup --- table in [`textadept.keys`][textadept_keys] is used. +-- determine the key's string representation. Otherwise, the +-- [`KEYSYMS`][keysyms] lookup table is used. -- -- [string_char]: http://www.lua.org/manual/5.1/manual.html#pdf-string.char --- [textadept_keys]: ../modules/textadept.keys.html +-- [keysyms]: ../modules/keys.html#KEYSYMS -- -- An action table is a table consisting of either: -- @@ -127,7 +126,7 @@ local ALT = 'a'..ADD local keys = keys local b, v = 'buffer', 'view' -local t = textadept +local gui = gui -- CTRL = 'c' -- SHIFT = 's' @@ -154,16 +153,16 @@ if not MAC then -- File local m_session = _m.textadept.session - keys.cn = { t.new_buffer } - keys.co = { io.open_file } + keys.cn = { new_buffer } + keys.co = { io.open_file } -- TODO: { 'reload', b } - keys.cs = { 'save', b } - keys.cS = { 'save_as', b } - keys.cw = { 'close', b } + keys.cs = { 'save', b } + keys.cS = { 'save_as', b } + keys.cw = { 'close', b } keys.cW = { io.close_all } -- TODO: { m_session.load } after prompting with open dialog -- TODO: { m_session.save } after prompting with save dialog - keys.aq = { t.quit } + keys.aq = { quit } -- Edit local m_editing = _m.textadept.editing @@ -211,19 +210,19 @@ if not MAC then } -- Search - keys.cf = { t.find.focus } -- find/replace - keys['f3'] = { t.find.find_next } + keys.cf = { gui.find.focus } -- find/replace + keys['f3'] = { gui.find.find_next } -- Find Next is an when find pane is focused. -- Find Prev is ap when find pane is focused. -- Replace is ar when find pane is focused. - keys.cF = { t.find.find_incremental } + keys.cF = { gui.find.find_incremental } -- Find in Files is ai when find pane is focused. - -- TODO: { t.find.goto_file_in_list, true } - -- TODO: { t.find.goto_file_in_list, false } + -- TODO: { gui.find.goto_file_in_list, true } + -- TODO: { gui.find.goto_file_in_list, false } keys.cg = { m_editing.goto_line } -- Tools - keys['f2'] = { t.command_entry.focus } + keys['f2'] = { gui.command_entry.focus } -- Run local m_run = _m.textadept.run keys.cr = { m_run.run } @@ -237,7 +236,7 @@ if not MAC then keys.ai = { m_snippets.show_style } -- Buffers - keys.cb = { t.switch_buffer } + keys.cb = { gui.switch_buffer } keys['c\t'] = { 'goto_buffer', v, 1, false } keys['cs\t'] = { 'goto_buffer', v, -1, false } local function toggle_setting(setting) @@ -261,8 +260,8 @@ if not MAC then -- Views keys.cav = { - n = { t.goto_view, 1, false }, - p = { t.goto_view, -1, false }, + n = { gui.goto_view, 1, false }, + p = { gui.goto_view, -1, false }, S = { 'split', v }, -- vertical s = { 'split', v, false }, -- horizontal w = { function() view:unsplit() return true end }, @@ -311,16 +310,16 @@ else -- File local m_session = _m.textadept.session - keys.an = { t.new_buffer } - keys.ao = { io.open_file } + keys.an = { new_buffer } + keys.ao = { io.open_file } -- TODO: { 'reload', b } - keys.as = { 'save', b } - keys.aS = { 'save_as', b } - keys.aw = { 'close', b } + keys.as = { 'save', b } + keys.aS = { 'save_as', b } + keys.aw = { 'close', b } keys.aW = { io.close_all } -- TODO: { m_session.load } after prompting with open dialog -- TODO: { m_session.save } after prompting with save dialog - keys.aq = { t.quit } + keys.aq = { quit } -- Edit local m_editing = _m.textadept.editing @@ -369,23 +368,23 @@ else } -- Search - keys.af = { t.find.focus } -- find/replace - keys.ag = { t.find.find_next } - keys.aG = { t.find.find_prev } - keys.ar = { t.find.replace } - keys.ai = { t.find.find_incremental } + keys.af = { gui.find.focus } -- find/replace + keys.ag = { gui.find.find_next } + keys.aG = { gui.find.find_prev } + keys.ar = { gui.find.replace } + keys.ai = { gui.find.find_incremental } keys.aF = { function() - t.find.in_files = true - t.find.focus() + gui.find.in_files = true + gui.find.focus() end } - keys.cag = { t.find.goto_file_in_list, true } - keys.caG = { t.find.goto_file_in_list, false } + keys.cag = { gui.find.goto_file_in_list, true } + keys.caG = { gui.find.goto_file_in_list, false } keys.cg = { m_editing.goto_line } -- Tools - keys['f2'] = { t.command_entry.focus } + keys['f2'] = { gui.command_entry.focus } -- Run local m_run = _m.textadept.run keys.cr = { m_run.run } @@ -399,7 +398,7 @@ else keys.ci = { m_snippets.show_style } -- Buffers - keys.ab = { t.switch_buffer } + keys.ab = { gui.switch_buffer } keys['c\t'] = { 'goto_buffer', v, 1, false } keys['cs\t'] = { 'goto_buffer', v, -1, false } local function toggle_setting(setting) @@ -423,8 +422,8 @@ else -- Views keys.cv = { - n = { t.goto_view, 1, false }, - p = { t.goto_view, -1, false }, + n = { gui.goto_view, 1, false }, + p = { gui.goto_view, -1, false }, S = { 'split', v }, -- vertical s = { 'split', v, false }, -- horizontal w = { function() view:unsplit() return true end }, @@ -478,7 +477,7 @@ else keys.cad = { 'del_word_right', b } end -textadept.user_dofile('key_commands.lua') -- load user key commands +user_dofile('key_commands.lua') -- load user key commands -- Do not edit below this line. @@ -526,7 +525,7 @@ local keychain = {} -- Clears the current key sequence. local function clear_key_sequence() keychain = {} - textadept.statusbar_text = '' + gui.statusbar_text = '' end -- Helper function that gets commands associated with the current keychain from @@ -537,7 +536,7 @@ end local function try_get_cmd(active_table) for _, key_seq in ipairs(keychain) do active_table = active_table[key_seq] end if #active_table == 0 and next(active_table) then - textadept.statusbar_text = locale.KEYCHAIN..table.concat(keychain, ' ') + gui.statusbar_text = locale.KEYCHAIN..table.concat(keychain, ' ') error(-1, 0) else local func = active_table[1] @@ -642,7 +641,7 @@ local function keypress(code, shift, control, alt) local size = #keychain - 1 clear_key_sequence() if size > 0 then -- previously in a chain - textadept.statusbar_text = locale.KEYS_INVALID + gui.statusbar_text = locale.KEYS_INVALID return true end else diff --git a/core/ext/menu.lua b/core/ext/menu.lua index ee60bc60..60e5679c 100644 --- a/core/ext/menu.lua +++ b/core/ext/menu.lua @@ -1,17 +1,16 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -local textadept = _G.textadept local locale = _G.locale local events = _G.events --- -- Provides dynamic menus for Textadept. -- This module, like ext/key_commands, should be 'require'ed last. -module('textadept.menu', package.seeall) +module('menu', package.seeall) -local t = textadept +local gui = gui local l = locale -local gtkmenu = textadept.gtkmenu +local gtkmenu = gui.gtkmenu local SEPARATOR = 'separator' local ID = { @@ -282,7 +281,7 @@ for _, lexer in ipairs(_m.textadept.mime_types.lexers) do lexer_menu[#lexer_menu + 1] = { lexer, ID.LEXER_START + #lexer_menu } end table.insert(menubar, #menubar, gtkmenu(lexer_menu)) -- before 'Help' -t.menubar = menubar +gui.menubar = menubar local b, v = 'buffer', 'view' local m_snippets = _m.textadept.snippets @@ -327,7 +326,7 @@ end local actions = { -- File - [ID.NEW] = { t.new_buffer }, + [ID.NEW] = { new_buffer }, [ID.OPEN] = { io.open_file }, [ID.RELOAD] = { 'reload', b }, [ID.SAVE] = { 'save', b }, @@ -337,34 +336,34 @@ local actions = { [ID.LOAD_SESSION] = { function() local utf8_filename = - t.dialog('fileselect', - '--title', l.MENU_LOAD_SESSION_TITLE, - '--with-directory', - (textadept.session_file or ''):match('.+[/\\]') or '', - '--with-file', - (textadept.session_file or ''):match('[^/\\]+$') or '', - '--no-newline') + gui.dialog('fileselect', + '--title', l.MENU_LOAD_SESSION_TITLE, + '--with-directory', + (_SESSIONFILE or ''):match('.+[/\\]') or '', + '--with-file', + (_SESSIONFILE or ''):match('[^/\\]+$') or '', + '--no-newline') if #utf8_filename > 0 then - _m.textadept.session.load(t.iconv(utf8_filename, _CHARSET, 'UTF-8')) + _m.textadept.session.load(utf8_filename:iconv(_CHARSET, 'UTF-8')) end end }, [ID.SAVE_SESSION] = { function() local utf8_filename = - t.dialog('filesave', - '--title', l.MENU_SAVE_SESSION_TITLE, - '--with-directory', - (textadept.session_file or ''):match('.+[/\\]') or '', - '--with-file', - (textadept.session_file or ''):match('[^/\\]+$') or '', - '--no-newline') + gui.dialog('filesave', + '--title', l.MENU_SAVE_SESSION_TITLE, + '--with-directory', + (_SESSIONFILE or ''):match('.+[/\\]') or '', + '--with-file', + (_SESSIONFILE or ''):match('[^/\\]+$') or '', + '--no-newline') if #utf8_filename > 0 then - _m.textadept.session.save(t.iconv(utf8_filename, _CHARSET, 'UTF-8')) + _m.textadept.session.save(utf8_filename:iconv(_CHARSET, 'UTF-8')) end end }, - [ID.QUIT] = { t.quit }, + [ID.QUIT] = { quit }, -- Edit [ID.UNDO] = { 'undo', b }, [ID.REDO] = { 'redo', b }, @@ -405,23 +404,23 @@ local actions = { [ID.SELECT_IN_INDENTED_BLOCK] = { m_editing.select_indented_block }, [ID.SELECT_IN_SCOPE] = { m_editing.select_scope }, -- Tools - [ID.FIND] = { t.find.focus }, - [ID.FIND_NEXT] = { t.find.call_find_next }, - [ID.FIND_PREV] = { t.find.call_find_prev }, - [ID.FIND_AND_REPLACE] = { t.find.focus }, - [ID.REPLACE] = { t.find.call_replace }, - [ID.REPLACE_ALL] = { t.find.call_replace_all }, - [ID.FIND_INCREMENTAL] = { t.find.find_incremental }, + [ID.FIND] = { gui.find.focus }, + [ID.FIND_NEXT] = { gui.find.call_find_next }, + [ID.FIND_PREV] = { gui.find.call_find_prev }, + [ID.FIND_AND_REPLACE] = { gui.find.focus }, + [ID.REPLACE] = { gui.find.call_replace }, + [ID.REPLACE_ALL] = { gui.find.call_replace_all }, + [ID.FIND_INCREMENTAL] = { gui.find.find_incremental }, [ID.FIND_IN_FILES] = { function() - t.find.in_files = true - t.find.focus() + gui.find.in_files = true + gui.find.focus() end }, - [ID.GOTO_NEXT_FILE_FOUND] = { t.find.goto_file_in_list, true }, - [ID.GOTO_PREV_FILE_FOUND] = { t.find.goto_file_in_list, false }, + [ID.GOTO_NEXT_FILE_FOUND] = { gui.find.goto_file_in_list, true }, + [ID.GOTO_PREV_FILE_FOUND] = { gui.find.goto_file_in_list, false }, [ID.GOTO_LINE] = { m_editing.goto_line }, - [ID.FOCUS_COMMAND_ENTRY] = { t.command_entry.focus }, + [ID.FOCUS_COMMAND_ENTRY] = { gui.command_entry.focus }, [ID.RUN] = { m_run.run }, [ID.COMPILE] = { m_run.compile }, -- Tools -> Snippets @@ -452,10 +451,10 @@ local actions = { [ID.ENCODING_MACROMAN] = { set_encoding, 'MacRoman' }, [ID.ENCODING_UTF16] = { set_encoding, 'UTF-16LE' }, [ID.REFRESH_SYNTAX_HIGHLIGHTING] = { 'colourise', b, 0, -1 }, - [ID.SWITCH_BUFFER] = { t.switch_buffer }, + [ID.SWITCH_BUFFER] = { gui.switch_buffer }, -- View - [ID.NEXT_VIEW] = { t.goto_view, 1, false }, - [ID.PREV_VIEW] = { t.goto_view, -1, false }, + [ID.NEXT_VIEW] = { gui.goto_view, 1, false }, + [ID.PREV_VIEW] = { gui.goto_view, -1, false }, [ID.SPLIT_VIEW_VERTICAL] = { 'split', v }, [ID.SPLIT_VIEW_HORIZONTAL] = { 'split', v, false }, [ID.UNSPLIT_VIEW] = { function() view:unsplit() end }, @@ -470,8 +469,8 @@ local actions = { [ID.MANUAL] = { open_webpage, _HOME..'/doc/manual/1_Introduction.html' }, [ID.LUADOC] = { open_webpage, _HOME..'/doc/index.html' }, [ID.ABOUT] = { - t.dialog, 'ok-msgbox', '--title', 'Textadept', '--informative-text', - _RELEASE, '--no-cancel' + gui.dialog, 'ok-msgbox', '--title', 'Textadept', '--informative-text', + _RELEASE, '--no-cancel' }, } @@ -506,7 +505,7 @@ events.connect('menu_clicked', end) -- Right-click context menu. -t.context_menu = gtkmenu { +gui.context_menu = gtkmenu { { l.MENU_EDIT_UNDO, ID.UNDO }, { l.MENU_EDIT_REDO, ID.REDO }, { SEPARATOR, ID.SEPARATOR }, diff --git a/core/file_io.lua b/core/file_io.lua index a994b34a..856959d4 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -1,6 +1,5 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -local textadept = _G.textadept local locale = _G.locale local events = _G.events @@ -26,20 +25,20 @@ module('io', package.seeall) -- If your filesystem does not use UTF-8 encoded filenames, conversions to and -- from that encoding will be necessary. When opening and saving files through -- dialogs, Textadept takes care of these conversions for you, but if you need --- to do them manually, use [`textadept.iconv()`][textadept_iconv] along with +-- to do them manually, use [`string.iconv()`][string_iconv] along with -- `_CHARSET`, your filesystem's detected encoding. -- -- Example: -- -- events.connect('file_opened', -- function(utf8_filename) --- local filename = textadept.iconv(utf8_filename, _CHARSET, 'UTF-8') +-- local filename = utf8_filename:iconv(_CHARSET, 'UTF-8') -- local f = io.open(filename, 'rb') -- -- process file -- f:close() -- end) -- --- [textadept_iconv]: ../modules/textadept.html#iconv +-- [string_iconv]: ../modules/string.html#iconv -- -- ## Events -- @@ -77,7 +76,7 @@ boms = { -- Attempt to detect the encoding of the given text. -- @param text Text to determine encoding from. --- @return encoding string for textadept.iconv() (unless 'binary', indicating a +-- @return encoding string for string.iconv() (unless 'binary', indicating a -- binary file), byte-order mark (BOM) string or nil. If encoding string is -- nil, no encoding has been detected. local function detect_encoding(text) @@ -116,7 +115,7 @@ try_encodings = { local function open_helper(utf8_filename) if not utf8_filename then return end utf8_filename = utf8_filename:gsub('^file://', '') - for index, buffer in ipairs(textadept.buffers) do + for index, buffer in ipairs(_BUFFERS) do if utf8_filename == buffer.filename then view:goto_buffer(index) return @@ -124,25 +123,25 @@ local function open_helper(utf8_filename) end local text - local filename = textadept.iconv(utf8_filename, _CHARSET, 'UTF-8') + local filename = utf8_filename:iconv(_CHARSET, 'UTF-8') local f = 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 end - local buffer = textadept.new_buffer() + 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 = textadept.iconv(text, 'UTF-8', encoding) + text = text:iconv('UTF-8', encoding) else -- Try list of encodings. for _, try_encoding in ipairs(try_encodings) do - local ret, conv = pcall(textadept.iconv, text, 'UTF-8', try_encoding) + local ret, conv = pcall(string.iconv, text, 'UTF-8', try_encoding) if ret then encoding = try_encoding text = conv @@ -154,7 +153,7 @@ local function open_helper(utf8_filename) else encoding = nil end - local c = textadept.constants + 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. @@ -191,28 +190,28 @@ end function open_file(utf8_filenames) utf8_filenames = utf8_filenames or - textadept.dialog('fileselect', - '--title', locale.IO_OPEN_TITLE, - '--select-multiple', - '--with-directory', - (buffer.filename or ''):match('.+[/\\]') or '') + gui.dialog('fileselect', + '--title', locale.IO_OPEN_TITLE, + '--select-multiple', + '--with-directory', + (buffer.filename or ''):match('.+[/\\]') or '') for filename in utf8_filenames:gmatch('[^\n]+') do open_helper(filename) end end -- LuaDoc is in core/.buffer.lua. local function reload(buffer) - textadept.check_focused_buffer(buffer) + gui.check_focused_buffer(buffer) if not buffer.filename then return end local pos = buffer.current_pos local first_visible_line = buffer.first_visible_line - local filename = textadept.iconv(buffer.filename, _CHARSET, 'UTF-8') + local filename = buffer.filename:iconv(_CHARSET, 'UTF-8') local f, err = io.open(filename, 'rb') if not f then return end local text = f:read('*all') f:close() local encoding, encoding_bom = buffer.encoding, buffer.encoding_bom if encoding_bom then text = text:sub(#encoding_bom + 1, -1) end - if encoding then text = textadept.iconv(text, 'UTF-8', encoding) end + if encoding then text = text:iconv('UTF-8', encoding) end buffer:clear_all() buffer:add_text(text, #text) buffer:line_scroll(0, first_visible_line) @@ -223,15 +222,14 @@ end -- LuaDoc is in core/.buffer.lua. local function set_encoding(buffer, encoding) - textadept.check_focused_buffer(buffer) + gui.check_focused_buffer(buffer) if not buffer.encoding then error('Cannot change binary file encoding') end - local iconv = textadept.iconv local pos = buffer.current_pos local first_visible_line = buffer.first_visible_line local text = buffer:get_text(buffer.length) - text = iconv(text, buffer.encoding, 'UTF-8') - text = iconv(text, encoding, buffer.encoding) - text = iconv(text, 'UTF-8', encoding) + text = text:iconv(buffer.encoding, 'UTF-8') + text = text:iconv(encoding, buffer.encoding) + text = text:iconv('UTF-8', encoding) buffer:clear_all() buffer:add_text(text, #text) buffer:line_scroll(0, first_visible_line) @@ -241,15 +239,15 @@ end -- LuaDoc is in core/.buffer.lua. local function save(buffer) - textadept.check_focused_buffer(buffer) + gui.check_focused_buffer(buffer) if not buffer.filename then return buffer:save_as() end events.emit('file_before_save', buffer.filename) local text = buffer:get_text(buffer.length) if buffer.encoding then local bom = buffer.encoding_bom or '' - text = bom..textadept.iconv(text, buffer.encoding, 'UTF-8') + text = bom..text:iconv(buffer.encoding, 'UTF-8') end - local filename = textadept.iconv(buffer.filename, _CHARSET, 'UTF-8') + local filename = buffer.filename:iconv(_CHARSET, 'UTF-8') local f, err = io.open(filename, 'wb') if f then f:write(text) @@ -264,16 +262,16 @@ end -- LuaDoc is in core/.buffer.lua. local function save_as(buffer, utf8_filename) - textadept.check_focused_buffer(buffer) + gui.check_focused_buffer(buffer) if not utf8_filename then utf8_filename = - textadept.dialog('filesave', - '--title', locale.IO_SAVE_TITLE, - '--with-directory', - (buffer.filename or ''):match('.+[/\\]') or '', - '--with-file', - (buffer.filename or ''):match('[^/\\]+$') or '', - '--no-newline') + gui.dialog('filesave', + '--title', locale.IO_SAVE_TITLE, + '--with-directory', + (buffer.filename or ''):match('.+[/\\]') or '', + '--with-file', + (buffer.filename or ''):match('[^/\\]+$') or '', + '--no-newline') end if #utf8_filename > 0 then buffer.filename = utf8_filename @@ -288,7 +286,7 @@ end function save_all() local current_buffer = buffer local current_index - for index, buffer in ipairs(textadept.buffers) do + for index, buffer in ipairs(_BUFFERS) do view:goto_buffer(index) if buffer == current_buffer then current_index = index end if buffer.filename and buffer.dirty then buffer:save() end @@ -298,17 +296,17 @@ end -- LuaDoc is in core/.buffer.lua. local function close(buffer) - textadept.check_focused_buffer(buffer) + gui.check_focused_buffer(buffer) if buffer.dirty and - textadept.dialog('msgbox', - '--title', locale.IO_CLOSE_TITLE, - '--text', locale.IO_CLOSE_TEXT, - '--informative-text', - string.format('%s', (buffer.filename or - buffer._type or locale.UNTITLED)), - '--button1', 'gtk-cancel', - '--button2', locale.IO_CLOSE_BUTTON2, - '--no-newline') ~= '2' then + gui.dialog('msgbox', + '--title', locale.IO_CLOSE_TITLE, + '--text', locale.IO_CLOSE_TEXT, + '--informative-text', + string.format('%s', (buffer.filename or + buffer._type or locale.UNTITLED)), + '--button1', 'gtk-cancel', + '--button2', locale.IO_CLOSE_BUTTON2, + '--no-newline') ~= '2' then return false end buffer:delete() @@ -322,8 +320,8 @@ end -- @usage io.close_all() -- @return true if user did not cancel. function close_all() - while #textadept.buffers > 1 do - view:goto_buffer(#textadept.buffers) + while #_BUFFERS > 1 do + view:goto_buffer(#_BUFFERS) if not buffer:close() then return false end end buffer:close() -- the last one @@ -335,17 +333,17 @@ end local function update_modified_file() if not buffer.filename then return end local utf8_filename = buffer.filename - local filename = textadept.iconv(utf8_filename, _CHARSET, 'UTF-8') + local filename = utf8_filename:iconv(_CHARSET, 'UTF-8') local attributes = lfs.attributes(filename) if not attributes then return end if buffer.modification_time < attributes.modification then - if textadept.dialog('yesno-msgbox', - '--title', locale.IO_RELOAD_TITLE, - '--text', locale.IO_RELOAD_TEXT, - '--informative-text', - string.format(locale.IO_RELOAD_MSG, utf8_filename), - '--no-cancel', - '--no-newline') == '1' then + if gui.dialog('yesno-msgbox', + '--title', locale.IO_RELOAD_TITLE, + '--text', locale.IO_RELOAD_TEXT, + '--informative-text', + string.format(locale.IO_RELOAD_MSG, utf8_filename), + '--no-cancel', + '--no-newline') == '1' then buffer:reload() else buffer.modification_time = attributes.modification @@ -368,8 +366,8 @@ events.connect('buffer_new', events.connect('file_opened', function(utf8_filename) -- close initial 'Untitled' buffer - local b = textadept.buffers[1] - if #textadept.buffers == 2 and not (b.filename or b._type or b.dirty) then + local b = _BUFFERS[1] + if #_BUFFERS == 2 and not (b.filename or b._type or b.dirty) then view:goto_buffer(1, true) buffer:close() end diff --git a/core/gui.lua b/core/gui.lua new file mode 100644 index 00000000..e317ecd6 --- /dev/null +++ b/core/gui.lua @@ -0,0 +1,72 @@ +-- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. + +local gui = _G.gui + +-- LuaDoc is in core/.gui.lua. +function gui.check_focused_buffer(buffer) + if type(buffer) ~= 'table' or not buffer.doc_pointer then + error(locale.ERR_BUFFER_EXPECTED, 2) + elseif gui.focused_doc_pointer ~= buffer.doc_pointer then + error(locale.ERR_BUFFER_NOT_FOCUSED, 2) + end +end + +-- LuaDoc is in core/.gui.lua. +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 + if buffer._type == buffer_type then + message_buffer, message_buffer_index = buffer, index + for jndex, view in ipairs(_VIEWS) do + if view.doc_pointer == message_buffer.doc_pointer then + message_view, message_view_index = view, jndex + break + end + end + break + end + end + if not message_view then + local _, message_view = view:split(false) -- horizontal split + if not message_buffer then + message_buffer = new_buffer() + message_buffer._type = buffer_type + events.emit('file_opened') + else + message_view:goto_buffer(message_buffer_index, true) + end + else + gui.goto_view(message_view_index, true) + end + message_buffer:append_text(message..'\n') + message_buffer:set_save_point() + end + pcall(safe_print, ...) -- prevent endless loops if this errors +end + +-- LuaDoc is in core/.gui.lua. +function gui.print(...) gui._print(locale.MESSAGE_BUFFER, ...) end + +-- LuaDoc is in core/.gui.lua. +function gui.switch_buffer() + local items = {} + for _, buffer in ipairs(_BUFFERS) do + local filename = buffer.filename or buffer._type or locale.UNTITLED + local dirty = buffer.dirty and '*' or '' + items[#items + 1] = dirty..filename:match('[^/\\]+$') + items[#items + 1] = filename + end + local out = + gui.dialog('filteredlist', + '--title', locale.SWITCH_BUFFERS, + '--button1', 'gtk-ok', + '--button2', 'gtk-cancel', + '--no-newline', + '--columns', 'Name', 'File', + '--items', unpack(items)) + local i = tonumber(out:match('%-?%d+$')) + if i and i >= 0 then view:goto_buffer(i + 1, true) end +end diff --git a/core/iface.lua b/core/iface.lua index 046ceb14..954aca04 100644 --- a/core/iface.lua +++ b/core/iface.lua @@ -1,4 +1,15 @@ -local constants = { +-- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. + +--- +-- Scintilla constants, functions, and properties. +-- Do not modify anything in this module. Doing so will result in instability. +module('_SCINTILLA', package.seeall) + +--- +-- Scintilla constants. +-- @class table +-- @name constants +constants = { ANNOTATION_BOXED = 2, ANNOTATION_HIDDEN = 0, ANNOTATION_STANDARD = 1, @@ -562,9 +573,12 @@ local constants = { SCN_INDICATORCLICK = 2023, SCN_INDICATORRELEASE = 2024, } -rawset(textadept, 'constants', constants) -local buffer_functions = { +--- +-- Scintilla functions. +-- @class table +-- @name functions +functions = { add_ref_document = {2376, 0, 0, 1}, add_selection = {2573, 1, 1, 1}, add_styled_text = {2002, 0, 2, 9}, @@ -831,9 +845,12 @@ local buffer_functions = { zoom_in = {2333, 0, 0, 0}, zoom_out = {2334, 0, 0, 0}, } -rawset(textadept, 'buffer_functions', buffer_functions) -local buffer_properties = { +--- +-- Scintilla properties. +-- @class table +-- @name properties +properties = { additional_caret_fore = {2605, 2604, 4, 0}, additional_carets_blink = {2568, 2567, 5, 0}, additional_carets_visible = {2609, 2608, 5, 0}, @@ -1004,4 +1021,3 @@ local buffer_properties = { x_offset = {2398, 2397, 1, 0}, zoom = {2374, 2373, 1, 0}, } -rawset(textadept, 'buffer_properties', buffer_properties) diff --git a/core/init.lua b/core/init.lua index fcf8e354..39497614 100644 --- a/core/init.lua +++ b/core/init.lua @@ -2,8 +2,6 @@ _RELEASE = "Textadept 2.2" -local textadept = _G.textadept - package.path = _HOME..'/core/?.lua;'..package.path _USERHOME = os.getenv(not WIN32 and 'HOME' or 'USERPROFILE')..'/.textadept' @@ -29,83 +27,15 @@ require 'iface' require 'locale' require 'events' require 'file_io' +require 'gui' rawset = nil -- do not allow modifications which could compromise stability --- LuaDoc is in core/.textadept.lua. -function textadept.check_focused_buffer(buffer) - if type(buffer) ~= 'table' or not buffer.doc_pointer then - error(locale.ERR_BUFFER_EXPECTED, 2) - elseif textadept.focused_doc_pointer ~= buffer.doc_pointer then - error(locale.ERR_BUFFER_NOT_FOCUSED, 2) - end -end - --- LuaDoc is in core/.textadept.lua. -function textadept._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(textadept.buffers) do - if buffer._type == buffer_type then - message_buffer, message_buffer_index = buffer, index - for jndex, view in ipairs(textadept.views) do - if view.doc_pointer == message_buffer.doc_pointer then - message_view, message_view_index = view, jndex - break - end - end - break - end - end - if not message_view then - local _, message_view = view:split(false) -- horizontal split - if not message_buffer then - message_buffer = textadept.new_buffer() - message_buffer._type = buffer_type - events.emit('file_opened') - else - message_view:goto_buffer(message_buffer_index, true) - end - else - textadept.goto_view(message_view_index, true) - end - message_buffer:append_text(message..'\n') - message_buffer:set_save_point() - end - pcall(safe_print, ...) -- prevent endless loops if this errors -end - --- LuaDoc is in core/.textadept.lua. -function textadept.print(...) textadept._print(locale.MESSAGE_BUFFER, ...) end - --- LuaDoc is in core/.textadept.lua. -function textadept.switch_buffer() - local items = {} - for _, buffer in ipairs(textadept.buffers) do - local filename = buffer.filename or buffer._type or locale.UNTITLED - local dirty = buffer.dirty and '*' or '' - items[#items + 1] = dirty..filename:match('[^/\\]+$') - items[#items + 1] = filename - end - local out = - textadept.dialog('filteredlist', - '--title', locale.SWITCH_BUFFERS, - '--button1', 'gtk-ok', - '--button2', 'gtk-cancel', - '--no-newline', - '--columns', 'Name', 'File', - '--items', unpack(items)) - local i = tonumber(out:match('%-?%d+$')) - if i and i >= 0 then view:goto_buffer(i + 1, true) end -end - --- LuaDoc is in core/.textadept.lua. -function textadept.user_dofile(filename) +-- LuaDoc is in core/._G.lua. +function _G.user_dofile(filename) if lfs.attributes(_USERHOME..'/'..filename) then local ret, errmsg = pcall(dofile, _USERHOME..'/'..filename) - if not ret then textadept.print(errmsg) end + if not ret then gui.print(errmsg) end return ret end return false diff --git a/doc/manual/7_LuaInterface.md b/doc/manual/7_LuaInterface.md index f99691e4..2b8c7693 100644 --- a/doc/manual/7_LuaInterface.md +++ b/doc/manual/7_LuaInterface.md @@ -8,26 +8,3 @@ but documentation for all of its modules and features as well. It is more up to date than a manual like this could ever be. [LuaDoc]: ../index.html - -## Global Variables - -The following global variables not mentioned in the LuaDoc are available in -Textadept's Lua state: - -* `_HOME`: Path to the directory containing Textadept. -* `_LEXERPATH`: Paths to lexers, formatted like [`package.path`][package_path]. -* `_RELEASE`: The Textadept release version. -* `_THEME`: The [theme][theme] file to use. -* `_USERHOME`: Path to the user's `~/.textadept/`. -* `MAC`: If Textadept is running on Mac OSX, this flag is `true`. -* `_CHARSET`: The character set encoding of the filesystem. This is used in - [File I/O][file_io]. -* `RESETTING`: If [`textadept.reset()`][textadept_reset] has been called, this - flag is `true` while the Lua state is being re-initialized. -* `WIN32`: If Textadept is running on Windows, this flag is `true`. -* `arg`: Table containing the command line arguments passed to Textadept. - -[package_path]: http://www.lua.org/manual/5.1/manual.html#pdf-package.path -[theme]: 6_Startup.html -[file_io]: ../modules/io.html -[textadept_reset]: ../modules/textadept.html#reset @@ -1,7 +1,5 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -local textadept = _G.textadept - local paths = { _USERHOME..'/?.lua', _USERHOME..'/modules/?.lua', @@ -12,7 +10,7 @@ local paths = { } package.path = table.concat(paths, ';') -if not textadept.user_dofile('init.lua') then +if not user_dofile('init.lua') then -- Core extension modules to load on startup. require 'ext/find' -- provides functionality for find/replace require 'ext/command_entry' -- provides tab-completion for the command entry diff --git a/modules/cpp/commands.lua b/modules/cpp/commands.lua index 65f67ff4..2348ad41 100644 --- a/modules/cpp/commands.lua +++ b/modules/cpp/commands.lua @@ -1,7 +1,5 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -local textadept = _G.textadept - --- -- Commands for the cpp module. module('_m.cpp.commands', package.seeall) @@ -27,8 +25,7 @@ if type(keys) == 'table' then keys.cpp = { al = { m = { io.open_file, - textadept.iconv(_HOME..'/modules/cpp/init.lua', - 'UTF-8', _CHARSET) }, + (_HOME..'/modules/cpp/init.lua'):iconv('UTF-8', _CHARSET) }, }, ['s\n'] = { function() buffer:line_end() diff --git a/modules/lua/commands.lua b/modules/lua/commands.lua index 5f544ae0..0489ea56 100644 --- a/modules/lua/commands.lua +++ b/modules/lua/commands.lua @@ -1,7 +1,5 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -local textadept = _G.textadept - --- -- Commands for the lua module. module('_m.lua.commands', package.seeall) @@ -69,7 +67,7 @@ function goto_required() for path in package.path:gmatch('[^;]+') do path = path:gsub('?', file) if lfs.attributes(path) then - io.open_file(textadept.iconv(path, 'UTF-8', _CHARSET)) + io.open_file(path:iconv('UTF-8', _CHARSET)) break end end @@ -81,8 +79,7 @@ if type(keys) == 'table' then keys.lua = { al = { m = { io.open_file, - textadept.iconv(_HOME..'/modules/lua/init.lua', - 'UTF-8', _CHARSET) }, + (_HOME..'/modules/lua/init.lua'):iconv('UTF-8', _CHARSET) }, g = { goto_required }, }, ['s\n'] = { try_to_autocomplete_end }, diff --git a/modules/textadept/bookmarks.lua b/modules/textadept/bookmarks.lua index 2b95df1d..581390d4 100644 --- a/modules/textadept/bookmarks.lua +++ b/modules/textadept/bookmarks.lua @@ -1,6 +1,5 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -local textadept = _G.textadept local locale = _G.locale --- diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index 2d1586a2..6c8cd680 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -1,6 +1,5 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -local textadept = _G.textadept local locale = _G.locale local events = _G.events @@ -227,10 +226,10 @@ function goto_line(line) local buffer = buffer if not line then line = - textadept.dialog('standard-inputbox', - '--title', locale.M_TEXTADEPT_EDITING_GOTO_TITLE, - '--text', locale.M_TEXTADEPT_EDITING_GOTO_TEXT, - '--no-newline') + 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/mime_types.lua b/modules/textadept/mime_types.lua index f3265b53..96f56216 100644 --- a/modules/textadept/mime_types.lua +++ b/modules/textadept/mime_types.lua @@ -1,6 +1,5 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -local textadept = _G.textadept local locale = _G.locale local events = _G.events @@ -26,8 +25,8 @@ module('_m.textadept.mime_types', package.seeall) -- -- ## Configuration Files -- --- Built-in mime-types are located in `core/ext/mime_types.conf`. You can --- override or add to them in your `~/.textadept/mime_types.conf`. +-- Built-in mime-types are located in `modules/textadept/mime_types.conf`. You +-- can override or add to them in your `~/.textadept/mime_types.conf`. -- -- #### Detection by File Extension -- @@ -253,14 +252,14 @@ events.connect('reset_after', function() buffer:set_lexer(buffer._lexer) end) -- buffer. function select_lexer() local out = - textadept.dialog('filteredlist', - '--title', locale.MT_SELECT_LEXER, - '--button1', 'gtk-ok', - '--button2', 'gtk-cancel', - '--no-newline', - '--string-output', - '--columns', 'Name', - '--items', unpack(lexers)) + gui.dialog('filteredlist', + '--title', locale.MT_SELECT_LEXER, + '--button1', 'gtk-ok', + '--button2', 'gtk-cancel', + '--no-newline', + '--string-output', + '--columns', 'Name', + '--items', unpack(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/run.lua b/modules/textadept/run.lua index a576ff27..78b1fbdb 100644 --- a/modules/textadept/run.lua +++ b/modules/textadept/run.lua @@ -1,6 +1,5 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -local textadept = _G.textadept local locale = _G.locale --- @@ -19,7 +18,7 @@ module('_m.textadept.run', package.seeall) -- * %(filename) The name of the file including extension. -- * %(filename_noext) The name of the file excluding extension. function execute(command) - local filepath = textadept.iconv(buffer.filename, _CHARSET, 'UTF-8') + local filepath = buffer.filename:iconv(_CHARSET, 'UTF-8') local filedir, filename if filepath:find('[/\\]') then filedir, filename = filepath:match('^(.+[/\\])([^/\\]+)$') @@ -39,7 +38,7 @@ function execute(command) local out = p:read('*all') p:close() lfs.chdir(current_dir) - textadept.print(textadept.iconv('> '..command..'\n'..out, 'UTF-8', _CHARSET)) + gui.print(('> '..command..'\n'..out):iconv('UTF-8', _CHARSET)) buffer:goto_pos(buffer.length) end @@ -115,7 +114,7 @@ function goto_error(pos, line_num) if #captures > 0 then local lfs = require 'lfs' local utf8_filename = captures[error_detail.filename] - local filename = textadept.iconv(utf8_filename, _CHARSET, 'UTF-8') + local filename = utf8_filename:iconv(_CHARSET, 'UTF-8') if lfs.attributes(filename) then io.open_file(utf8_filename) _m.textadept.editing.goto_line(captures[error_detail.line]) diff --git a/modules/textadept/session.lua b/modules/textadept/session.lua index 3535bca1..22f19c11 100644 --- a/modules/textadept/session.lua +++ b/modules/textadept/session.lua @@ -1,6 +1,5 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -local textadept = _G.textadept local locale = _G.locale --- @@ -49,7 +48,7 @@ function load(filename) not_found[#not_found + 1] = filename end else - textadept.new_buffer() + new_buffer() buffer._type = filename events.handle('file_opened', filename) end @@ -73,7 +72,7 @@ function load(filename) local level, num, buf_idx = line:match('^(%s*)view(%d): (%d+)$') local view = splits[#level][tonumber(num)] or view buf_idx = tonumber(buf_idx) - if buf_idx > #textadept.buffers then buf_idx = #textadept.buffers end + if buf_idx > #_BUFFERS then buf_idx = #_BUFFERS end view:goto_buffer(buf_idx) elseif line:find('^current_view:') then local view_idx = line:match('^current_view: (%d+)') @@ -81,18 +80,18 @@ function load(filename) end if line:find('^size:') then local width, height = line:match('^size: (%d+) (%d+)$') - if width and height then textadept.size = { width, height } end + if width and height then gui.size = { width, height } end end end f:close() - textadept.views[current_view]:focus() - textadept.session_file = filename or DEFAULT_SESSION + _VIEWS[current_view]:focus() + _SESSIONFILE = filename or DEFAULT_SESSION if #not_found > 0 then - textadept.dialog('msgbox', - '--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'))) + gui.dialog('msgbox', + '--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'))) end return true end @@ -110,10 +109,10 @@ function save(filename) local split_line = "%ssplit%d: %s %d" -- level, number, type, size local view_line = "%sview%d: %d" -- level, number, doc index -- Write out opened buffers. - for _, buffer in ipairs(textadept.buffers) do + for _, buffer in ipairs(_BUFFERS) do local filename = buffer.filename or buffer._type if filename then - local current = buffer.doc_pointer == textadept.focused_doc_pointer + 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 = @@ -141,7 +140,7 @@ function save(filename) session[#session + 1] = view_line:format(spaces, 2, c2) end end - local splits = textadept.get_split_table() + local splits = gui.get_split_table() if type(splits) == 'table' then write_split(splits, 0, 0) else @@ -149,7 +148,7 @@ function save(filename) end -- Write out the current focused view. local current_view = view - for index, view in ipairs(textadept.views) do + for index, view in ipairs(_VIEWS) do if view == current_view then current_view = index break @@ -157,11 +156,11 @@ function save(filename) end session[#session + 1] = ("current_view: %d"):format(current_view) -- Write out other things. - local size = textadept.size + local size = gui.size session[#session + 1] = ("size: %d %d"):format(size[1], size[2]) -- Write the session. local f = - io.open_file(filename or textadept.session_file or DEFAULT_SESSION, 'wb') + io.open_file(filename or _SESSIONFILE or DEFAULT_SESSION, 'wb') if f then f:write(table.concat(session, '\n')) f:close() diff --git a/modules/textadept/snippets.lua b/modules/textadept/snippets.lua index 07ab0c8f..cb79987b 100644 --- a/modules/textadept/snippets.lua +++ b/modules/textadept/snippets.lua @@ -1,6 +1,5 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -local textadept = _G.textadept local locale = _G.locale --- @@ -477,4 +476,4 @@ function show_style() buffer:call_tip_show(buffer.current_pos, text) end -textadept.user_dofile('snippets.lua') -- load user snippets +user_dofile('snippets.lua') -- load user snippets diff --git a/scripts/gen_iface.lua b/scripts/gen_iface.lua index aa5f8c33..917ffeae 100755 --- a/scripts/gen_iface.lua +++ b/scripts/gen_iface.lua @@ -9,7 +9,15 @@ local constants = contents:match('ifaceConstants%[%] = (%b{})') local functions = contents:match('ifaceFunctions%[%] = (%b{})') local properties = contents:match('ifaceProperties%[%] = (%b{})') -local out = '' +local out = [[ +-- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. + +--- +-- Scintilla constants, functions, and properties. +-- Do not modify anything in this module. Doing so will result in instability. +module('_SCINTILLA', package.seeall) + +]] local types = { void = 0, int = 1, length = 2, position = 3, colour = 4, bool = 5, @@ -17,7 +25,13 @@ local types = { findtext = 11, formatrange = 12 } -out = out..'local constants = {\n' +out = out..[[ +--- +-- Scintilla constants. +-- @class table +-- @name constants +constants = { +]] -- {"constant", value} for item in constants:sub(2, -2):gmatch('%b{}') do local name, value = item:match('^{"(.-)",(.-)}') @@ -53,9 +67,15 @@ out = out..[[ SCN_INDICATORCLICK = 2023, SCN_INDICATORRELEASE = 2024, ]] -out = out..'}\nrawset(textadept, \'constants\', constants)\n\n' +out = out..'}\n\n' -out = out..'local buffer_functions = {\n' +out = out..[[ +--- +-- Scintilla functions. +-- @class table +-- @name functions +functions = { +]] -- {"function", msg_id, iface_*, {iface_*, iface_*}} for item in functions:sub(2, -2):gmatch('%b{}') do local name, msg_id, rt_type, p1_type, p2_type = @@ -67,9 +87,15 @@ for item in functions:sub(2, -2):gmatch('%b{}') do name, msg_id, types[rt_type], types[p1_type], types[p2_type]) out = out..line end -out = out..'}\nrawset(textadept, \'buffer_functions\', buffer_functions)\n\n' +out = out..'}\n\n' -out = out..'local buffer_properties = {\n' +out = out..[[ +--- +-- Scintilla properties. +-- @class table +-- @name properties +properties = { +]] -- {"property", get_id, set_id, rt_type, p1_type} for item in properties:sub(2, -2):gmatch('%b{}') do local name, get_id, set_id, rt_type, p1_type = @@ -81,7 +107,7 @@ for item in properties:sub(2, -2):gmatch('%b{}') do name, get_id, set_id, types[rt_type], types[p1_type]) out = out..line end -out = out..'}\nrawset(textadept, \'buffer_properties\', buffer_properties)\n' +out = out..'}\n' f = io.open('../core/iface.lua', 'w') f:write(out) diff --git a/src/lua_interface.c b/src/lua_interface.c index c3bf55b6..0003d702 100644 --- a/src/lua_interface.c +++ b/src/lua_interface.c @@ -13,9 +13,6 @@ lua_pushstring(l, k); \ lua_rawget(l, -2); \ lua_setfield(l, LUA_REGISTRYINDEX, k); \ - lua_pushstring(l, k); \ - lua_pushnil(l); \ - lua_rawset(l, -3); \ } #define l_togtkwidget(l, i) (GtkWidget *)lua_touserdata(l, i) #define l_mt(l, k, i, ni) { \ @@ -41,17 +38,17 @@ static void warn(const char *s) { static int l_buffer_mt_index(lua_State *), l_buffer_mt_newindex(lua_State *), l_bufferp_mt_index(lua_State *), l_bufferp_mt_newindex(lua_State *), l_view_mt_index(lua_State *), l_view_mt_newindex(lua_State *), - l_ta_mt_index(lua_State *), l_ta_mt_newindex(lua_State *), + l_gui_mt_index(lua_State *), l_gui_mt_newindex(lua_State *), l_find_mt_index(lua_State *), l_find_mt_newindex(lua_State *), l_ce_mt_index(lua_State *), l_ce_mt_newindex(lua_State *); static int l_cf_buffer_delete(lua_State *), l_cf_buffer_text_range(lua_State *), l_cf_view_focus(lua_State *), l_cf_view_split(lua_State *), - l_cf_view_unsplit(lua_State *), l_cf_ta_buffer_new(lua_State *), - l_cf_ta_dialog(lua_State *), l_cf_ta_get_split_table(lua_State *), - l_cf_ta_goto_window(lua_State *), l_cf_view_goto_buffer(lua_State *), - l_cf_ta_gtkmenu(lua_State *), l_cf_ta_iconv(lua_State *), - l_cf_ta_reset(lua_State *), l_cf_ta_quit(lua_State *), + l_cf_view_unsplit(lua_State *), l_cf_buffer_new(lua_State *), + l_cf_gui_dialog(lua_State *), l_cf_gui_get_split_table(lua_State *), + l_cf_gui_goto_view(lua_State *), l_cf_view_goto_buffer(lua_State *), + l_cf_gui_gtkmenu(lua_State *), l_cf_string_iconv(lua_State *), + l_cf_reset(lua_State *), l_cf_quit(lua_State *), l_cf_find_focus(lua_State *), l_cf_find_next(lua_State *), l_cf_find_prev(lua_State *), l_cf_find_replace(lua_State *), l_cf_find_replace_all(lua_State *), l_cf_ce_focus(lua_State *), @@ -101,19 +98,29 @@ int l_init(int argc, char **argv, int reinit) { l_cfunc(lua, l_cf_ce_show_completions, "show_completions"); l_mt(lua, "_ce_mt", l_ce_mt_index, l_ce_mt_newindex); lua_setfield(lua, -2, "command_entry"); - l_cfunc(lua, l_cf_ta_dialog, "dialog"); - l_cfunc(lua, l_cf_ta_get_split_table, "get_split_table"); - l_cfunc(lua, l_cf_ta_goto_window, "goto_view"); - l_cfunc(lua, l_cf_ta_gtkmenu, "gtkmenu"); - l_cfunc(lua, l_cf_ta_iconv, "iconv"); - l_cfunc(lua, l_cf_ta_buffer_new, "new_buffer"); - l_cfunc(lua, l_cf_ta_quit, "quit"); - l_cfunc(lua, l_cf_ta_reset, "reset"); - l_mt(lua, "_textadept_mt", l_ta_mt_index, l_ta_mt_newindex); - lua_setglobal(lua, "textadept"); + l_cfunc(lua, l_cf_gui_dialog, "dialog"); + l_cfunc(lua, l_cf_gui_get_split_table, "get_split_table"); + l_cfunc(lua, l_cf_gui_goto_view, "goto_view"); + l_cfunc(lua, l_cf_gui_gtkmenu, "gtkmenu"); + l_mt(lua, "_gui_mt", l_gui_mt_index, l_gui_mt_newindex); + lua_setglobal(lua, "gui"); + + lua_getglobal(lua, "_G"); + l_cfunc(lua, l_cf_buffer_new, "new_buffer"); + l_cfunc(lua, l_cf_quit, "quit"); + l_cfunc(lua, l_cf_reset, "reset"); + lua_pop(lua, 1); // _G + + lua_getglobal(lua, "string"); + l_cfunc(lua, l_cf_string_iconv, "iconv"); + lua_pop(lua, 1); // string lua_getfield(lua, LUA_REGISTRYINDEX, "arg"); lua_setglobal(lua, "arg"); + lua_getfield(lua, LUA_REGISTRYINDEX, "buffers"); + lua_setglobal(lua, "_BUFFERS"); + lua_getfield(lua, LUA_REGISTRYINDEX, "views"); + lua_setglobal(lua, "_VIEWS"); lua_pushstring(lua, textadept_home); lua_setglobal(lua, "_HOME"); #if __WIN32__ @@ -129,11 +136,11 @@ int l_init(int argc, char **argv, int reinit) { lua_setglobal(lua, "_CHARSET"); if (l_load_script("core/init.lua")) { - lua_getglobal(lua, "textadept"); + lua_getglobal(lua, "_SCINTILLA"); l_archive(lua, "constants"); - l_archive(lua, "buffer_functions"); - l_archive(lua, "buffer_properties"); - lua_pop(lua, 1); // textadept + l_archive(lua, "functions"); + l_archive(lua, "properties"); + lua_pop(lua, 1); // _SCINTILLA return TRUE; } lua_close(lua); @@ -283,7 +290,7 @@ static sptr_t l_checkdocpointer(lua_State *lua, int narg) { /** * Adds a Scintilla document to the global 'buffers' table with a metatable. * @param doc The Scintilla document to add. - * @return integer index of the new buffer in textadept.buffers. + * @return integer index of the new buffer in _BUFFERS. */ int l_add_scintilla_buffer(sptr_t doc) { lua_getfield(lua, LUA_REGISTRYINDEX, "buffers"); @@ -668,8 +675,8 @@ void l_emit_scnnotification(struct SCNotification *n) { * Requests and pops up a context menu for the Scintilla view. * @param event The mouse button event. */ -void l_ta_popup_context_menu(GdkEventButton *event) { - lua_getglobal(lua, "textadept"); +void l_gui_popup_context_menu(GdkEventButton *event) { + lua_getglobal(lua, "gui"); if (lua_istable(lua, -1)) { lua_getfield(lua, -1, "context_menu"); if (lua_isuserdata(lua, -1)) { @@ -679,8 +686,8 @@ void l_ta_popup_context_menu(GdkEventButton *event) { event ? event->button : 0, gdk_event_get_time((GdkEvent *)event)); } else if (!lua_isnil(lua, -1)) - warn("textadept.context_menu: gtkmenu expected"); - lua_pop(lua, 1); // textadept.context_menu + warn("gui.context_menu: gtkmenu expected"); + lua_pop(lua, 1); // gui.context_menu } else lua_pop(lua, 1); } @@ -759,21 +766,21 @@ static int l_call_buffer_function(lua_State *lua) { static int l_buffer_mt_index(lua_State *lua) { const char *key = luaL_checkstring(lua, 2); - lua_getfield(lua, LUA_REGISTRYINDEX, "buffer_functions"); + lua_getfield(lua, LUA_REGISTRYINDEX, "functions"); lua_getfield(lua, -1, key); - lua_remove(lua, -2); // ta_buffer_functions + lua_remove(lua, -2); // buffer functions if (lua_istable(lua, -1)) { l_check_focused_buffer(lua, 1); // Of the form { msg, rt_type, p1_type, p2_type } lua_pushlightuserdata(lua, (GtkWidget *)focused_editor); - l_insert(lua, -1); // shift buffer_functions down + l_insert(lua, -1); // shift buffer functions down lua_pushcclosure(lua, l_call_buffer_function, 2); return 1; } else lua_pop(lua, 1); // non-table - lua_getfield(lua, LUA_REGISTRYINDEX, "buffer_properties"); + lua_getfield(lua, LUA_REGISTRYINDEX, "properties"); lua_getfield(lua, -1, key); - lua_remove(lua, -2); // ta_buffer_properties + lua_remove(lua, -2); // buffer properties if (lua_istable(lua, -1)) { l_check_focused_buffer(lua, 1); // Of the form { get_id, set_id, rt_type, p1_type } @@ -809,9 +816,9 @@ static int l_buffer_mt_index(lua_State *lua) { * getter and setter properties, it is 2 because the index is an argument. */ static int l_bufferp_mt_(lua_State *lua, int n, const char *prop, int arg) { - lua_getfield(lua, LUA_REGISTRYINDEX, "buffer_properties"); + lua_getfield(lua, LUA_REGISTRYINDEX, "properties"); lua_getfield(lua, -1, prop); - lua_remove(lua, -2); // ta_buffer_properties + lua_remove(lua, -2); // buffer properties if (lua_istable(lua, -1)) { l_check_focused_buffer(lua, 1); int msg = l_rawgeti_int(lua, -1, n); // getter (1) or setter (2) @@ -872,12 +879,9 @@ static int l_view_mt_newindex(lua_State *lua) { return 0; } -static int l_ta_mt_index(lua_State *lua) { +static int l_gui_mt_index(lua_State *lua) { const char *key = lua_tostring(lua, 2); - if (streq(key, "buffers") || streq(key, "views") || streq(key, "constants") || - streq(key, "buffer_functions") || streq(key, "buffer_properties")) - lua_getfield(lua, LUA_REGISTRYINDEX, key); - else if (streq(key, "title")) + if (streq(key, "title")) lua_pushstring(lua, gtk_window_get_title(GTK_WINDOW(window))); else if (streq(key, "focused_doc_pointer")) lua_pushinteger(lua, SS(focused_editor, SCI_GETDOCPOINTER, 0, 0)); @@ -900,12 +904,9 @@ static int l_ta_mt_index(lua_State *lua) { return 1; } -static int l_ta_mt_newindex(lua_State *lua) { +static int l_gui_mt_newindex(lua_State *lua) { const char *key = lua_tostring(lua, 2); - if (streq(key, "buffers") || streq(key, "views") || streq(key, "constants") || - streq(key, "buffer_functions") || streq(key, "buffer_properties")) - luaL_argerror(lua, 3, "read-only property"); - else if (streq(key, "title")) + if (streq(key, "title")) gtk_window_set_title(GTK_WINDOW(window), lua_tostring(lua, 3)); else if (streq(key, "statusbar_text")) set_statusbar_text(lua_tostring(lua, 3), FALSE); @@ -1011,7 +1012,7 @@ static int l_cf_buffer_delete(lua_State *lua) { return 0; } -static int l_cf_ta_buffer_new(lua_State *lua) { +static int l_cf_buffer_new(lua_State *lua) { new_scintilla_buffer(focused_editor, TRUE, TRUE); lua_getfield(lua, LUA_REGISTRYINDEX, "buffers"); lua_rawgeti(lua, -1, lua_objlen(lua, -1)); @@ -1081,7 +1082,7 @@ void l_create_entry(lua_State *lua, GtkWidget *c1, GtkWidget *c2, lua_setfield(lua, -2, "size"); } -static int l_cf_ta_get_split_table(lua_State *lua) { +static int l_cf_gui_get_split_table(lua_State *lua) { lua_getfield(lua, LUA_REGISTRYINDEX, "views"); if (lua_objlen(lua, -1) > 1) { GtkWidget *pane = gtk_widget_get_parent(focused_editor); @@ -1092,7 +1093,7 @@ static int l_cf_ta_get_split_table(lua_State *lua) { return 1; } -static int l_cf_ta_goto_(lua_State *lua, GtkWidget *editor, int buffer) { +static int l_cf_gui_goto_(lua_State *lua, GtkWidget *editor, int buffer) { int n = luaL_checkinteger(lua, 1); int absolute = (lua_gettop(lua) > 1) ? lua_toboolean(lua, 2) == 1 : TRUE; buffer ? l_goto_scintilla_buffer(editor, n, absolute) @@ -1108,7 +1109,7 @@ static int l_cf_view_goto_buffer(lua_State *lua) { GtkWidget *orig_focused_editor = focused_editor; if (switch_focus) SS(editor, SCI_SETFOCUS, TRUE, 0); lua_remove(lua, 1); // view table - l_cf_ta_goto_(lua, editor, TRUE); + l_cf_gui_goto_(lua, editor, TRUE); if (switch_focus) { SS(editor, SCI_SETFOCUS, FALSE, 0); gtk_widget_grab_focus(orig_focused_editor); @@ -1116,7 +1117,7 @@ static int l_cf_view_goto_buffer(lua_State *lua) { return 0; } -static int l_cf_ta_dialog(lua_State *lua) { +static int l_cf_gui_dialog(lua_State *lua) { GCDialogType type = gcocoadialog_type(luaL_checkstring(lua, 1)); int argc = lua_gettop(lua) - 1; const char *argv[argc]; @@ -1127,22 +1128,22 @@ static int l_cf_ta_dialog(lua_State *lua) { return 1; } -static int l_cf_ta_goto_window(lua_State *lua) { - return l_cf_ta_goto_(lua, focused_editor, FALSE); +static int l_cf_gui_goto_view(lua_State *lua) { + return l_cf_gui_goto_(lua, focused_editor, FALSE); } static void t_menu_activate(GtkWidget *menu, gpointer id) { l_emit_event("menu_clicked", LUA_TNUMBER, GPOINTER_TO_INT(id), -1); } -static int l_cf_ta_gtkmenu(lua_State *lua) { +static int l_cf_gui_gtkmenu(lua_State *lua) { luaL_checktype(lua, 1, LUA_TTABLE); GtkWidget *menu = l_create_gtkmenu(lua, G_CALLBACK(t_menu_activate), FALSE); lua_pushlightuserdata(lua, (GtkWidget *)menu); return 1; } -static int l_cf_ta_iconv(lua_State *lua) { +static int l_cf_string_iconv(lua_State *lua) { size_t text_len = 0, conv_len = 0; const char *text = luaL_checklstring(lua, 1, &text_len); const char *to = luaL_checkstring(lua, 2); @@ -1155,7 +1156,7 @@ static int l_cf_ta_iconv(lua_State *lua) { return 1; } -static int l_cf_ta_quit(lua_State *lua) { +static int l_cf_quit(lua_State *lua) { GdkEventAny event; event.type = GDK_DELETE; event.window = window->window; @@ -1164,7 +1165,7 @@ static int l_cf_ta_quit(lua_State *lua) { return 0; } -static int l_cf_ta_reset(lua_State *lua) { +static int l_cf_reset(lua_State *lua) { l_emit_event("reset_before", -1); l_init(0, NULL, TRUE); lua_pushboolean(lua, TRUE); diff --git a/src/textadept.c b/src/textadept.c index f0fa79f6..c3948634 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -449,12 +449,12 @@ static gbool s_keypress(GtkWidget *editor, GdkEventKey *event, gpointer udata) { /** * Signal for a Scintilla mouse click. * If it is a right-click, popup a context menu. - * @see l_ta_popup_context_menu + * @see l_gui_popup_context_menu */ static gbool s_buttonpress(GtkWidget *editor, GdkEventButton *event, gpointer udata) { if (event->type != GDK_BUTTON_PRESS || event->button != 3) return FALSE; - l_ta_popup_context_menu(event); + l_gui_popup_context_menu(event); return TRUE; } diff --git a/src/textadept.h b/src/textadept.h index 74db23d0..6d9e2c75 100644 --- a/src/textadept.h +++ b/src/textadept.h @@ -56,6 +56,6 @@ void l_set_buffer_global(GtkWidget *); int l_emit_event(const char *, ...); void l_emit_scnnotification(struct SCNotification *); -void l_ta_popup_context_menu(GdkEventButton *); +void l_gui_popup_context_menu(GdkEventButton *); #endif diff --git a/themes/dark/buffer.lua b/themes/dark/buffer.lua index cd2c8ce5..12a4e55b 100644 --- a/themes/dark/buffer.lua +++ b/themes/dark/buffer.lua @@ -1,7 +1,6 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -- Dark editor theme for Textadept. -local textadept = _G.textadept local buffer = buffer -- folding diff --git a/themes/dark/view.lua b/themes/dark/view.lua index 45491d27..c3c68edf 100644 --- a/themes/dark/view.lua +++ b/themes/dark/view.lua @@ -1,8 +1,7 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -- Dark editor theme for Textadept. -local textadept = _G.textadept -local c = textadept.constants +local c = _SCINTILLA.constants local buffer = buffer -- caret diff --git a/themes/light/buffer.lua b/themes/light/buffer.lua index 8f2c22dd..1bb9a7da 100644 --- a/themes/light/buffer.lua +++ b/themes/light/buffer.lua @@ -1,7 +1,6 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -- Light editor theme for Textadept. -local textadept = _G.textadept local buffer = buffer -- folding diff --git a/themes/light/view.lua b/themes/light/view.lua index 5527120e..1a684d0b 100644 --- a/themes/light/view.lua +++ b/themes/light/view.lua @@ -1,8 +1,7 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -- Light editor theme for Textadept. -local textadept = _G.textadept -local c = textadept.constants +local c = _SCINTILLA.constants local buffer = buffer -- caret diff --git a/themes/scite/buffer.lua b/themes/scite/buffer.lua index 92e5dea8..a93116db 100644 --- a/themes/scite/buffer.lua +++ b/themes/scite/buffer.lua @@ -1,7 +1,6 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -- SciTE editor theme for Textadept. -local textadept = _G.textadept local buffer = buffer -- folding diff --git a/themes/scite/view.lua b/themes/scite/view.lua index 8ee70c9e..d612377d 100644 --- a/themes/scite/view.lua +++ b/themes/scite/view.lua @@ -1,8 +1,7 @@ -- Copyright 2007-2010 Mitchell mitchell<att>caladbolg.net. See LICENSE. -- SciTE editor theme for Textadept. -local textadept = _G.textadept -local c = textadept.constants +local c = _SCINTILLA.constants local buffer = buffer buffer.margin_width_n[0] = 4 * buffer:text_width(c.STYLE_LINENUMBER, "9") |