Skip to content

Commit

Permalink
Separate locating and loading of init file.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornbm committed Apr 28, 2023
1 parent 2debb10 commit 8280237
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions ple.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1014,20 +1014,24 @@ editor.bindings_ctlx = { -- ^X<key>
[62] = e.goeot, -- ^X >
}--editor.bindings_ctlx

local function editor_loadinitfile()
local function editor_initfile()
-- Return path to PLE user configuration file, if any.
local initlocations = { -- Init file locations in order of priority
os.getenv("PLE_INIT"),
"./ple_init.lua",
(os.getenv("HOME") or "~") .. "/.config/ple/ple_init.lua",
}
-- Return first initfile found
for _, initfile in pairs(initlocations) do
if fileexists(initfile) then return initfile end
end
return nil -- No init file found
end--getinitfilename

local function editor_loadinitfile(initfile)
-- function to be executed before entering the editor loop
-- could be used to load a configuration/initialization file
local initfile = os.getenv("PLE_INIT")
if fileexists(initfile) then
return assert(loadfile(initfile))()
end
initfile = "./ple_init.lua"
if fileexists(initfile) then
return assert(loadfile(initfile))()
end
local homedir = os.getenv("HOME") or "~"
initfile = homedir .. "/.config/ple/ple_init.lua"
if fileexists(initfile) then
if initfile then
return assert(loadfile(initfile))()
end
return nil
Expand All @@ -1036,7 +1040,7 @@ end--editor_loadinitfile

local function editor_loop(ll, fname)
editor.initmsg = "Help: F1 or ^X^H"
local r = editor_loadinitfile()
local r = editor_loadinitfile(editor_initfile())
style.normal()
e.newbuffer(nil, fname, ll);
-- 1st arg is current buffer (unused for newbuffer, so nil)
Expand Down

0 comments on commit 8280237

Please sign in to comment.