aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2013-04-29 16:13:59 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2013-04-29 16:13:59 -0400
commit78990df4f114c45adc7fd2678ffaedf0c4124d95 (patch)
tree9e79e8f93aa07ee9384b5ddd8cc548dc3c8ea20f /core
parent8407377bbe3800dbc4706f584285b7a7858efabc (diff)
downloadtextadept-78990df4f114c45adc7fd2678ffaedf0c4124d95.tar.gz
textadept-78990df4f114c45adc7fd2678ffaedf0c4124d95.zip
More code cleanup.
"local buffer = buffer" and similar optimizations are not needed since lexing the buffer is much more expensive and reaction time is limited by how fast the keyboard can submit key presses.
Diffstat (limited to 'core')
-rw-r--r--core/args.lua6
-rw-r--r--core/events.lua1
-rw-r--r--core/file_io.lua8
-rw-r--r--core/gui.lua9
-rw-r--r--core/init.lua22
-rw-r--r--core/keys.lua43
6 files changed, 25 insertions, 64 deletions
diff --git a/core/args.lua b/core/args.lua
index e6db7696..f0cdba65 100644
--- a/core/args.lua
+++ b/core/args.lua
@@ -12,8 +12,6 @@ local M = {}
-- Emitted when no command line arguments are passed to Textadept on startup.
module('args')]]
-local arg = arg
-
-- Contains registered command line switches.
-- @class table
-- @name switches
@@ -79,6 +77,8 @@ local function show_help()
end
if not CURSES then M.register('-h', '--help', 0, show_help, 'Shows this') end
+local arg = arg
+
-- For Windows, create arg table from single command line string (arg[0]).
if WIN32 and not CURSES and #arg[0] > 0 then
local P, C = lpeg.P, lpeg.C
@@ -99,7 +99,7 @@ if not lfs.attributes(userhome) then lfs.mkdir(userhome) end
if not lfs.attributes(userhome..'/init.lua') then
local f = io.open(userhome..'/init.lua', 'w')
if f then
- f:write("_M.textadept = require 'textadept'\n")
+ f:write("_M.textadept = require('textadept')\n")
f:close()
end
end
diff --git a/core/events.lua b/core/events.lua
index 51644644..02bb81b2 100644
--- a/core/events.lua
+++ b/core/events.lua
@@ -290,7 +290,6 @@ function M.disconnect(event, id)
end
local error_emitted = false
-
---
-- Sequentially calls all handler functions for *event* with the given
-- arguments.
diff --git a/core/file_io.lua b/core/file_io.lua
index 137463d9..145159a4 100644
--- a/core/file_io.lua
+++ b/core/file_io.lua
@@ -79,7 +79,7 @@ io.recent_files = {}
-- @class table
-- @name boms
io.boms = {
- ['UTF-16BE'] = '\254\255', ['UTF-16LE'] = '\255\254',
+ ['UTF-16BE'] = '\254\255', ['UTF-16LE'] = '\255\254',
['UTF-32BE'] = '\0\0\254\255', ['UTF-32LE'] = '\255\254\0\0'
}
@@ -346,7 +346,6 @@ end
-- of Textadept.
local function update_modified_file()
if not buffer.filename then return end
- local buffer = buffer
local utf8_filename = buffer.filename
local filename = utf8_filename:iconv(_CHARSET, 'UTF-8')
local mod_time = lfs.attributes(filename, 'modification')
@@ -373,7 +372,6 @@ events_connect(events.VIEW_AFTER_SWITCH, update_modified_file)
-- Set additional buffer functions.
events_connect(events.BUFFER_NEW, function()
- local buffer = buffer
buffer.reload = reload
buffer.save, buffer.save_as = save, save_as
buffer.close = close
@@ -382,8 +380,8 @@ end)
-- Close initial "Untitled" buffer.
events_connect(events.FILE_OPENED, function(utf8_filename)
- local b = _BUFFERS[1]
- if #_BUFFERS == 2 and not (b.filename or b._type or b.dirty) then
+ local buf = _BUFFERS[1]
+ if #_BUFFERS == 2 and not (buf.filename or buf._type or buf.dirty) then
view:goto_buffer(1)
buffer:close()
end
diff --git a/core/gui.lua b/core/gui.lua
index 6869468f..445a65de 100644
--- a/core/gui.lua
+++ b/core/gui.lua
@@ -19,8 +19,6 @@ local gui = gui
-- The text displayed by the buffer statusbar.
module('gui')]]
-local _L = _L
-
-- Helper function for printing messages to buffers.
-- @see gui._print
local function _print(buffer_type, ...)
@@ -161,6 +159,7 @@ end
local theme_file = not CURSES and 'theme' or 'theme_term'
local THEME
+
---
-- Sets the editor theme name to *name* or the default platform theme.
-- Themes with *name* in the *`_USERHOME`/themes/* directory override themes of
@@ -348,23 +347,21 @@ events_connect(events.APPLEEVENT_ODOC, function(uri)
return events_emit(events.URI_DROPPED, 'file://'..uri)
end)
-local string_format = string.format
local EOLs = {_L['CRLF'], _L['CR'], _L['LF']}
local GETLEXERLANGUAGE = _SCINTILLA.properties.lexer_language[1]
-- Sets docstatusbar text.
events_connect(events.UPDATE_UI, function()
- local buffer = buffer
local pos = buffer.current_pos
local line, max = buffer:line_from_position(pos) + 1, buffer.line_count
local col = buffer.column[pos] + 1
local lexer = buffer:private_lexer_call(GETLEXERLANGUAGE):match('^[^/]+')
local eol = EOLs[buffer.eol_mode + 1]
- local tabs = string_format('%s %d', buffer.use_tabs and _L['Tabs:'] or
+ local tabs = string.format('%s %d', buffer.use_tabs and _L['Tabs:'] or
_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'
- gui.docstatusbar_text = string_format(text, _L['Line:'], line, max,
+ gui.docstatusbar_text = string.format(text, _L['Line:'], line, max,
_L['Col:'], col, lexer, eol, tabs, enc)
end)
diff --git a/core/init.lua b/core/init.lua
index d3a57482..83da8eff 100644
--- a/core/init.lua
+++ b/core/init.lua
@@ -4,24 +4,22 @@ _RELEASE = "Textadept 6.6 beta"
package.path = _HOME..'/core/?.lua;'..package.path
-_SCINTILLA = require 'iface'
-args = require 'args'
-_L = require 'locale'
-events = require 'events'
-require 'file_io'
-require 'lfs_ext'
-require 'gui'
-keys = require 'keys'
+_SCINTILLA = require('iface')
+args = require('args')
+_L = require('locale')
+events = require('events')
+require('file_io')
+require('lfs_ext')
+require('gui')
+keys = require('keys')
_LEXERPATH = _USERHOME..'/lexers/?.lua;'.._HOME..'/lexers'
-
-gui.set_theme()
-
_M = {} -- modules table
-
-- LuaJIT compatibility.
if jit then module, package.searchers, bit32 = nil, package.loaders, bit end
+gui.set_theme()
+
--[[ This comment is for LuaDoc.
---
-- Extends Lua's _G table to provide extra functions and fields for Textadept.
diff --git a/core/keys.lua b/core/keys.lua
index f6373af6..13459982 100644
--- a/core/keys.lua
+++ b/core/keys.lua
@@ -122,22 +122,10 @@ local M = {}
-- The default value is `nil`.
module('keys')]]
-local ADD = ''
-local CTRL, ALT, META, SHIFT = 'c'..ADD, 'a'..ADD, 'm'..ADD, 's'..ADD
-if CURSES then ALT = META end
+local CTRL, ALT, META, SHIFT = 'c', not CURSES and 'a' or 'm', 'm', 's'
M.CLEAR = 'esc'
M.LANGUAGE_MODULE_PREFIX = (not OSX and not CURSES and CTRL or META)..'l'
--- Optimize for speed.
-local OSX = OSX
-local string = string
-local string_byte, string_char = string.byte, string.char
-local table_unpack = table.unpack
-local xpcall, next, type = xpcall, next, type
-local no_args = {}
-local getmetatable = getmetatable
-local error = function(e) events.emit(events.ERROR, e) end
-
---
-- Lookup table for string representations of key codes higher than 255.
-- Key codes can be identified by temporarily uncommenting the `print()`
@@ -195,13 +183,15 @@ end
-- Export for command_entry.lua without creating LuaDoc.
if CURSES then M.clear_key_sequence = clear_key_sequence end
+local none = {}
+local function key_error(e) events.emit(events.ERROR, e) end
-- Runs a given command.
-- This is also used by *modules/textadept/menu.lua*.
-- @param command A function or table as described above.
-- @param command_type Equivalent to `type(command)`.
-- @return the value the command returns.
local function run_command(command, command_type)
- local f, args = command_type == 'function' and command or command[1], no_args
+ local f, args = command_type == 'function' and command or command[1], none
if command_type == 'table' then
args = command
-- If the argument is a view or buffer, use the current one instead.
@@ -214,7 +204,7 @@ local function run_command(command, command_type)
end
end
end
- local _, result = xpcall(f, error, table_unpack(args, 2))
+ local _, result = xpcall(f, key_error, table.unpack(args, 2))
return result
end
M.run_command = run_command -- export for menu.lua without creating LuaDoc
@@ -251,7 +241,7 @@ end
-- @return `true` to stop handling the key; `nil` otherwise.
local function keypress(code, shift, control, alt, meta)
--print(code, M.KEYSYMS[code], shift, control, alt, meta)
- local key = code < 256 and (not CURSES or code ~= 7) and string_char(code) or
+ local key = code < 256 and (not CURSES or code ~= 7) and string.char(code) or
M.KEYSYMS[code]
if not key then return end
shift = shift and (code >= 256 or code == 9) -- printable chars are uppercased
@@ -285,27 +275,6 @@ local function keypress(code, shift, control, alt, meta)
end
events.connect(events.KEYPRESS, keypress, 1)
--- Returns the GDK integer keycode and modifier mask for a key sequence.
--- This is used for creating menu accelerators.
--- @param key_seq The string key sequence.
--- @return keycode and modifier mask
-local function get_gdk_key(key_seq)
- if not key_seq then return nil end
- local mods, key = key_seq:match('^([cams]*)(.+)$')
- if not mods or not key then return nil end
- local modifiers = ((mods:find('s') or key:lower() ~= key) and 1 or 0) +
- (mods:find('c') and 4 or 0) + (mods:find('a') and 8 or 0) +
- (mods:find('m') and 268435456 or 0)
- local byte = string_byte(key)
- if #key > 1 or byte < 32 then
- for i, s in pairs(M.KEYSYMS) do
- if s == key and i > 0xFE20 then byte = i break end
- end
- end
- return byte, modifiers
-end
-M.get_gdk_key = get_gdk_key -- export for menu.lua without generating LuaDoc
-
---
-- Map of key bindings to commands, with language-specific key tables assigned
-- to a lexer name key.