aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+orbitalquark@users.noreply.github.com>2020-10-12 10:43:30 -0400
committerGravatar mitchell <70453897+orbitalquark@users.noreply.github.com>2020-10-12 10:43:30 -0400
commit0ebd2624ae677ecd4b58c8e4abd37618ab5bb0c2 (patch)
tree1219185a17d354006013d29c685e1f584d1bda34 /modules
parentff7f869ae0a02535dcc7f44a65dd3ea2fed87d01 (diff)
Added `ui.command_entry.append_history()` for manually appending history.
Normally history is auto-appended by the default '\n' key handler, but some custom modes may have their own '\n' handlers and did not have a way to append history.
Diffstat (limited to 'modules')
-rw-r--r--modules/lua/ta_api1
-rw-r--r--modules/lua/ta_tags1
-rw-r--r--modules/textadept/command_entry.lua16
3 files changed, 15 insertions, 3 deletions
diff --git a/modules/lua/ta_api b/modules/lua/ta_api
index 3d9a9b7f..a7db7a60 100644
--- a/modules/lua/ta_api
+++ b/modules/lua/ta_api
@@ -333,6 +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.\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 b0634779..a213f6ef 100644
--- a/modules/lua/ta_tags
+++ b/modules/lua/ta_tags
@@ -335,6 +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_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 594b1e81..5c30394e 100644
--- a/modules/textadept/command_entry.lua
+++ b/modules/textadept/command_entry.lua
@@ -35,6 +35,18 @@ local function cycle_history(prev)
end
---
+-- Appends the given text to the history for the current or most recent command
+-- entry 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
+end
+
+---
-- A metatable with typical platform-specific key bindings for text entries.
-- This metatable may be used to add basic editing and movement keys to command
-- entry modes. It is automatically added to command entry modes unless a
@@ -217,9 +229,7 @@ function M.run(f, keys, lang, height)
if M:auto_c_active() then return false end -- allow Enter to autocomplete
M.focus() -- hide
if not f then return end
- local mode_history = history[history.mode]
- mode_history[#mode_history + 1] = M:get_text()
- mode_history.pos = #mode_history
+ M.append_history(M:get_text())
f(M:get_text())
end
end