First implementation of unix-like data directory

It basically works by setting the data directory to

$prefix/share/lite-xl

where $prefix is determined so that $prefix/bin corresponds to EXEDIR.

The packages 'user' and 'user.*' are loaded from the directory
'$HOME/.config/lite-xl'.
This commit is contained in:
Francesco Abbate 2020-12-02 00:23:15 +01:00
parent e9938862b5
commit 3589d7d3c0
6 changed files with 49 additions and 10 deletions

View File

@ -98,7 +98,7 @@ command.add(nil, {
end, end,
["core:open-user-module"] = function() ["core:open-user-module"] = function()
core.root_view:open_doc(core.open_doc(EXEDIR .. "/data/user/init.lua")) core.root_view:open_doc(core.open_doc(USERDIR .. "/init.lua"))
end, end,
["core:open-project-module"] = function() ["core:open-project-module"] = function()

View File

@ -94,7 +94,7 @@ function core.init()
CommandView = require "core.commandview" CommandView = require "core.commandview"
Doc = require "core.doc" Doc = require "core.doc"
local project_dir = EXEDIR local project_dir = "."
local files = {} local files = {}
for i = 2, #ARGS do for i = 2, #ARGS do
local info = system.get_file_info(ARGS[i]) or {} local info = system.get_file_info(ARGS[i]) or {}
@ -187,7 +187,7 @@ end
function core.load_plugins() function core.load_plugins()
local no_errors = true local no_errors = true
local files = system.list_dir(EXEDIR .. "/data/plugins") local files = system.list_dir(DATADIR .. "/plugins")
for _, filename in ipairs(files) do for _, filename in ipairs(files) do
local modname = "plugins." .. filename:gsub(".lua$", "") local modname = "plugins." .. filename:gsub(".lua$", "")
local ok = core.try(require, modname) local ok = core.try(require, modname)

View File

@ -7,10 +7,10 @@ style.scrollbar_size = common.round(4 * SCALE)
style.caret_width = common.round(2 * SCALE) style.caret_width = common.round(2 * SCALE)
style.tab_width = common.round(170 * SCALE) style.tab_width = common.round(170 * SCALE)
style.font = renderer.font.load(EXEDIR .. "/data/fonts/font.ttf", 14 * SCALE) style.font = renderer.font.load(DATADIR .. "/fonts/font.ttf", 14 * SCALE)
style.big_font = renderer.font.load(EXEDIR .. "/data/fonts/font.ttf", 34 * SCALE) style.big_font = renderer.font.load(DATADIR .. "/fonts/font.ttf", 34 * SCALE)
style.icon_font = renderer.font.load(EXEDIR .. "/data/fonts/icons.ttf", 14 * SCALE) style.icon_font = renderer.font.load(DATADIR .. "/fonts/icons.ttf", 14 * SCALE)
style.code_font = renderer.font.load(EXEDIR .. "/data/fonts/monospace.ttf", 13.5 * SCALE) style.code_font = renderer.font.load(DATADIR .. "/fonts/monospace.ttf", 13.5 * SCALE)
style.background = { common.color "#2e2e32" } style.background = { common.color "#2e2e32" }
style.background2 = { common.color "#252529" } style.background2 = { common.color "#252529" }

View File

@ -14,8 +14,15 @@ endif
sdl_dep = dependency('sdl2', method: 'config-tool') sdl_dep = dependency('sdl2', method: 'config-tool')
lite_cargs = []
if host_machine.system() == 'windows'
lite_cargs += ['-DLITE_XL_DATA_USE_EXEDIR']
endif
lite_include = include_directories('src') lite_include = include_directories('src')
install_subdir('data', install_dir : 'bin') install_subdir('data/core', install_dir : 'share/lite-xl')
install_subdir('data/fonts', install_dir : 'share/lite-xl')
install_subdir('data/plugins', install_dir : 'share/lite-xl')
lite_link_args = [] lite_link_args = []
if get_option('buildtype') == 'release' if get_option('buildtype') == 'release'

View File

@ -123,8 +123,39 @@ int main(int argc, char **argv) {
" SCALE = tonumber(os.getenv(\"LITE_SCALE\")) or SCALE\n" " SCALE = tonumber(os.getenv(\"LITE_SCALE\")) or SCALE\n"
" PATHSEP = package.config:sub(1, 1)\n" " PATHSEP = package.config:sub(1, 1)\n"
" EXEDIR = EXEFILE:match(\"^(.+)[/\\\\].*$\")\n" " EXEDIR = EXEFILE:match(\"^(.+)[/\\\\].*$\")\n"
" package.path = EXEDIR .. '/data/?.lua;' .. package.path\n" #ifdef LITE_XL_DATA_USE_EXEDIR
" package.path = EXEDIR .. '/data/?/init.lua;' .. package.path\n" " DATADIR = EXEDIR .. '/data'\n"
#else
" local prefix = EXEDIR:match(\"^(.+)[/\\\\]bin$\")\n"
" DATADIR = prefix and (prefix .. '/share/lite-xl') or (EXEDIR .. '/data')\n"
" USERDIR = os.getenv(\"HOME\") .. '/.config/lite-xl'\n"
"table.insert(package.searchers, 1, function(module_name)\n"
" if module_name == 'user' or module_name:match('^user%.') then\n"
" return function(x_module_name)\n"
" local filename, err\n"
" if x_module_name == 'user' then\n"
" filename = USERDIR..'/init.lua'\n"
" else\n"
" local modname = x_module_name:gsub('^user%.', '')\n"
" filename, err = package.searchpath(modname, USERDIR..'/?.lua;'..USERDIR..'/?/init.lua')\n"
" end\n"
" if filename then\n"
" local module_f, module_err = loadfile(filename)\n"
" if module_f then\n"
" return module_f()\n"
" else\n"
" return nil, module_err\n"
" end\n"
" else\n"
" return nil, err\n"
" end\n"
" end\n"
" end\n"
"end)\n"
#endif
" package.path = DATADIR .. '/?.lua;' .. package.path\n"
" package.path = DATADIR .. '/?/init.lua;' .. package.path\n"
" core = require('core')\n" " core = require('core')\n"
" core.init()\n" " core.init()\n"
" core.run()\n" " core.run()\n"

View File

@ -12,6 +12,7 @@ executable('lite',
lite_sources + lite_rc, lite_sources + lite_rc,
include_directories: [lite_include, font_renderer_include], include_directories: [lite_include, font_renderer_include],
dependencies: [lua_dep, sdl_dep, libm, libdl], dependencies: [lua_dep, sdl_dep, libm, libdl],
c_args: lite_cargs,
link_with: libfontrenderer, link_with: libfontrenderer,
link_args: lite_link_args, link_args: lite_link_args,
install: true, install: true,