diff --git a/config/src/lua.rs b/config/src/lua.rs index 805efba16..16320cac1 100644 --- a/config/src/lua.rs +++ b/config/src/lua.rs @@ -111,6 +111,28 @@ pub fn make_lua_context(config_file: &Path) -> anyhow::Result { .to_str() .ok_or_else(|| anyhow!("config file path is not UTF-8"))?; + // Hook into loader and arrange to watch all require'd files. + // + // 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", diff --git a/docs/changelog.md b/docs/changelog.md index 77b2acd30..0ecb83963 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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 diff --git a/docs/config/lua/wezterm/add_to_config_reload_watch_list.md b/docs/config/lua/wezterm/add_to_config_reload_watch_list.md index 447f4bdcb..4144972e5 100644 --- a/docs/config/lua/wezterm/add_to_config_reload_watch_list.md +++ b/docs/config/lua/wezterm/add_to_config_reload_watch_list.md @@ -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.