2023-11-12 00:21:50 +01:00
|
|
|
# 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"
|
|
|
|
|
2023-11-12 22:54:56 +01:00
|
|
|
# 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" }
|
|
|
|
|
2023-11-12 00:21:50 +01:00
|
|
|
# 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
|
|
|
|
|
2023-11-12 17:26:31 +01:00
|
|
|
declare-option str tree_highlight_style "black,blue"
|
|
|
|
|
|
|
|
declare-option -hidden range-specs tree_highlight
|
|
|
|
add-highlighter global/tree_highlight ranges tree_highlight
|
|
|
|
|
2023-12-19 18:42:30 +01:00
|
|
|
declare-option str tree_quickjump_highlight_style "black,green+F"
|
2023-12-19 18:26:43 +01:00
|
|
|
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
|
|
|
|
|
2023-11-12 00:21:50 +01:00
|
|
|
define-command -hidden tree-command -params 1..2 -docstring %{
|
|
|
|
tree-command <OP_TYPE> [<OP_PARAMS>]
|
|
|
|
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
|
2023-11-12 22:54:56 +01:00
|
|
|
' "${kak_opt_filetype}" "${kak_selections_desc}" "${tree_draft}" $1 "$2" | ${kak_opt_tree_cmd} --config "${kak_opt_tree_config}" 2>${kak_opt_tree_log}
|
2023-11-12 00:21:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
define-command -hidden tree-command-with-optional-kind -params 1..2 -docstring %{
|
|
|
|
tree-command-with-optional-kind <OP_TYPE> [<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 [<KIND>]
|
|
|
|
Select the closest visible ancestor or ancestor of KIND when provided.
|
|
|
|
} %{ tree-command-with-optional-kind SelectParentNode %arg{1} }
|
|
|
|
|
2023-11-12 17:26:44 +01:00
|
|
|
define-command tree-select-node -docstring %{
|
|
|
|
tree-select-node
|
|
|
|
Select the closest visible node
|
|
|
|
} %{ tree-command-with-optional-kind SelectNode }
|
|
|
|
|
2023-11-12 00:21:50 +01:00
|
|
|
define-command tree-select-next-node -params ..1 -docstring %{
|
|
|
|
tree-select-next-node [<KIND>]
|
|
|
|
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 [<KIND>]
|
|
|
|
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 [<KIND>]
|
|
|
|
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 [<KIND>]
|
|
|
|
Select the first immediate visible children or the first descendant matching KIND when provided.
|
|
|
|
} %{
|
|
|
|
tree-command-with-optional-kind SelectChildren %arg{1}
|
2023-11-12 17:26:31 +01:00
|
|
|
execute-keys ,
|
|
|
|
}
|
|
|
|
|
2023-12-19 18:26:43 +01:00
|
|
|
define-command tree-quickjump -params 1 -docstring %{
|
|
|
|
tree-quickjump [<KIND>]
|
|
|
|
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}"'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-12 17:26:31 +01:00
|
|
|
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
|
2023-11-12 20:20:20 +01:00
|
|
|
hook -group tree-always-highlight global BufNewFile .* tree-node-highlight
|
|
|
|
hook -group tree-always-highlight global BufOpenFile .* tree-node-highlight
|
2023-11-12 17:26:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
define-command tree-always-highlight-disable -docstring %{
|
|
|
|
Stop highlighting the cursor
|
|
|
|
} %{
|
|
|
|
remove-hooks global tree-always-highlight
|
|
|
|
tree-node-clear-highlight
|
2023-11-12 00:21:50 +01:00
|
|
|
}
|
|
|
|
|