From 1177ef981b04a0c368ab4cbad5e0f6bfdd252cb6 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Mon, 29 Mar 2010 19:04:32 -0400 Subject: Use textadept.user_dofile() for user init.lua. --- core/.textadept.lua | 2 ++ core/init.lua | 2 ++ init.lua | 13 ++----------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/core/.textadept.lua b/core/.textadept.lua index ec6d9622..5fe9776d 100644 --- a/core/.textadept.lua +++ b/core/.textadept.lua @@ -131,5 +131,7 @@ 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. +-- Errors are printed to the Textadept message buffer. -- @param filename The name of the file (not path). +-- @return true if successful; false otherwise. function user_dofile(filename) end diff --git a/core/init.lua b/core/init.lua index 7576e660..505a3b45 100644 --- a/core/init.lua +++ b/core/init.lua @@ -105,5 +105,7 @@ 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 + return ret end + return false end diff --git a/init.lua b/init.lua index c81f2766..05b1361f 100644 --- a/init.lua +++ b/init.lua @@ -4,23 +4,14 @@ local textadept = _G.textadept local paths = { _HOME..'/modules/?.lua', - _HOME..'/modules/?/init.lua', + _HOME..'/modules/?/init.lua', _USERHOME..'/modules/?.lua', _USERHOME..'/modules/?/init.lua', package.path } package.path = table.concat(paths, ';') -local loaded_user_modules = false -local user_init = _USERHOME..'/init.lua' -local lfs = require 'lfs' -if lfs.attributes(user_init) then - local ret, errmsg = pcall(dofile, user_init) - if not ret then error(errmsg) end - loaded_user_modules = ret -end - -if not loaded_user_modules then +if not textadept.user_dofile('init.lua') then -- Core extension modules to load on startup. require 'ext/keys' -- provides key command support require 'ext/find' -- provides functionality for find/replace -- cgit v1.2.3