Skip to content

JasonBrownDeveloper/Acorn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Acorn

Leverages Tree-sitter to do more than syntax highlighting.

Built on top of danr's fork of tomKPZ's pykak, Acorn uses py-tree-sitter to integrate Tree-sitter utility into Kakoune.

Features

  • Syntax highlighting
  • Custom highlight queries
  • Finer grain coloring
  • Custom post processing for additional logic
  • Navigation by tag

Prerequisites

Install Python 3. pip install py-tree-sitter and any languages you wish to support (e.g. tree-sitter-c). Clone pykak and source it in your kakrc or link it to your autoload folder. At the time of writing some additional changes are needed from this pull request.

Installation

Clone Acorn and source it in your kakrc or link it to your autoload folder.

Configuring

Once the module is loaded, AcornBegin can be set to initialize the configuration. acorn_state is a dictionary of configuration and state information that stays persistent in the accompanying pykak python instance.

hook global ModuleLoaded acorn %{

set-option global AcornBegin %{
global acorn_state
...
}  }

Syntax highlighting

Tree-sitter grammars should be registered in the 'filetype' key.

acorn_state[ 'filetype' ].setdefault( 'c', {} )
acorn_state[ 'filetype' ][ 'c' ][ 'module' ] = 'tree_sitter_c'

Custom highlight queries

Most grammars provide a highlight query but you may want to define your own.

acorn_state[ 'filetype' ][ 'c' ][ 'highlights_query' ] = """
    (identifier) @variable
...
    ((comment) @comment_line
     (#match? @comment_line "^//"))
    ((comment) @comment_block
     (#match? @comment_block "^/\*"))
    """

Finer grain coloring

Tree-sitter highlight queries generate more precision than traditional syntax highlighting strategies. We can leverage that to create more targeted coloring.

set-face global comment_line        "rgb:%opt{green_40}"
set-face global comment_block       "rgb:%opt{green_30}"

Custom post processing for additional logic

Acorn can run a post-processing python function to highlight based on arbitrary rules. The function will be called once for each node in the tree. State between calls can be stored in acorn_state as needed. See included kakrc for an example.

Navigation by tag

Most grammars will also provide a tags query. This will typically mark high level structures (e.g. function and class definitions). Acorn will allow you to cycle through each tag.

map -docstring 'Next tagged name' global user j ': acorn_next_tag<ret>'
map -docstring 'Previous tagged name' global user k ': acorn_prev_tag<ret>'

About

Kakoune Tree-sitter integration via pykak and py-tree-sitter

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors