Compare commits
No commits in common. "1314dce07d2a5c164ab4a89284d4c71bb7cd4917" and "0acc4dbba472491d62125a62439b5cb10611012a" have entirely different histories.
1314dce07d
...
0acc4dbba4
36
rc/tree.kak
36
rc/tree.kak
|
@ -9,11 +9,6 @@ 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
|
||||
|
||||
define-command -hidden tree-command -params 1..2 -docstring %{
|
||||
tree-command <OP_TYPE> [<OP_PARAMS>]
|
||||
Send request to kak-tree and evaluate response.
|
||||
|
@ -54,11 +49,6 @@ define-command tree-select-parent-node -params ..1 -docstring %{
|
|||
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 [<KIND>]
|
||||
Select the closest visible next sibling or next sibling of KIND when provided.
|
||||
|
@ -84,30 +74,6 @@ define-command tree-select-first-child -params ..1 -docstring %{
|
|||
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-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
|
||||
execute-keys <space>
|
||||
}
|
||||
|
||||
|
|
|
@ -52,9 +52,6 @@ impl Config {
|
|||
impl FiletypeConfig {
|
||||
pub fn is_node_visible(&self, node: Node) -> bool {
|
||||
let kind = node.kind();
|
||||
if !node.is_named() {
|
||||
return false;
|
||||
}
|
||||
match &self.whitelist {
|
||||
Some(whitelist) => whitelist.iter().any(|x| x == kind),
|
||||
None => match &self.blacklist {
|
||||
|
|
|
@ -9,32 +9,6 @@ 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 {
|
||||
ranges
|
||||
.iter()
|
||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -23,12 +23,10 @@ struct Request {
|
|||
#[serde(tag = "type")]
|
||||
enum Op {
|
||||
NodeSExp,
|
||||
HighlightCurrentNode,
|
||||
SelectChildren { kind: Option<String> },
|
||||
SelectNextNode { kind: Option<String> },
|
||||
SelectParentNode { kind: Option<String> },
|
||||
SelectPreviousNode { kind: Option<String> },
|
||||
SelectNode,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -107,13 +105,6 @@ fn handle_request(config: &Config, request: &Request) -> String {
|
|||
let mut new_ranges = Vec::new();
|
||||
let filetype_config = config.get_filetype_config(&request.filetype);
|
||||
match &request.op {
|
||||
Op::SelectNode => {
|
||||
for range in &ranges {
|
||||
let node = tree::shrink_to_range(tree.root_node(), range);
|
||||
new_ranges.push(node.range());
|
||||
}
|
||||
kakoune::select_ranges(&buffer, &new_ranges)
|
||||
}
|
||||
Op::SelectParentNode { kind } => {
|
||||
let kinds = kind
|
||||
.as_ref()
|
||||
|
@ -190,13 +181,6 @@ fn handle_request(config: &Config, request: &Request) -> String {
|
|||
let node = tree::shrink_to_range(tree.root_node(), &ranges[0]);
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ pub fn shrink_to_range<'a>(root_node: Node<'a>, range: &Range) -> Node<'a> {
|
|||
for child in parent.children(&mut cursor) {
|
||||
if child.range().start_byte <= range.start_byte
|
||||
&& range.end_byte <= child.range().end_byte
|
||||
&& child.is_named()
|
||||
{
|
||||
node = child;
|
||||
continue 'outer;
|
||||
|
|
Loading…
Reference in New Issue
Block a user