Restructure kakoune configuration

This commit is contained in:
Natsu Kagami 2022-01-12 15:55:53 -05:00
parent 801622b7be
commit d5989c525c
Signed by: nki
GPG key ID: 7306B3D3C3AD6E51
5 changed files with 135 additions and 82 deletions

View file

@ -10,7 +10,7 @@ provide-module latex-kak %{
define-command -hidden create-begin-block %{
execute-keys "<esc>i\begin{b0}<ret>\end{b0}<esc>"
execute-keys "<a-/>b0<ret><a-N>"
execute-keys -with-hooks "c"
execute-keys -with-hooks -with-maps "c"
hook -once buffer ModeChange .*:normal %{
execute-keys -with-maps "<space>gl"
}
@ -24,7 +24,8 @@ provide-module latex-kak %{
}
# Create a \param{} block and put the cursor in the middle.
define-command -params 2 -hidden create-delims %{
execute-keys "<esc>i%arg{1}<esc>hZa%arg{2}<esc>zli"
execute-keys "<esc>i%arg{1}<esc>hZa%arg{2}<esc>zl"
execute-keys -with-hooks -with-maps "i"
}
define-command -params 1 create-block-with %{
create-delims "\%arg{1}{" "}"
@ -58,6 +59,7 @@ provide-module latex-kak %{
# map -docstring "Math Bold (mathbf)" global latex-font <a-B> ": create-block-with mathbf<ret>"
# map -docstring "Serif font (mathsf)" global latex-font <a-s> ": create-block-with mathsf<ret>"
map -docstring "Math Monospace (mathtt)" global latex-font <a-m> ": create-block-with mathtt<ret>"
map -docstring "Math Fraktur (mathfrak)" global latex-font f ": create-block-with mathfrak<ret>"
# "Insert block" menu
declare-user-mode latex-insert-block
@ -70,8 +72,14 @@ provide-module latex-kak %{
map -docstring "Lemma" global latex-insert-block l ": create-begin-block-with lemma<ret>"
map -docstring "Example" global latex-insert-block e ": create-begin-block-with example<ret>"
map -docstring "Proof" global latex-insert-block p ": create-begin-block-with proof<ret>"
map -docstring "Remark" global latex-insert-block r ": create-begin-block-with remark<ret>"
map -docstring "Proposition" global latex-insert-block <a-p> ": create-begin-block-with proposition<ret>"
map -docstring "Corollary" global latex-insert-block c ": create-begin-block-with corollary<ret>"
## Common environments
map -docstring "align*" global latex-insert-block a ": create-begin-block-with align*<ret>"
map -docstring "align" global latex-insert-block <a-a> ": create-begin-block-with align<ret>"
map -docstring "equation" global latex-insert-block e ": create-begin-block-with equation<ret>"
map -docstring "equation*" global latex-insert-block <a-e> ": create-begin-block-with equation*<ret>"
map -docstring "Matrix" global latex-insert-block m ": create-begin-block-with bmatrix<ret>"
map -docstring "Cases" global latex-insert-block C ": create-begin-block-with cases<ret>"
map -docstring "Table" global latex-insert-block T ": create-begin-block-with tabular<ret>"
@ -80,42 +88,45 @@ provide-module latex-kak %{
# Pairs of delimiters
declare-user-mode latex-insert-delims
map -docstring "Grouping" global latex-insert-delims g ": create-delims { }<ret>"
map -docstring "Parentheses" global latex-insert-delims p ": create-delims ( )<ret>"
map -docstring "Large Parentheses" global latex-insert-delims P ": create-delims \left( \right)<ret>"
map -docstring "Brackets" global latex-insert-delims b ": create-delims \left[ \right]<ret>"
map -docstring "Sets" global latex-insert-delims s ": create-delims \{ \}<ret>"
map -docstring "Large Sets" global latex-insert-delims S ": create-delims \left\{ \right\}<ret>"
hook global WinSetOption filetype=(latex) %{
## Create inline and display math blocks
map buffer normal <a-3> "i\(\)<esc>hhi"
map buffer insert <a-3> "\(\)<a-;>2h"
map buffer normal <a-4> "i\[\]<esc>hhi"
map buffer insert <a-4> "\[\]<a-;>2h"
map buffer normal <a-5> ": enter-user-mode latex-insert-delims<ret>"
map buffer insert <a-5> "<esc>: enter-user-mode latex-insert-delims<ret>"
## Create delims (shortcuts)
map buffer normal <a-1> ": enter-user-mode latex-insert-delims<ret>p"
map buffer insert <a-1> "<esc>: enter-user-mode latex-insert-delims<ret>p"
map buffer normal <a-2> ": enter-user-mode latex-insert-delims<ret>g"
map buffer insert <a-2> "<esc>: enter-user-mode latex-insert-delims<ret>g"
map buffer normal <a-3> "i\(\)<esc>Zhhi"
map buffer insert <a-3> "\(\)<a-;>Z<a-;>2h"
map buffer normal <a-4> "i\[\]<esc>Zhhi"
map buffer insert <a-4> "\[\]<a-;>Z<a-;>2h"
map buffer normal <a-5> ": enter-user-mode latex-insert-delims<ret>"
map buffer insert <a-5> "<esc>: enter-user-mode latex-insert-delims<ret>"
## Quickly create begin/end blocks
map buffer normal <c-n> ": create-begin-block<ret>"
map buffer insert <c-n> "<esc>: create-begin-block<ret>"
## Quickly create begin/end blocks
map buffer normal <c-n> ": create-begin-block<ret>"
map buffer insert <c-n> "<esc>: create-begin-block<ret>"
## Font menu
map buffer normal <c-b> ": enter-user-mode latex-font<ret>"
map buffer insert <c-b> "<esc>: enter-user-mode latex-font<ret>"
## Font menu
map buffer normal <c-b> ": enter-user-mode latex-font<ret>"
map buffer insert <c-b> "<esc>: enter-user-mode latex-font<ret>"
## Insert menu
map buffer normal <a-b> ": enter-user-mode latex-insert-block<ret>"
map buffer insert <a-b> "<esc>: enter-user-mode latex-insert-block<ret>"
## Insert menu
map buffer normal <a-b> ": enter-user-mode latex-insert-block<ret>"
map buffer insert <a-b> "<esc>: enter-user-mode latex-insert-block<ret>"
## Select math equations and environment blocks
map buffer object e -docstring "Inline Math equation \( \)" "c\\\\\\(,\\\\\\)<ret>"
map buffer object E -docstring "Display Math equation \[ \]" "c\\\\\\[,\\\\\\]<ret>"
map buffer object v -docstring "Simple environment \env{}" "c\\\\\\w+\\{,\\}<ret>"
map buffer object V -docstring "Full environment \begin{env}\end{env}" "c\\\\begin\\{\\w+\\}(?:\\{[\\w\\s]*\\})*(?:\\[[\\w\\s]*\\])*,\\\\end\\{\\w+\\}<ret>"
## Select math equations and environment blocks
map buffer object e -docstring "Inline Math equation \( \)" "c\\\\\\(,\\\\\\)<ret>"
map buffer object E -docstring "Display Math equation \[ \]" "c\\\\\\[,\\\\\\]<ret>"
map buffer object v -docstring "Simple environment \env{}" "c\\\\\\w+\\{,\\}<ret>"
map buffer object V -docstring "Full environment \begin{env}\end{env}" "c\\\\begin\\{\\w+\\}(?:\\{[\\w\\s]*\\})*(?:\\[[\\w\\s]*\\])*,\\\\end\\{\\w+\\}<ret>"
## Quickly get a new item
map buffer normal <a-o> "o\item "
map buffer insert <a-ret> "<esc>o\item "
}
## Quickly get a new item
map buffer normal <a-o> "o\item "
map buffer insert <a-ret> "<esc>o\item "
}

View file

@ -17,47 +17,35 @@ let
};
});
};
# record a file in the kakoune folder
kakouneFile = filename: {
name = "kakoune/${filename}";
value = {
source = ./. + "/${filename}";
target = ".config/kak/${filename}";
};
};
kakouneAutoload = { name, src }: {
name = "kakoune/autoload/${name}";
value = {
source = src;
target = ".config/kak/autoload/${name}";
};
};
in
{
imports = [ ./kak-lsp.nix ];
imports = [ ../modules/programs/my-kakoune ];
# Enable the kakoune package.
home.packages = [ kakounePkg ];
# Enable kak-lsp
programs.my-kakoune.enable = true;
programs.kak-lsp.enable = true;
# Source the kakrc we have here.
home.file = builtins.listToAttrs (map kakouneFile [
"kakrc"
"latex.kak"
"source-pwd"
programs.my-kakoune.package = kakounePkg;
programs.my-kakoune.rc =
builtins.readFile ./kakrc + ''
# autoload files
"autoload/markdown.kak"
] ++ map kakouneAutoload [
# include the original autoload files
# Source any settings in the current working directory,
# recursive upwards
evaluate-commands %sh{
${pkgs.writeScript "source-pwd" (builtins.readFile ./source-pwd)}
}
'';
programs.my-kakoune.autoload = [
# My own scripts
{
name = "rc";
src = "${kakounePkg}/share/kak/autoload";
name = "latex.kak";
src = ./autoload/latex.kak;
}
{
name = "markdown.kak";
src = ./autoload/markdown.kak;
}
# Plugins
{
name = "fzf.kak";
@ -105,11 +93,5 @@ in
narHash = "sha256-IcxFmvG0jqpMCG/dT9crVRgPgMGKkic6xwrnW5z4+bc=";
}) + "/rc";
}
# {
# name = "kakoune-text-objects";
# sec = (builtins.fetchTree {
# type =
# } );
# }
]);
];
}

