1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-24 05:42:03 +03:00

lua: we now watch require'd files in addition to the main config file

Finally got around to https://github.com/wez/wezterm/discussions/914#discussioncomment-960983
This commit is contained in:
Wez Furlong 2022-06-29 15:12:06 -07:00
parent d23414105e
commit ad42f1d7c4
3 changed files with 26 additions and 2 deletions

View File

@ -111,6 +111,28 @@ pub fn make_lua_context(config_file: &Path) -> anyhow::Result<Lua> {
.to_str()
.ok_or_else(|| anyhow!("config file path is not UTF-8"))?;
// Hook into loader and arrange to watch all require'd files.
// <https://www.lua.org/manual/5.3/manual.html#pdf-package.searchers>
// says that the second searcher function is the one that is responsible
// for loading lua files, so we shim around that and speculatively
// add the name of the file that it would find (as returned from
// package.searchpath) to the watch list, then we just call the
// original implementation.
lua.load(
r#"
local orig = package.searchers[2]
package.searchers[2] = function(module)
local name, err = package.searchpath(module, package.path)
if name then
package.loaded.wezterm.add_to_config_reload_watch_list(name)
end
return orig(module)
end
"#,
)
.set_name("=searcher")?
.eval()?;
wezterm_mod.set("config_file", config_file_str)?;
wezterm_mod.set(
"config_dir",

View File

@ -18,6 +18,7 @@ As features stabilize some brief notes about them will accumulate here.
* `colors.indexed` would error out with `Cannot convert String to u8`. [#2197](https://github.com/wez/wezterm/issues/2197)
* X11: closing a window when multiple were open could result in an X protocol error that closed all windows [#2198](https://github.com/wez/wezterm/issues/2198)
* Config will now automatically reload after error. Previously, you would need to manually reload the config using [ReloadConfiguration](config/lua/keyassignment/ReloadConfiguration.md). [#1174](https://github.com/wez/wezterm/issues/1174)
* Config will now automatically reload for changes made to 'require'd lua files. Previously, only the main config file and any files that you explicitly passed to [add_to_config_reload_watch_list](config/lua/wezterm/add_to_config_reload_watch_list.md) would trigger a reload.
### 20220624-141144-bd1b7c5d

View File

@ -7,5 +7,6 @@ If [automatically_reload_config](../config/automatically_reload_config.md)
is enabled, then the config will be reloaded when any of the files
that have been added to the watch list have changed.
The intent of for this to be used together with a custom lua loader
in a future iteration of wezterm.
*Since: nightly builds only*
This function is now called implicitly when you `require` a lua file.