# Path to the kak-tree executable. # 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" # Option to store draft of the current buffer before passing to shell. declare-option -hidden str tree_draft declare-option str tree_highlight_style "black,blue" declare-option -hidden range-specs tree_highlight add-highlighter global/tree_highlight ranges tree_highlight declare-option str tree_quickjump_highlight_style "black,green+F" declare-option -hidden range-specs tree_quickjump_replace add-highlighter global/tree_quickjump_replace replace-ranges tree_quickjump_replace declare-option -hidden range-specs tree_quickjump_highlight add-highlighter global/tree_quickjump_highlight ranges tree_quickjump_highlight declare-option -hidden range-specs tree_quickjump define-command -hidden tree-command -params 1..2 -docstring %{ tree-command [] Send request to kak-tree and evaluate response. } %{ evaluate-commands -draft -no-hooks %{exec '%'; set buffer tree_draft %val{selection}} evaluate-commands %sh{ tree_draft=$(printf '%s.' "${kak_opt_tree_draft}" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed "s/$(printf '\t')/\\\\t/g") tree_draft=${tree_draft%.} printf ' filetype = "%s" selections_desc = "%s" content = """ %s""" [op] type = "%s" %s ' "${kak_opt_filetype}" "${kak_selections_desc}" "${tree_draft}" $1 "$2" | ${kak_opt_tree_cmd} --config "${kak_opt_tree_config}" 2>${kak_opt_tree_log} } } define-command -hidden tree-command-with-optional-kind -params 1..2 -docstring %{ tree-command-with-optional-kind [] Send request which optionally takes node kind. } %{ tree-command %arg{1} %sh{ if [ -n "$2" ]; then printf 'kind = "%s"' "$2" fi } } define-command tree-select-parent-node -params ..1 -docstring %{ tree-select-parent-node [] Select the closest visible ancestor or ancestor of KIND when provided. } %{ tree-command-with-optional-kind SelectParentNode %arg{1} } define-command tree-select-node -docstring %{ tree-select-node Select the closest visible node } %{ tree-command-with-optional-kind SelectNode } define-command tree-select-next-node -params ..1 -docstring %{ tree-select-next-node [] Select the closest visible next sibling or next sibling of KIND when provided. } %{ tree-command-with-optional-kind SelectNextNode %arg{1} } define-command tree-select-previous-node -params ..1 -docstring %{ tree-select-previous-node [] Select the closest visible previous sibling or previous sibling of KIND when provided. } %{ tree-command-with-optional-kind SelectPreviousNode %arg{1} } define-command tree-select-children -params ..1 -docstring %{ tree-select-children [] Select all immediate visible children or all descendants matching KIND when provided. } %{ tree-command-with-optional-kind SelectChildren %arg{1} } define-command tree-node-sexp -docstring %{ tree-node-sexp Show info box with a syntax tree of the main selection parent. } %{ tree-command NodeSExp } define-command tree-select-first-child -params ..1 -docstring %{ tree-select-first-child [] Select the first immediate visible children or the first descendant matching KIND when provided. } %{ tree-command-with-optional-kind SelectChildren %arg{1} execute-keys , } define-command tree-quickjump -params 1 -docstring %{ tree-quickjump [] Opens a menu to jump to a node of the specified kind } %{ tree-command-with-optional-kind QuickJump %arg{1} # We have now set the tree_quickjump variable to contain each location to jump to prompt -menu \ -shell-script-candidates 'IFS=" "; for entry in $kak_opt_tree_quickjump ; do echo "${entry#*|}" ; done' "Jump to " \ -on-abort %{ set-option buffer tree_quickjump "%val{timestamp}" set-option buffer tree_quickjump_highlight "%val{timestamp}" set-option buffer tree_quickjump_replace "%val{timestamp}" } \ %{evaluate-commands %sh{ # loop through tree_quickjump to find the corresponding selection IFS=" " for entry in $kak_opt_tree_quickjump ; do echo "echo -debug \"testing $entry ($kak_text)\"" [ "$entry" = "${entry%|$kak_text}" ] && continue echo "echo -debug \"yes\"" echo "select ${entry%|$kak_text}" done echo 'set-option buffer tree_quickjump "%val{timestamp}"' echo 'set-option buffer tree_quickjump_highlight "%val{timestamp}"' echo 'set-option buffer tree_quickjump_replace "%val{timestamp}"' } } } define-command tree-node-highlight -docstring %{ tree-node-highlight Highlight the current node using the tree_highlight_style face } %{ tree-command HighlightCurrentNode } define-command tree-node-clear-highlight -docstring %{ tree-node-clear-highlight Removes any highlight } %{ set-option buffer tree_highlight %val{timestamp} } define-command tree-always-highlight -docstring %{ Highlight the current node at all times, as the cursor moves } %{ hook -group tree-always-highlight global RawKey .* tree-node-highlight hook -group tree-always-highlight global BufNewFile .* tree-node-highlight hook -group tree-always-highlight global BufOpenFile .* tree-node-highlight } define-command tree-always-highlight-disable -docstring %{ Stop highlighting the cursor } %{ remove-hooks global tree-always-highlight tree-node-clear-highlight }