aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/10_Advanced.md3
-rw-r--r--doc/13_Help.md2
-rw-r--r--modules/textadept/command_entry.lua8
3 files changed, 12 insertions, 1 deletions
diff --git a/doc/10_Advanced.md b/doc/10_Advanced.md
index a54f7145..5ac24594 100644
--- a/doc/10_Advanced.md
+++ b/doc/10_Advanced.md
@@ -10,7 +10,8 @@ For available commands, see the [Lua API][]. Abbreviated commands for
[`buffer`][], [`view`][] and [`gui`][] are available: the command
`buffer:append_text('foo')` can be shortened to `append_text('foo')`. Therefore,
use `_G.print()` for Lua's `print()` since [`gui.print()`][] is shortened to
-`print()`.
+`print()`. You can also run commands on startup using the `-e` and `--execute`
+command line switches.
![Command Entry](images/commandentry.png)
diff --git a/doc/13_Help.md b/doc/13_Help.md
index f2c3dedc..673c2759 100644
--- a/doc/13_Help.md
+++ b/doc/13_Help.md
@@ -7,6 +7,7 @@ parameters.
Switch |Arguments|Description
-------------------|:-------:|-----------
+`-e`, `--execute` | 1 |Run Lua [code][].
`-f`, `--force` | 0 |Forces [unique instance][].
`-h`, `--help` | 0 |Shows this.
`-n`, `--nosession`| 0 |No [session][] functionality.
@@ -15,6 +16,7 @@ Switch |Arguments|Description
The help switch is unavailable in ncurses.
+[code]: 10_Advanced.html#Command.Entry
[unique instance]: 02_Installation.html#Single.Instance
[session]: 04_WorkingWithFiles.html#Sessions
[`_USERHOME`]: api/_G.html#_USERHOME
diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua
index d3d2d1ea..31e3cff1 100644
--- a/modules/textadept/command_entry.lua
+++ b/modules/textadept/command_entry.lua
@@ -87,6 +87,14 @@ events.connect(events.COMMAND_ENTRY_KEYPRESS, function(code)
end
end)
+-- Executes Lua code on startup.
+local function execute(command)
+ local f, err = load(command, nil, 'bt', env)
+ if err then error(err) end
+ f()
+end
+args.register('-e', '--execute', 1, execute, 'Execute Lua code')
+
--[[ The function below is a Lua C function.
---