on master help sign in
Load config files from ~/.config/helix, fallback to defaults.
bc4e54cBlaž Hrastnik
Cargo.lock+7
@@ -496,6 +496,7 @@ dependencies = [
496 "tree-sitter",
496 "tree-sitter",
497 "unicode-segmentation",
497 "unicode-segmentation",
498 "unicode-width",
498 "unicode-width",
499+ "xdg",
499]
500]
500
501
501[[package]]
502[[package]]
@@ -1390,3 +1391,9 @@ name = "winapi-x86_64-pc-windows-gnu"
1390version = "0.4.0"
1391version = "0.4.0"
1391source = "registry+https://github.com/rust-lang/crates.io-index"
1392source = "registry+https://github.com/rust-lang/crates.io-index"
1392checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
1393checksum = "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"
21regex = "1"
21regex = "1"
22
22
23serde = { version = "1.0", features = ["derive"] }
23serde = { 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) -
44 None
44 None
45}
45}
46
46
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+
47pub use ropey::{Rope, RopeSlice};
54pub use ropey::{Rope, RopeSlice};
48
55
49pub use tendril::StrTendril as Tendril;
56pub use tendril::StrTendril as Tendril;
helix-term/src/main.rs+9−2
@@ -74,10 +74,17 @@ fn main() {
74 setup_logging(verbosity).expect("failed to initialize logging.");
74 setup_logging(verbosity).expect("failed to initialize logging.");
75
75
76 // initialize language registry
76 // initialize language registry
77+ use helix_core::config_dir;
77 use helix_core::syntax::{Loader, LOADER};
78 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+
79 LOADER.get_or_init(|| {
86 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");
81 Loader::new(config)
88 Loader::new(config)
82 });
89 });
83
90
helix-view/src/editor.rs+7−3
@@ -25,9 +25,13 @@ pub enum Action {
25
25
26impl Editor {
26impl Editor {
27 pub fn new(executor: &'static smol::Executor<'static>, mut area: tui::layout::Rect) -> Self {
27 pub fn new(executor: &'static smol::Executor<'static>, mut area: tui::layout::Rect) -> Self {
28− // TODO: load from config dir
28+ use helix_core::config_dir;
29− let toml = include_str!("../../theme.toml");
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"));
30− let theme: Theme = toml::from_str(&toml).expect("failed to parse theme.toml");
34+ let theme: Theme = toml::from_slice(&toml).expect("failed to parse theme.toml");
31
35
32 let language_servers = helix_lsp::Registry::new();
36 let language_servers = helix_lsp::Registry::new();
33
37