diff options
-rw-r--r-- | core/.textadept.lua | 6 | ||||
-rw-r--r-- | core/ext/key_commands.lua | 7 | ||||
-rw-r--r-- | core/init.lua | 8 | ||||
-rw-r--r-- | modules/textadept/lsnippets.lua | 2 |
4 files changed, 17 insertions, 6 deletions
diff --git a/core/.textadept.lua b/core/.textadept.lua index 0ce0d19a..ec6d9622 100644 --- a/core/.textadept.lua +++ b/core/.textadept.lua @@ -127,3 +127,9 @@ function switch_buffer() end -- Each argument is like a string in Lua's 'arg' table. -- @return string CocoaDialog result. function dialog(kind, ...) end + +--- +-- Calls 'dofile' on the given filename in the user's Textadept directory. +-- This is typically used for loading user files like key commands or snippets. +-- @param filename The name of the file (not path). +function user_dofile(filename) end diff --git a/core/ext/key_commands.lua b/core/ext/key_commands.lua index f318c08d..70357a5a 100644 --- a/core/ext/key_commands.lua +++ b/core/ext/key_commands.lua @@ -462,12 +462,7 @@ else keys.cad = { 'del_word_right', b } end --- Load user key commands. -local lfs = require 'lfs' -if lfs.attributes(_USERHOME..'/key_commands.lua') then - local ret, errmsg = pcall(dofile, _USERHOME..'/key_commands.lua') - if not ret then textadept.print(errmsg) end -end +textadept.user_dofile('key_commands.lua') -- load user key commands --- -- This module has no functions. diff --git a/core/init.lua b/core/init.lua index b55a3f04..7576e660 100644 --- a/core/init.lua +++ b/core/init.lua @@ -99,3 +99,11 @@ function textadept.switch_buffer() local i = tonumber(out:match('%-?%d+$')) if i and i >= 0 then view:goto_buffer(i + 1, true) end end + +-- LuaDoc is in core/.textadept.lua. +function textadept.user_dofile(filename) + if lfs.attributes(_USERHOME..'/'..filename) then + local ret, errmsg = pcall(dofile, _USERHOME..'/'..filename) + if not ret then textadept.print(errmsg) end + end +end diff --git a/modules/textadept/lsnippets.lua b/modules/textadept/lsnippets.lua index 1c2c377b..9eb999ea 100644 --- a/modules/textadept/lsnippets.lua +++ b/modules/textadept/lsnippets.lua @@ -456,3 +456,5 @@ function show_style() style_num) buffer:call_tip_show(buffer.current_pos, text) end + +textadept.user_dofile('snippets.lua') -- load user snippets |