on master help sign in
Load config files from ~/.config/helix, fallback to defaults.
commitbc4e54c0c45abbbb5fe9ac3278361d0b4e5774ba authorBlaž Hrastnik <blaz@mxxn.io> dateWed 7 Apr 2021, 23:56 (6 years ago) parentf0d49d3
5 files changed+32−5
Cargo.lock+7 helix-core/Cargo.toml+2 helix-core/src/lib.rs+7 helix-term/src/main.rs+9−2 helix-view/src/editor.rs+7−3
Cargo.lock+7
@@ -496,6 +496,7 @@ dependencies = [
496496 "tree-sitter",
497497 "unicode-segmentation",
498498 "unicode-width",
499+ "xdg",
499500]
500501
501502[[package]]
@@ -1390,3 +1391,9 @@ name = "winapi-x86_64-pc-windows-gnu"
13901391version = "0.4.0"
13911392source = "registry+https://github.com/rust-lang/crates.io-index"
13921393checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
1394+
1395+[[package]]
1396+name = "xdg"
1397+version = "2.2.0"
1398+source = "registry+https://github.com/rust-lang/crates.io-index"
1399+checksum = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57"
helix-core/Cargo.toml+2
@@ -21,3 +21,5 @@ once_cell = "1.4"
2121regex = "1"
2222
2323serde = { version = "1.0", features = ["derive"] }
24+
25+xdg = "2.0"
helix-core/src/lib.rs+7
@@ -44,6 +44,13 @@ pub(crate) fn find_first_non_whitespace_char(text: RopeSlice, line_num: usize) -
4444 None
4545}
4646
47+pub fn config_dir() -> std::path::PathBuf {
48+ // TODO: allow env var override
49+ let xdg_dirs =
50+ xdg::BaseDirectories::with_prefix("helix").expect("Unable to find XDG directories!");
51+ xdg_dirs.get_config_home()
52+}
53+
4754pub use ropey::{Rope, RopeSlice};
4855
4956pub use tendril::StrTendril as Tendril;
helix-term/src/main.rs+9−2
@@ -74,10 +74,17 @@ fn main() {
7474 setup_logging(verbosity).expect("failed to initialize logging.");
7575
7676 // initialize language registry
77+ use helix_core::config_dir;
7778 use helix_core::syntax::{Loader, LOADER};
78− let toml = include_str!("../../languages.toml");
79+
80+ // load $HOME/.config/helix/languages.toml, fallback to default config
81+ let config = std::fs::read(config_dir().join("languages.toml"));
82+ let toml = config
83+ .as_deref()
84+ .unwrap_or(include_bytes!("../../languages.toml"));
85+
7986 LOADER.get_or_init(|| {
80− let config = toml::from_str(toml).expect("Could not parse languages.toml");
87+ let config = toml::from_slice(toml).expect("Could not parse languages.toml");
8188 Loader::new(config)
8289 });
8390
helix-view/src/editor.rs+7−3
@@ -25,9 +25,13 @@ pub enum Action {
2525
2626impl Editor {
2727 pub fn new(executor: &'static smol::Executor<'static>, mut area: tui::layout::Rect) -> Self {
28− // TODO: load from config dir
29− let toml = include_str!("../../theme.toml");
30− let theme: Theme = toml::from_str(&toml).expect("failed to parse theme.toml");
28+ use helix_core::config_dir;
29+ let config = std::fs::read(config_dir().join("theme.toml"));
30+ // load $HOME/.config/helix/theme.toml, fallback to default config
31+ let toml = config
32+ .as_deref()
33+ .unwrap_or(include_bytes!("../../theme.toml"));
34+ let theme: Theme = toml::from_slice(&toml).expect("failed to parse theme.toml");
3135
3236 let language_servers = helix_lsp::Registry::new();
3337