From 4e4873d59c41c0c72549c4eccd63b8a339f0aba7 Mon Sep 17 00:00:00 2001 From: Alexander Brevig Date: Thu, 28 Jul 2022 20:00:24 +0200 Subject: [PATCH 01/16] docs: add section about local config, written like the one for languages --- .helix/config.toml | 2 ++ .helix/languages.toml | 3 +++ book/src/configuration.md | 7 +++++++ 3 files changed, 12 insertions(+) create mode 100644 .helix/config.toml create mode 100644 .helix/languages.toml diff --git a/.helix/config.toml b/.helix/config.toml new file mode 100644 index 000000000000..3333b105d08e --- /dev/null +++ b/.helix/config.toml @@ -0,0 +1,2 @@ +theme = "gruvbox_light" +err = yes diff --git a/.helix/languages.toml b/.helix/languages.toml new file mode 100644 index 000000000000..38f7db065ed0 --- /dev/null +++ b/.helix/languages.toml @@ -0,0 +1,3 @@ +[[language]] +name = "rust" +#auto-format = false diff --git a/book/src/configuration.md b/book/src/configuration.md index affd497c7580..cf7d3cda71fa 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -25,8 +25,15 @@ select = "underline" hidden = false ``` +<<<<<<< HEAD You may also specify a file to use for configuration with the `-c` or `--config` CLI argument: `hx -c path/to/custom-config.toml`. +======= +Editor configuration may also be overridden local to a project by creating +a `config.toml` file under a `.helix` directory. Its settings will be merged +with the configuration directory `config.toml` and the built-in configuration. + +>>>>>>> a4a8e122 (docs: add section about local config, written like the one for languages) ## Editor From 1e9bee31eda2557d94f9c5b443c608a31a4c51f6 Mon Sep 17 00:00:00 2001 From: Alexander Brevig Date: Thu, 28 Jul 2022 20:04:02 +0200 Subject: [PATCH 02/16] fix: mistakes were made --- .helix/config.toml | 2 -- .helix/languages.toml | 3 --- 2 files changed, 5 deletions(-) delete mode 100644 .helix/config.toml delete mode 100644 .helix/languages.toml diff --git a/.helix/config.toml b/.helix/config.toml deleted file mode 100644 index 3333b105d08e..000000000000 --- a/.helix/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -theme = "gruvbox_light" -err = yes diff --git a/.helix/languages.toml b/.helix/languages.toml deleted file mode 100644 index 38f7db065ed0..000000000000 --- a/.helix/languages.toml +++ /dev/null @@ -1,3 +0,0 @@ -[[language]] -name = "rust" -#auto-format = false From 04da5ee20aa34e4b311b6be640c30ea59b2e2f9e Mon Sep 17 00:00:00 2001 From: Alexander Brevig Date: Tue, 30 Aug 2022 01:11:43 +0200 Subject: [PATCH 03/16] fix: cleaner code --- helix-term/src/config.rs | 89 ++++++++++++++++++++++++++++++++++++++++ helix-term/src/main.rs | 14 +------ 2 files changed, 90 insertions(+), 13 deletions(-) diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs index 4407a882f838..c1dfe8b8ba1b 100644 --- a/helix-term/src/config.rs +++ b/helix-term/src/config.rs @@ -55,6 +55,95 @@ impl Config { pub fn load_default() -> Result { Config::load(helix_loader::config_file()) } + + // Load a merged config from configuration and $PWD/.helix/config.toml + pub fn load_merged_config() -> Config { + let root_config: Config = std::fs::read_to_string(helix_loader::config_file()) + .ok() + .and_then(|config| toml::from_str(&config).ok()) + .unwrap_or_else(|| { + eprintln!("Bad config: {:?}", helix_loader::config_file()); + Config::halt_and_confirm("default"); + Config::default() + }); + + // Load each config file + let local_config_values = helix_loader::local_config_dirs() + .into_iter() + .map(|path| path.join("config.toml")) + .chain([helix_loader::config_file()]) + .filter_map(|file| Config::load_config_toml_values(&root_config, file)); + + // Merge configs and return, or alert user of error and load default + match local_config_values + .fold(toml::Value::Table(toml::value::Table::default()), |a, b| { + helix_loader::merge_toml_values(b, a, 3) + }) + .try_into() + { + Ok(conf) => conf, + Err(_) => root_config, + } + } + + // Load a specific config file if allowed by config + // Stay with toml::Values as they can be merged + pub fn load_config_toml_values( + root_config: &Config, + config_path: std::path::PathBuf, + ) -> Option { + if config_path.exists() { + let mut confirmed = true; + if config_path != helix_loader::config_file() { + if root_config.editor.security.load_local_config { + if root_config.editor.security.confirm_local_config { + eprintln!( + "Type yes to continue with loading config: {:#?}", + config_path + ); + let mut input = String::new(); + std::io::stdin().read_line(&mut input).unwrap_or_default(); + confirmed = input.contains("yes"); + } //else we still presume confirmed = true + } else { + // User denies local configs, do not load + confirmed = false; + } + } + if confirmed { + log::debug!("Load config: {:?}", config_path); + let bytes = std::fs::read(&config_path); + let cfg: Option = match bytes { + Ok(bytes) => { + let cfg = toml::from_slice(&bytes); + match cfg { + Ok(cfg) => Some(cfg), + Err(e) => { + eprintln!("Toml parse error for {:?}: {}", &config_path, e); + Config::halt_and_confirm("loaded"); + None + } + } + } + Err(e) => { + eprintln!("Could not read {:?}: {}", &config_path, e); + Config::halt_and_confirm("loaded"); + None + } + }; + return cfg; + } else { + return None; + } + } + None + } + + fn halt_and_confirm(config_type: &'static str) { + eprintln!("Press to continue with {} config", config_type); + let mut tmp = String::new(); + let _ = std::io::stdin().read_line(&mut tmp); + } } #[cfg(test)] diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index 7f04f2014b95..91ee8d239095 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -122,19 +122,7 @@ FLAGS: helix_loader::initialize_config_file(args.config_file.clone()); - let config = match std::fs::read_to_string(helix_loader::config_file()) { - Ok(config) => toml::from_str(&config) - .map(helix_term::keymap::merge_keys) - .unwrap_or_else(|err| { - eprintln!("Bad config: {}", err); - eprintln!("Press to continue with default config"); - use std::io::Read; - let _ = std::io::stdin().read(&mut []); - Config::default() - }), - Err(err) if err.kind() == std::io::ErrorKind::NotFound => Config::default(), - Err(err) => return Err(Error::new(err)), - }; + let config: Config = Config::load_merged_config(); // TODO: use the thread local executor to spawn the application task separately from the work pool let mut app = Application::new(args, config).context("unable to create new application")?; From 6ad3fb333dcec2f7917f6106dea968d186b1b324 Mon Sep 17 00:00:00 2001 From: Alexander Brevig Date: Tue, 30 Aug 2022 08:52:17 +0200 Subject: [PATCH 04/16] fix: after rebase, reinstate editor.security --- helix-term/src/main.rs | 2 +- helix-view/src/editor.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index 91ee8d239095..de80e29d037e 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -122,7 +122,7 @@ FLAGS: helix_loader::initialize_config_file(args.config_file.clone()); - let config: Config = Config::load_merged_config(); + let config = Config::load_merged_config(); // TODO: use the thread local executor to spawn the application task separately from the work pool let mut app = Application::new(args, config).context("unable to create new application")?; diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 0bf7ebd02cc9..59fafd2650d5 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -156,6 +156,9 @@ pub struct Config { /// Search configuration. #[serde(default)] pub search: SearchConfig, + /// Security settings (i.e. loading TOML files from $PWD/.helix) + #[serde(default)] + pub security: SecurityConfig, pub lsp: LspConfig, pub terminal: Option, /// Column numbers at which to draw the rulers. Default to `[]`, meaning no rulers. @@ -168,6 +171,26 @@ pub struct Config { pub color_modes: bool, } +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "kebab-case", default, deny_unknown_fields)] +pub struct SecurityConfig { + pub load_local_config: bool, + pub confirm_local_config: bool, + //pub load_local_languages: bool, //TODO: implement + //pub confirm_local_languages: bool, //TODO: implement +} + +impl Default for SecurityConfig { + fn default() -> Self { + Self { + load_local_config: false, + confirm_local_config: true, + //load_local_languages: false, + //confirm_local_languages: true, + } + } +} + #[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] #[serde(default, rename_all = "kebab-case", deny_unknown_fields)] pub struct TerminalConfig { @@ -550,6 +573,7 @@ impl Default for Config { cursor_shape: CursorShapeConfig::default(), true_color: false, search: SearchConfig::default(), + security: SecurityConfig::default(), lsp: LspConfig::default(), terminal: get_terminal_provider(), rulers: Vec::new(), From a53a008ce0382992164cc32018986f791688d6e2 Mon Sep 17 00:00:00 2001 From: Alexander Brevig Date: Tue, 30 Aug 2022 08:57:48 +0200 Subject: [PATCH 05/16] fix: configuration book entry after rebase --- book/src/configuration.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/book/src/configuration.md b/book/src/configuration.md index cf7d3cda71fa..0f32ee96ddaa 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -25,15 +25,12 @@ select = "underline" hidden = false ``` -<<<<<<< HEAD You may also specify a file to use for configuration with the `-c` or -`--config` CLI argument: `hx -c path/to/custom-config.toml`. -======= -Editor configuration may also be overridden local to a project by creating -a `config.toml` file under a `.helix` directory. Its settings will be merged -with the configuration directory `config.toml` and the built-in configuration. +`--config` CLI argument: `hx -c path/to/custom-config.toml`. ->>>>>>> a4a8e122 (docs: add section about local config, written like the one for languages) +Finally, you can have a `config.toml` local to a project by it under a `.helix` directory in your repository. +Its settings will be merged with the configuration directory `config.toml` and the built-in configuration, +if you have enabled the feature under `[editor.security]` in your global configuration. ## Editor @@ -236,3 +233,13 @@ Example: render = true character = "╎" ``` + +### `[editor.security]` Section + +Opt in to features that may put you at risk. +It is possible to write malicious TOML files, so we suggest you keep the `confirm_*` options to their default value of `true`. + +| Key | Description | Default | +| --- | --- | --- | +| `load_local_config` | Load a `config.yaml` from `$PWD/.helix` that will merge with your global configuration. | `false` | +| `confirm_local_config` | Prompt the user at launch in order to accept the loading of a found local `$PWD/.helix` | `true` | \ No newline at end of file From f93e2d1f3ecdbdeb384387828efe32b0a4338d25 Mon Sep 17 00:00:00 2001 From: Alexander Brevig Date: Tue, 30 Aug 2022 11:08:42 +0200 Subject: [PATCH 06/16] fix: clippy from rebase --- helix-term/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index de80e29d037e..b7c80f30d65d 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -1,4 +1,4 @@ -use anyhow::{Context, Error, Result}; +use anyhow::{Context, Result}; use crossterm::event::EventStream; use helix_term::application::Application; use helix_term::args::Args; From e6e6ec3d911c239cd54dc6878fac19f31bb32378 Mon Sep 17 00:00:00 2001 From: Alexander Brevig Date: Thu, 1 Sep 2022 23:57:17 +0200 Subject: [PATCH 07/16] fix: use reduce and not fold --- helix-term/src/config.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs index c1dfe8b8ba1b..269ebc793435 100644 --- a/helix-term/src/config.rs +++ b/helix-term/src/config.rs @@ -75,14 +75,9 @@ impl Config { .filter_map(|file| Config::load_config_toml_values(&root_config, file)); // Merge configs and return, or alert user of error and load default - match local_config_values - .fold(toml::Value::Table(toml::value::Table::default()), |a, b| { - helix_loader::merge_toml_values(b, a, 3) - }) - .try_into() - { - Ok(conf) => conf, - Err(_) => root_config, + match local_config_values.reduce(|a, b| helix_loader::merge_toml_values(b, a, 3)) { + Some(conf) => conf.try_into().unwrap_or_default(), + None => root_config, } } From ed9aa6020dcb9e7fb5f90e95c9b0473e159203c2 Mon Sep 17 00:00:00 2001 From: Alexander Brevig Date: Thu, 1 Sep 2022 23:59:03 +0200 Subject: [PATCH 08/16] fix: early exit --- helix-term/src/config.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs index 269ebc793435..22e3f261e21c 100644 --- a/helix-term/src/config.rs +++ b/helix-term/src/config.rs @@ -87,7 +87,9 @@ impl Config { root_config: &Config, config_path: std::path::PathBuf, ) -> Option { - if config_path.exists() { + if !config_path.exists() { + return None; + } else { let mut confirmed = true; if config_path != helix_loader::config_file() { if root_config.editor.security.load_local_config { @@ -131,7 +133,6 @@ impl Config { return None; } } - None } fn halt_and_confirm(config_type: &'static str) { From 3da3606b30d5c418ed061207f58ff9a55acb600f Mon Sep 17 00:00:00 2001 From: Alexander Brevig Date: Fri, 2 Sep 2022 00:31:16 +0200 Subject: [PATCH 09/16] style: clippy ok --- helix-term/src/config.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs index 22e3f261e21c..fe05b0fc69e5 100644 --- a/helix-term/src/config.rs +++ b/helix-term/src/config.rs @@ -88,7 +88,7 @@ impl Config { config_path: std::path::PathBuf, ) -> Option { if !config_path.exists() { - return None; + None } else { let mut confirmed = true; if config_path != helix_loader::config_file() { @@ -128,9 +128,9 @@ impl Config { None } }; - return cfg; + cfg } else { - return None; + None } } } From 9359c4518185e1e8c97198a67a87b0b1a502da2e Mon Sep 17 00:00:00 2001 From: Alexander Brevig Date: Fri, 9 Sep 2022 20:12:51 +0200 Subject: [PATCH 10/16] style: no need to else after early exit, golang style --- helix-term/src/config.rs | 81 ++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs index fe05b0fc69e5..bf09da8f9c2d 100644 --- a/helix-term/src/config.rs +++ b/helix-term/src/config.rs @@ -88,50 +88,49 @@ impl Config { config_path: std::path::PathBuf, ) -> Option { if !config_path.exists() { - None - } else { - let mut confirmed = true; - if config_path != helix_loader::config_file() { - if root_config.editor.security.load_local_config { - if root_config.editor.security.confirm_local_config { - eprintln!( - "Type yes to continue with loading config: {:#?}", - config_path - ); - let mut input = String::new(); - std::io::stdin().read_line(&mut input).unwrap_or_default(); - confirmed = input.contains("yes"); - } //else we still presume confirmed = true - } else { - // User denies local configs, do not load - confirmed = false; - } + return None; + } + let mut confirmed = true; + if config_path != helix_loader::config_file() { + if root_config.editor.security.load_local_config { + if root_config.editor.security.confirm_local_config { + eprintln!( + "Type yes to continue with loading config: {:#?}", + config_path + ); + let mut input = String::new(); + std::io::stdin().read_line(&mut input).unwrap_or_default(); + confirmed = input.contains("yes"); + } //else we still presume confirmed = true + } else { + // User denies local configs, do not load + confirmed = false; } - if confirmed { - log::debug!("Load config: {:?}", config_path); - let bytes = std::fs::read(&config_path); - let cfg: Option = match bytes { - Ok(bytes) => { - let cfg = toml::from_slice(&bytes); - match cfg { - Ok(cfg) => Some(cfg), - Err(e) => { - eprintln!("Toml parse error for {:?}: {}", &config_path, e); - Config::halt_and_confirm("loaded"); - None - } + } + if confirmed { + log::debug!("Load config: {:?}", config_path); + let bytes = std::fs::read(&config_path); + let cfg: Option = match bytes { + Ok(bytes) => { + let cfg = toml::from_slice(&bytes); + match cfg { + Ok(cfg) => Some(cfg), + Err(e) => { + eprintln!("Toml parse error for {:?}: {}", &config_path, e); + Config::halt_and_confirm("loaded"); + None } } - Err(e) => { - eprintln!("Could not read {:?}: {}", &config_path, e); - Config::halt_and_confirm("loaded"); - None - } - }; - cfg - } else { - None - } + } + Err(e) => { + eprintln!("Could not read {:?}: {}", &config_path, e); + Config::halt_and_confirm("loaded"); + None + } + }; + cfg + } else { + None } } From a0f80cd1d7cbac0ed87c7176c93732f13dd6ec33 Mon Sep 17 00:00:00 2001 From: Alexander Brevig Date: Mon, 19 Sep 2022 22:56:32 +0200 Subject: [PATCH 11/16] fix: remove confirm_local_config --- book/src/configuration.md | 3 +-- helix-term/src/config.rs | 21 +++------------------ helix-view/src/editor.rs | 15 +-------------- 3 files changed, 5 insertions(+), 34 deletions(-) diff --git a/book/src/configuration.md b/book/src/configuration.md index 0f32ee96ddaa..602805e0ebc0 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -241,5 +241,4 @@ It is possible to write malicious TOML files, so we suggest you keep the `confir | Key | Description | Default | | --- | --- | --- | -| `load_local_config` | Load a `config.yaml` from `$PWD/.helix` that will merge with your global configuration. | `false` | -| `confirm_local_config` | Prompt the user at launch in order to accept the loading of a found local `$PWD/.helix` | `true` | \ No newline at end of file +| `load-local-config` | Load `config.yaml` from `$PWD/.helix` that will merge with your global configuration. | `false` | diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs index bf09da8f9c2d..ef428057f2fd 100644 --- a/helix-term/src/config.rs +++ b/helix-term/src/config.rs @@ -90,24 +90,9 @@ impl Config { if !config_path.exists() { return None; } - let mut confirmed = true; - if config_path != helix_loader::config_file() { - if root_config.editor.security.load_local_config { - if root_config.editor.security.confirm_local_config { - eprintln!( - "Type yes to continue with loading config: {:#?}", - config_path - ); - let mut input = String::new(); - std::io::stdin().read_line(&mut input).unwrap_or_default(); - confirmed = input.contains("yes"); - } //else we still presume confirmed = true - } else { - // User denies local configs, do not load - confirmed = false; - } - } - if confirmed { + if config_path == helix_loader::config_file() + || root_config.editor.security.load_local_config + { log::debug!("Load config: {:?}", config_path); let bytes = std::fs::read(&config_path); let cfg: Option = match bytes { diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 59fafd2650d5..eeb8b1eb6d97 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -171,24 +171,11 @@ pub struct Config { pub color_modes: bool, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "kebab-case", default, deny_unknown_fields)] pub struct SecurityConfig { pub load_local_config: bool, - pub confirm_local_config: bool, //pub load_local_languages: bool, //TODO: implement - //pub confirm_local_languages: bool, //TODO: implement -} - -impl Default for SecurityConfig { - fn default() -> Self { - Self { - load_local_config: false, - confirm_local_config: true, - //load_local_languages: false, - //confirm_local_languages: true, - } - } } #[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] From 11aa4189bd928b5f23e61164717a3ed85f8efa07 Mon Sep 17 00:00:00 2001 From: Alexander Brevig Date: Fri, 23 Sep 2022 13:48:24 +0200 Subject: [PATCH 12/16] fix: remove confirm option from book --- book/src/configuration.md | 1 - 1 file changed, 1 deletion(-) diff --git a/book/src/configuration.md b/book/src/configuration.md index 602805e0ebc0..437d553cce23 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -237,7 +237,6 @@ character = "╎" ### `[editor.security]` Section Opt in to features that may put you at risk. -It is possible to write malicious TOML files, so we suggest you keep the `confirm_*` options to their default value of `true`. | Key | Description | Default | | --- | --- | --- | From 8acc1b95181f5961834b9016ed14ab75dde37481 Mon Sep 17 00:00:00 2001 From: Alexander Brevig Date: Fri, 23 Sep 2022 13:55:49 +0200 Subject: [PATCH 13/16] style: merged an if statement --- helix-term/src/config.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs index ef428057f2fd..28e0f2836c3b 100644 --- a/helix-term/src/config.rs +++ b/helix-term/src/config.rs @@ -87,11 +87,9 @@ impl Config { root_config: &Config, config_path: std::path::PathBuf, ) -> Option { - if !config_path.exists() { - return None; - } - if config_path == helix_loader::config_file() - || root_config.editor.security.load_local_config + if config_path.exists() + && (config_path == helix_loader::config_file() + || root_config.editor.security.load_local_config) { log::debug!("Load config: {:?}", config_path); let bytes = std::fs::read(&config_path); From 0f311640c12b6fbdf8f0b1a3d7814208d9ac09fc Mon Sep 17 00:00:00 2001 From: Alexander Brevig Date: Sat, 24 Sep 2022 08:48:25 +0200 Subject: [PATCH 14/16] style: ...and early return --- helix-term/src/config.rs | 49 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs index 28e0f2836c3b..437d557696eb 100644 --- a/helix-term/src/config.rs +++ b/helix-term/src/config.rs @@ -87,34 +87,33 @@ impl Config { root_config: &Config, config_path: std::path::PathBuf, ) -> Option { - if config_path.exists() - && (config_path == helix_loader::config_file() - || root_config.editor.security.load_local_config) + if !config_path.exists() + || (config_path != helix_loader::config_file() + && !root_config.editor.security.load_local_config) { - log::debug!("Load config: {:?}", config_path); - let bytes = std::fs::read(&config_path); - let cfg: Option = match bytes { - Ok(bytes) => { - let cfg = toml::from_slice(&bytes); - match cfg { - Ok(cfg) => Some(cfg), - Err(e) => { - eprintln!("Toml parse error for {:?}: {}", &config_path, e); - Config::halt_and_confirm("loaded"); - None - } + return None; + } + log::debug!("Load config: {:?}", config_path); + let bytes = std::fs::read(&config_path); + let cfg: Option = match bytes { + Ok(bytes) => { + let cfg = toml::from_slice(&bytes); + match cfg { + Ok(cfg) => Some(cfg), + Err(e) => { + eprintln!("Toml parse error for {:?}: {}", &config_path, e); + Config::halt_and_confirm("loaded"); + None } } - Err(e) => { - eprintln!("Could not read {:?}: {}", &config_path, e); - Config::halt_and_confirm("loaded"); - None - } - }; - cfg - } else { - None - } + } + Err(e) => { + eprintln!("Could not read {:?}: {}", &config_path, e); + Config::halt_and_confirm("loaded"); + None + } + }; + cfg } fn halt_and_confirm(config_type: &'static str) { From 43470ccaf382fae3b1ebc2fbc85c5c5dcdc75e56 Mon Sep 17 00:00:00 2001 From: Alexander Brevig Date: Mon, 26 Sep 2022 02:10:39 +0200 Subject: [PATCH 15/16] fix: default to loading configs --- book/src/configuration.md | 4 ++-- helix-view/src/editor.rs | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/book/src/configuration.md b/book/src/configuration.md index 437d553cce23..e6f8c0d1a38c 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -236,8 +236,8 @@ character = "╎" ### `[editor.security]` Section -Opt in to features that may put you at risk. +Features that the paranoid among us may choose to disable. | Key | Description | Default | | --- | --- | --- | -| `load-local-config` | Load `config.yaml` from `$PWD/.helix` that will merge with your global configuration. | `false` | +| `load-local-config` | Load `config.yaml` from `$PWD/.helix` that will merge with your global configuration. | `true` | diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index eeb8b1eb6d97..5aa062bf0a4d 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -171,13 +171,21 @@ pub struct Config { pub color_modes: bool, } -#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "kebab-case", default, deny_unknown_fields)] pub struct SecurityConfig { pub load_local_config: bool, //pub load_local_languages: bool, //TODO: implement } +impl Default for SecurityConfig { + fn default() -> Self { + Self { + load_local_config: true, + } + } +} + #[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] #[serde(default, rename_all = "kebab-case", deny_unknown_fields)] pub struct TerminalConfig { From 84b4f12194c6afe2a50f2d1ea44c3408cc499dc3 Mon Sep 17 00:00:00 2001 From: Alexander Brevig Date: Fri, 18 Nov 2022 09:14:45 +0100 Subject: [PATCH 16/16] docs: fix typos --- book/src/configuration.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/book/src/configuration.md b/book/src/configuration.md index e6f8c0d1a38c..eba6f5f1856e 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -28,7 +28,7 @@ hidden = false You may also specify a file to use for configuration with the `-c` or `--config` CLI argument: `hx -c path/to/custom-config.toml`. -Finally, you can have a `config.toml` local to a project by it under a `.helix` directory in your repository. +Finally, you can have a `config.toml` local to a project by putting it under a `.helix` directory in your repository. Its settings will be merged with the configuration directory `config.toml` and the built-in configuration, if you have enabled the feature under `[editor.security]` in your global configuration. @@ -240,4 +240,4 @@ Features that the paranoid among us may choose to disable. | Key | Description | Default | | --- | --- | --- | -| `load-local-config` | Load `config.yaml` from `$PWD/.helix` that will merge with your global configuration. | `true` | +| `load-local-config` | Load `config.toml` from `$PWD/.helix` that will merge with your global configuration. | `true` |