Highlight current node
This commit is contained in:
parent
0acc4dbba4
commit
a78febec6c
31
rc/tree.kak
31
rc/tree.kak
|
@ -9,6 +9,11 @@ declare-option str tree_log "/tmp/kak-tree.log"
|
||||||
# Option to store draft of the current buffer before passing to shell.
|
# Option to store draft of the current buffer before passing to shell.
|
||||||
declare-option -hidden str tree_draft
|
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
|
||||||
|
|
||||||
define-command -hidden tree-command -params 1..2 -docstring %{
|
define-command -hidden tree-command -params 1..2 -docstring %{
|
||||||
tree-command <OP_TYPE> [<OP_PARAMS>]
|
tree-command <OP_TYPE> [<OP_PARAMS>]
|
||||||
Send request to kak-tree and evaluate response.
|
Send request to kak-tree and evaluate response.
|
||||||
|
@ -74,6 +79,30 @@ define-command tree-select-first-child -params ..1 -docstring %{
|
||||||
Select the first immediate visible children or the first descendant matching KIND when provided.
|
Select the first immediate visible children or the first descendant matching KIND when provided.
|
||||||
} %{
|
} %{
|
||||||
tree-command-with-optional-kind SelectChildren %arg{1}
|
tree-command-with-optional-kind SelectChildren %arg{1}
|
||||||
execute-keys <space>
|
execute-keys ,
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
tree-node-highlight
|
||||||
|
}
|
||||||
|
|
||||||
|
define-command tree-always-highlight-disable -docstring %{
|
||||||
|
Stop highlighting the cursor
|
||||||
|
} %{
|
||||||
|
remove-hooks global tree-always-highlight
|
||||||
|
tree-node-clear-highlight
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,32 @@ pub fn select_ranges(buffer: &[String], ranges: &[Range]) -> String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn highlight_ranges(buffer: &[String], ranges: &[Range]) -> String {
|
||||||
|
format!("set-option buffer tree_highlight %val{{timestamp}} {}", ranges_to_range_desc(&buffer, &ranges, "%opt{tree_highlight_style}".to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ranges_to_range_desc(buffer: &[String], ranges: &[Range], string: String) -> String {
|
||||||
|
ranges
|
||||||
|
.iter()
|
||||||
|
.map(|range| {
|
||||||
|
let mut end_row = range.end_point.row;
|
||||||
|
let mut end_column = range.end_point.column;
|
||||||
|
if end_column > 0 {
|
||||||
|
end_column -= 1;
|
||||||
|
} else {
|
||||||
|
end_row -= 1;
|
||||||
|
end_column = 1_000_000;
|
||||||
|
}
|
||||||
|
format!(
|
||||||
|
"\"{},{}|{}\"",
|
||||||
|
point_to_kak_coords(buffer, range.start_point),
|
||||||
|
point_to_kak_coords(buffer, Point::new(end_row, end_column)),
|
||||||
|
string,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.join(" ")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn ranges_to_selections_desc(buffer: &[String], ranges: &[Range]) -> String {
|
pub fn ranges_to_selections_desc(buffer: &[String], ranges: &[Range]) -> String {
|
||||||
ranges
|
ranges
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -23,6 +23,7 @@ struct Request {
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
enum Op {
|
enum Op {
|
||||||
NodeSExp,
|
NodeSExp,
|
||||||
|
HighlightCurrentNode,
|
||||||
SelectChildren { kind: Option<String> },
|
SelectChildren { kind: Option<String> },
|
||||||
SelectNextNode { kind: Option<String> },
|
SelectNextNode { kind: Option<String> },
|
||||||
SelectParentNode { kind: Option<String> },
|
SelectParentNode { kind: Option<String> },
|
||||||
|
@ -181,6 +182,13 @@ fn handle_request(config: &Config, request: &Request) -> String {
|
||||||
let node = tree::shrink_to_range(tree.root_node(), &ranges[0]);
|
let node = tree::shrink_to_range(tree.root_node(), &ranges[0]);
|
||||||
format!("info '{}'", node.to_sexp())
|
format!("info '{}'", node.to_sexp())
|
||||||
}
|
}
|
||||||
|
Op::HighlightCurrentNode => {
|
||||||
|
for range in &ranges {
|
||||||
|
let node = tree::shrink_to_range(tree.root_node(), range);
|
||||||
|
new_ranges.push(node.range());
|
||||||
|
}
|
||||||
|
kakoune::highlight_ranges(&buffer, &new_ranges)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user