View file

@ -102,7 +102,7 @@ hook global WinSetOption filetype=(racket|rust|python|go|javascript|typescript|c
# lsp-auto-hover-insert-mode-enable
set buffer lsp_hover_anchor true
}
hook global WinSetOption filetype=(racket|rust|python|go|javascript|typescript|c|cpp|tex|latex|haskell) %{
hook global WinSetOption filetype=(racket|rust|python|go|javascript|typescript|c|cpp|tex|latex|haskell|nix) %{
# Format the document if possible
hook window BufWritePre .* %{ lsp-formatting }
}
@ -146,6 +146,10 @@ hook global WinSetOption filetype=(rust) %{
set-option buffer makecmd "cargo check"
}
hook global WinSetOption filetype=(tex|latex) %{
require-module latex-kak
}
def -hidden insert-c-n %{
try %{
lsp-snippets-select-next-placeholders
@ -173,16 +177,5 @@ hook global BufOpenFile .* %{
modeline-parse
}
source "%val{config}/latex.kak"
require-module latex-kak
# source "%val{config}/plugins/plug.kak/rc/plug.kak"
map global normal <a-[> ':inc-dec-modify-numbers + %val{count}<ret>'
map global normal <a-]> ':inc-dec-modify-numbers - %val{count}<ret>'
# Source any settings in the current working directory,
# recursive upwards
evaluate-commands %sh{
$kak_config/source-pwd
}

View file

@ -0,0 +1,67 @@
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.programs.my-kakoune;
autoloadModule = types.submodule {
options = {
name = mkOption {
type = types.str;
description = "Name of the autoload script/folder. It might affect kakoune's load order.";
};
src = mkOption {
type = types.path;
description = "Path to the autoload script/folder.";
};
};
};
in
{
imports = [ ./kak-lsp.nix ];
options.programs.my-kakoune = {
enable = mkEnableOption "My version of the kakoune configuration";
package = mkOption {
type = types.package;
default = pkgs.kakoune;
description = "The kakoune package to be installed";
};
rc = mkOption {
type = types.lines;
default = "";
description = "Content of the kakrc file. A line-concatenated string";
};
autoload = mkOption {
type = types.listOf autoloadModule;
default = [ ];
description = "Sources to autoload";
};
};
config = mkIf cfg.enable {
home.packages = [ cfg.package ];
home.file =
let
kakouneAutoload = { name, src }: {
name = "kakoune/autoload/${name}";
value = {
source = src;
target = ".config/kak/autoload/${name}";
};
};
in
{
# kakrc
".config/kak/kakrc".text = cfg.rc;
} //
(builtins.listToAttrs (map kakouneAutoload ([
# include the original autoload files
{
name = "rc";
src = "${cfg.package}/share/kak/autoload";
}
] ++ cfg.autoload)));
};
}

View file

@ -230,7 +230,7 @@ in
enable = mkEnableOption "Enable kak-lsp support";
package = mkOption {
type = types.derivation;
type = types.package;
default = kak-lsp;
};
@ -260,7 +260,7 @@ in
};
config = mkIf cfg.enable {
home.packages = [ kak-lsp ];
home.packages = [ cfg.package ];
# Configurations
xdg.configFile."kak-lsp/kak-lsp.toml" = {