aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+667e-11@users.noreply.github.com>2020-03-30 18:44:15 -0400
committerGravatar mitchell <70453897+667e-11@users.noreply.github.com>2020-03-30 18:44:15 -0400
commitc46527cc32aef6fd332ea5e45757c0858b1cbb5d (patch)
tree8ffd94daf08117a21469697c4cec2c14a5bfdeb3
parent4d88d116f8f8181186fd734841d5303269924c16 (diff)
Fixed off-by-one issues with `buffer:get_cur_line()`.
-rw-r--r--doc/manual.md4
-rw-r--r--modules/ansi_c/init.lua3
-rw-r--r--modules/lua/init.lua4
-rw-r--r--modules/textadept/command_entry.lua3
4 files changed, 11 insertions, 3 deletions
diff --git a/doc/manual.md b/doc/manual.md
index 2779713d..880e3313 100644
--- a/doc/manual.md
+++ b/doc/manual.md
@@ -2080,6 +2080,10 @@ In migrating Textadept's internals, the following changes were made:
* Marker or indicator masks are produced by subtracting 1 from marker or
indicator numbers. For example, `1 << textadept.bookmarks.MARK_BOOKMARK`
changes to `1 << textadept.bookmarks.MARK_BOOKMARK - 1`.
+* Logic that depends on the return value of `buffer:get_cur_line()` may need to
+ be changed. For example, any subsequent references to `pos` after
+ `local line, pos = buffer:get_cur_line()` like `if line:sub(1, pos) ... end`
+ need to be changed to `if line:sub(1, pos - 1) ... end`.
I found it helpful to quickly scan source files for syntax-highlighted numbers
and then seeing if those numbers needed to be changed. Searching for "- 1",
diff --git a/modules/ansi_c/init.lua b/modules/ansi_c/init.lua
index 688b81c3..8cfc5135 100644
--- a/modules/ansi_c/init.lua
+++ b/modules/ansi_c/init.lua
@@ -35,7 +35,8 @@ local xpms = setmetatable({
textadept.editing.autocompleters.ansi_c = function()
-- Retrieve the symbol behind the caret.
local line, pos = buffer:get_cur_line()
- local symbol, op, part = line:sub(1, pos):match('([%w_]-)([%.%->]*)([%w_]*)$')
+ local symbol, op, part = line:sub(1, pos - 1):match(
+ '([%w_]-)([%.%->]*)([%w_]*)$')
if symbol == '' and part == '' then return nil end -- nothing to complete
if op ~= '' and op ~= '.' and op ~= '->' then return nil end
-- Attempt to identify the symbol type.
diff --git a/modules/lua/init.lua b/modules/lua/init.lua
index 7a06b302..056e230b 100644
--- a/modules/lua/init.lua
+++ b/modules/lua/init.lua
@@ -26,6 +26,7 @@ local function ta_api(filename)
buffer == ui.command_entry or buffer._type then
return filename
end
+ ui.dialogs.msgbox{text=filename,informative_text=buffer.filename}
end
end
@@ -61,7 +62,8 @@ textadept.editing.autocompleters.lua = function()
local list = {}
-- Retrieve the symbol behind the caret.
local line, pos = buffer:get_cur_line()
- local symbol, op, part = line:sub(1, pos):match('([%w_%.]-)([%.:]?)([%w_]*)$')
+ local symbol, op, part = line:sub(1, pos - 1):match(
+ '([%w_%.]-)([%.:]?)([%w_]*)$')
if symbol == '' and part == '' then return nil end -- nothing to complete
if symbol == '' and M.autocomplete_snippets then
local _, snippets = textadept.editing.autocompleters.snippet()
diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua
index 7929a6b8..8310a8b8 100644
--- a/modules/textadept/command_entry.lua
+++ b/modules/textadept/command_entry.lua
@@ -121,7 +121,8 @@ args.register('-e', '--execute', 1, run_lua, 'Execute Lua code')
-- `ui` tables are also considered as globals.
local function complete_lua()
local line, pos = M:get_cur_line()
- local symbol, op, part = line:sub(1, pos):match('([%w_.]-)([%.:]?)([%w_]*)$')
+ local symbol, op, part = line:sub(1, pos - 1):match(
+ '([%w_.]-)([%.:]?)([%w_]*)$')
local ok, result = pcall(
(load(string.format('return (%s)', symbol), nil, 't', env)))
if (not ok or type(result) ~= 'table') and symbol ~= '' then return end