aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+orbitalquark@users.noreply.github.com>2020-11-01 23:30:43 -0500
committerGravatar mitchell <70453897+orbitalquark@users.noreply.github.com>2020-11-01 23:30:43 -0500
commit85b8810660ffa37eb2d3edf85a4dbf12ba5f1ca3 (patch)
treec364b17b99c60326e7c85278c29ffc2c6584f598 /modules
parent2ec90788dc08346d74a79877a35f91c74d661688 (diff)
Added optional mode parameter to `ui.command_entry.append_history()`.
This allows for arbitrary appending to history, not just for the current or most recent mode.
Diffstat (limited to 'modules')
-rw-r--r--modules/lua/ta_api2
-rw-r--r--modules/lua/ta_tags2
-rw-r--r--modules/textadept/command_entry.lua25
3 files changed, 18 insertions, 11 deletions
diff --git a/modules/lua/ta_api b/modules/lua/ta_api
index 31327fc8..5832ece4 100644
--- a/modules/lua/ta_api
+++ b/modules/lua/ta_api
@@ -333,7 +333,7 @@ ansi_c _G.snippets.ansi_c (table)\nTable of C-specific snippets.
ansi_c _M.ansi_c (module)\nThe ansi_c module.\nIt provides utilities for editing C code.
any lexer.any (pattern)\nA pattern that matches any single character.
api_files textadept.editing.api_files (table)\nMap of lexer names to API documentation file tables.\nFile tables contain API file paths or functions that return such paths.\nEach line in an API file consists of a symbol name (not a fully qualified\nsymbol name), a space character, and that symbol's documentation. "\\n"\nrepresents a newline character.\n@see show_documentation
-append_history ui.command_entry.append_history(text)\nAppends the given text to the history for the current or most recent command\nentry mode.\nThis should only be called if `ui.command_entry.run()` is called with a keys\ntable that has a custom binding for the Enter key ('\\n').\nOtherwise, history is automatically appended as needed.\n@param text String text to append to history.
+append_history ui.command_entry.append_history(f, text)\nAppends string *text* to the history for command entry mode *f* or the\ncurrent or most recent mode.\nThis should only be called if `ui.command_entry.run()` is called with a keys\ntable that has a custom binding for the Enter key ('\\n').\nOtherwise, history is automatically appended as needed.\n@param f Optional command entry mode to append history to. This is a function\n passed to `ui.command_entry_run()`. If omitted, uses the current or most\n recent mode.\n@param text String text to append to history.
append_text buffer.append_text(buffer, text)\nAppends string *text* to the end of the buffer without modifying any existing\nselections or scrolling the text into view.\n@param buffer A buffer.\n@param text The text to append.
arg _G.arg (table)\nTable of command line parameters passed to Textadept.\n@see args
args _G.args (module)\nProcesses command line arguments for Textadept.
diff --git a/modules/lua/ta_tags b/modules/lua/ta_tags
index e186e8e3..dc56db4f 100644
--- a/modules/lua/ta_tags
+++ b/modules/lua/ta_tags
@@ -335,7 +335,7 @@ ansi_c _HOME/modules/ansi_c/init.lua /^module('_M.ansi_c')]]$/;" m class:_M
ansi_c _HOME/modules/ansi_c/init.lua /^snippets.ansi_c = {$/;" t class:snippets
any _HOME/lexers/lexer.lua /^module('lexer')]=]$/;" F class:lexer
api_files _HOME/modules/textadept/editing.lua /^M.api_files = setmetatable({}, {__index = function(t, k)$/;" t class:textadept.editing
-append_history _HOME/modules/textadept/command_entry.lua /^function M.append_history(text)$/;" f class:ui.command_entry
+append_history _HOME/modules/textadept/command_entry.lua /^function M.append_history(f, text)$/;" f class:ui.command_entry
append_text _HOME/core/.buffer.luadoc /^function append_text(buffer, text) end$/;" f class:buffer
arg _HOME/core/init.lua /^local arg$/;" t
args _HOME/core/args.lua /^module('args')]]$/;" m
diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua
index 3e344f81..d7475a8c 100644
--- a/modules/textadept/command_entry.lua
+++ b/modules/textadept/command_entry.lua
@@ -18,7 +18,10 @@ module('ui.command_entry')]]
-- The current mode is in the `mode` field.
-- @class table
-- @name history
-local history = {}
+local history = setmetatable({}, {__index = function(t, k)
+ if type(k) == 'function' then t[k] = {pos = 0} else return nil end
+ return t[k]
+end})
-- Cycles through command history for the current mode.
-- @param prev Flag that indicates whether to cycle to the previous command or
@@ -35,18 +38,23 @@ local function cycle_history(prev)
end
---
--- Appends the given text to the history for the current or most recent command
--- entry mode.
+-- Appends string *text* to the history for command entry mode *f* or the
+-- current or most recent mode.
-- This should only be called if `ui.command_entry.run()` is called with a keys
-- table that has a custom binding for the Enter key ('\n').
-- Otherwise, history is automatically appended as needed.
+-- @param f Optional command entry mode to append history to. This is a function
+-- passed to `ui.command_entry_run()`. If omitted, uses the current or most
+-- recent mode.
-- @param text String text to append to history.
-- @name append_history
-function M.append_history(text)
- if not history.mode then return end
- local mode_history = history[history.mode]
- mode_history[#mode_history + 1] = assert_type(text, 'string', 1)
- mode_history.pos = #mode_history
+function M.append_history(f, text)
+ if not assert_type(text, 'string/nil', 2) then
+ f, text = history.mode, assert_type(f, 'string', 1)
+ if not f then return end
+ end
+ local mode_history = history[assert_type(f, 'function', 1)]
+ mode_history[#mode_history + 1], mode_history.pos = text, #mode_history + 1
end
---
@@ -235,7 +243,6 @@ function M.run(f, keys, lang, height)
end
end
if not getmetatable(keys) then setmetatable(keys, M.editing_keys) end
- if f and not history[f] then history[f] = {pos = 0} end
history.mode = f
local mode_history = history[history.mode]
M:set_text(mode_history and mode_history[mode_history.pos] or '')