igor-ramazanov / kak-tree-sitter-helix

Generate kak-tree-sitter grammars, queries and themes using Helix.
6 stars 1 forks source link
helix highlighting kakoune nix-flake tree-sitter

kak-tree-sitter-helix

Python and Nix scripts to generate kak-tree-sitter grammars, queries and themes by relying on Helix repository.

Usage

Nix flakes + home-manager module only for now, because that's what I use.

  1. Add this flake url to flake inputs.
  2. Pass the home-manager module to extraSpecialArgs.
  3. Import it: import = [...];.
  4. In home-manager config file, set programs.kak-tree-sitter-helix.enable = true;

This will:

  1. Add kak-tree-sitter package to your home.packages.
  2. Create $XDG_CONFIG_HOME/kak-tree-sitter/config.toml file.
  3. Create $XDG_CONFIG_HOME/kak/colors dir with themes.
  4. Create $XDG_DATA_DIR/kak-tree-sitter dir with grammars and queries.

Using home-manager as nixos module

# flake.nix
{
  inputs = {
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
    home-manager.url = "github:nix-community/home-manager";
    kak-tree-sitter-helix.inputs.nixpkgs.follows = "nixpkgs";
    kak-tree-sitter-helix.url = "github:igor-ramazanov/kak-tree-sitter-helix";
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  };
  outputs = {
    home-manager,
    kak-tree-sitter-helix,
    nixpkgs,
    self,
  }: {
    nixosConfigurations.MY_PC_HOSTNAME = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ./configuration.nix
        home-manager.nixosModules.home-manager
        {
          home-manager = {
            extraSpecialArgs = {
              inherit (kak-tree-sitter-helix.homeManagerModules.x86_64-linux) kak-tree-sitter-helix;
            };
            users.MY_USERNAME = import ./home-manager.nix;
          };
        }
      ];
    };
  }
}

Using home-manager as standalone option

# flake.nix
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    kak-tree-sitter-helix.url = "github:igor-ramazanov/kak-tree-sitter-helix";
    kak-tree-sitter-helix.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { nixpkgs, home-manager, kak-tree-sitter-helix, ... }:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
    in {
      homeConfigurations."username" = home-manager.lib.homeManagerConfiguration {
        inherit pkgs;
        modules = [ 
        ./home.nix 
        ];
        extraSpecialArgs = {
          inherit (kak-tree-sitter-helix.homeManagerModules.x86_64-linux) kak-tree-sitter-helix;
        };
      };
    };

Then in home.nix or home-manager.nix

{kak-tree-sitter-helix,...}: {
  imports = [kak-tree-sitter-helix];
  programs.kak-tree-sitter-helix.enable = true;
}

Make sure you have the following code somewhere in $XDG_CONFIG_DIR/kak/autoload or in $XDG_CONFIG_DIR/kak/kakrc:

eval %sh{ kak-tree-sitter -dks --init $kak_session }
colorscheme termcolors # Unnecessary, read below.
colorscheme catppuccin-latte # Or any other theme from $XDG_CONFIG_DIR/kak/colors.

For more information on kak-tree-sitter flags visit usage manual.

termcolors.kak

The $XDG_CONFIG_DIR/kak/colors/termcolors.kak opinionatedly sets default Kakoune faces using ANSI terminal colors.\ The reason is that I use Stylix to have consistent theming across the whole NixOS, and termcolors.kak makes the Kakoune UI bit more consistent with the terminal colors.\ I'll remove it in the future once I figure out mapping from Helix to Kakoune's default and UI faces.

Motivation

kak-tree-sitter is an amazing tool that brings the power of tree-sitter to Kakoune.\ However, it requires laboursome configuration to define grammars and themes.\ I would like to recreate Helix-like experience with minimal configuration.

Note

This repo is in a heavy work-in-progress state, consult with the source code first.

Screenshots (outdated)