diff --git a/rc/default_config.toml b/rc/default_config.toml new file mode 100644 index 0000000..f9204c3 --- /dev/null +++ b/rc/default_config.toml @@ -0,0 +1,8 @@ +[filetype.rust] +group.identifier = ["identifier", "scoped_identifier"] +group.function = ["function_item"] +group.declaration = ["function_item", "struct_item", "enum_item"] +group.call = ["macro_invocation", "call_expression"] +group.arguments = ["arguments", "token_tree"] +group.statement = ["expression_statement", "let_declaration"] + diff --git a/rc/tree.kak b/rc/tree.kak index 1367159..348aa8c 100644 --- a/rc/tree.kak +++ b/rc/tree.kak @@ -1,8 +1,10 @@ # Path to the kak-tree executable. -# To load config: set-option global tree_cmd "kak-tree --config /path/to/kak-tree.toml" # To enable debug logging: set-option global tree_cmd "kak-tree -vvv" declare-option str tree_cmd "kak-tree" +# Path to the config file. Defaults to the built-in file default_config.toml +declare-option str tree_config %sh{ printf "$(dirname ${kak_source})/default_config.toml" } + # Path to the log file. declare-option str tree_log "/tmp/kak-tree.log" @@ -33,7 +35,7 @@ content = """ [op] type = "%s" %s -' "${kak_opt_filetype}" "${kak_selections_desc}" "${tree_draft}" $1 "$2" | ${kak_opt_tree_cmd} 2>${kak_opt_tree_log} +' "${kak_opt_filetype}" "${kak_selections_desc}" "${tree_draft}" $1 "$2" | ${kak_opt_tree_cmd} --config "${kak_opt_tree_config}" 2>${kak_opt_tree_log} } } diff --git a/src/config.rs b/src/config.rs index 1ef53a2..1536de0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -31,8 +31,8 @@ impl Default for Config { impl Config { pub fn load>(path: P) -> Option { - let config = std::fs::read_to_string(path).ok()?; - let mut config: Config = toml::from_str(&config).ok()?; + let config = std::fs::read_to_string(&path).map_err(|e| { eprintln!("Could not open config {}", path.as_ref().display()); e}).ok()?; + let mut config: Config = toml::from_str(&config).map_err(|e| { eprintln!("Could not read config: {e}"); e}).ok()?; if config.filetype.get("default").is_none() { config .filetype