aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/events.lua18
-rw-r--r--core/ext/mime_types.lua3
-rw-r--r--core/file_io.lua4
3 files changed, 15 insertions, 10 deletions
diff --git a/core/events.lua b/core/events.lua
index 6ffe327f..25dfb25d 100644
--- a/core/events.lua
+++ b/core/events.lua
@@ -16,9 +16,14 @@ module('textadept.events', package.seeall)
-- is useful to have a handler run under a specific condition(s). If this is the
-- case, place a conditional in the function that returns if it isn't met.
--
--- For users creating their own events, one does not have to be explicitly
--- defined. A handler can simply be added for an event name, and 'handle'd when
--- necessary.
+-- If a handler returns either true or false explicitly, all subsequent handlers
+-- are not called. This is useful for something like a 'keypress' event where if
+-- the key is handled, true should be returned so as to not propagate the event.
+--
+-- Events need not be declared. A handler can simply be added for an event name,
+-- and 'handle'd when necessary. As an example, you can create a handler for a
+-- custom 'my_event' and call "textadept.events.handle('my_event')" to envoke
+-- it.
--
-- For reference, events will be shown in 'event(arguments)' format, but in
-- reality, the event is handled as 'handle(event, arguments)'.
@@ -324,8 +329,6 @@ add_handler('buffer_new',
if not ret then io.stderr:write(errmsg) end
end)
-local title_text = '%s %s Textadept (%s)'
-
---
-- [Local function] Sets the title of the Textadept window to the buffer's
-- filename.
@@ -333,9 +336,10 @@ local title_text = '%s %s Textadept (%s)'
local function set_title(buffer)
local buffer = buffer
local filename = buffer.filename or buffer._type or locale.UNTITLED
- local d = buffer.dirty and '*' or '-'
+ local dirty = buffer.dirty and '*' or '-'
textadept.title =
- string.format(title_text, filename:match('[^/\\]+$'), d, filename)
+ string.format('%s %s Textadept (%s)', filename:match('[^/\\]+$'), dirty,
+ filename)
end
add_handler('save_point_reached',
diff --git a/core/ext/mime_types.lua b/core/ext/mime_types.lua
index a1867437..7fb7fcab 100644
--- a/core/ext/mime_types.lua
+++ b/core/ext/mime_types.lua
@@ -45,11 +45,12 @@ end
---
-- [Local function] Replacement for buffer:set_lexer_language().
--- Sets a buffer._lexer field so it can be restored without querying the
+-- Sets a buffer._lexer field so it can be restored without querying the
-- mime-types tables. Also if the user manually sets the lexer, it should be
-- restored.
-- @param buffer The buffer to set the lexer language of.
-- @param lang The string language to set.
+-- @usage buffer:set_lexer('language_name')
local function set_lexer(buffer, lang)
buffer._lexer = lang
buffer:set_lexer_language(lang)
diff --git a/core/file_io.lua b/core/file_io.lua
index b0131aa1..859e52c6 100644
--- a/core/file_io.lua
+++ b/core/file_io.lua
@@ -91,7 +91,6 @@ local function open_helper(utf8_filename)
end
local buffer = textadept.new_buffer()
if text then
- local c = textadept.constants
-- Tries to detect character encoding and convert text from it to UTF-8.
local encoding, encoding_bom = detect_encoding(text)
if encoding ~= 'binary' then
@@ -113,6 +112,7 @@ local function open_helper(utf8_filename)
else
encoding = nil
end
+ local c = textadept.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.
@@ -329,7 +329,7 @@ function load_session(filename, only_pm)
local anchor, current_pos, first_visible_line, filename =
line:match('^buffer: (%d+) (%d+) (%d+) (.+)$')
if not filename:find('^%[.+%]$') then
- textadept.io.open(filename or '', 'rb')
+ textadept.io.open(filename or '')
else
textadept.new_buffer()
buffer._type = filename