diff --git a/home/kakoune/latex.kak b/home/kakoune/autoload/latex.kak similarity index 66% rename from home/kakoune/latex.kak rename to home/kakoune/autoload/latex.kak index 9d26277..2e57396 100644 --- a/home/kakoune/latex.kak +++ b/home/kakoune/autoload/latex.kak @@ -10,7 +10,7 @@ provide-module latex-kak %{ define-command -hidden create-begin-block %{ execute-keys "i\begin{b0}\end{b0}" execute-keys "b0" - execute-keys -with-hooks "c" + execute-keys -with-hooks -with-maps "c" hook -once buffer ModeChange .*:normal %{ execute-keys -with-maps "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 "i%arg{1}hZa%arg{2}zli" + execute-keys "i%arg{1}hZa%arg{2}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 ": create-block-with mathbf" # map -docstring "Serif font (mathsf)" global latex-font ": create-block-with mathsf" map -docstring "Math Monospace (mathtt)" global latex-font ": create-block-with mathtt" + map -docstring "Math Fraktur (mathfrak)" global latex-font f ": create-block-with mathfrak" # "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" map -docstring "Example" global latex-insert-block e ": create-begin-block-with example" map -docstring "Proof" global latex-insert-block p ": create-begin-block-with proof" + map -docstring "Remark" global latex-insert-block r ": create-begin-block-with remark" + map -docstring "Proposition" global latex-insert-block ": create-begin-block-with proposition" + map -docstring "Corollary" global latex-insert-block c ": create-begin-block-with corollary" ## Common environments map -docstring "align*" global latex-insert-block a ": create-begin-block-with align*" + map -docstring "align" global latex-insert-block ": create-begin-block-with align" + map -docstring "equation" global latex-insert-block e ": create-begin-block-with equation" + map -docstring "equation*" global latex-insert-block ": create-begin-block-with equation*" map -docstring "Matrix" global latex-insert-block m ": create-begin-block-with bmatrix" map -docstring "Cases" global latex-insert-block C ": create-begin-block-with cases" map -docstring "Table" global latex-insert-block T ": create-begin-block-with tabular" @@ -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 { }" map -docstring "Parentheses" global latex-insert-delims p ": create-delims ( )" map -docstring "Large Parentheses" global latex-insert-delims P ": create-delims \left( \right)" map -docstring "Brackets" global latex-insert-delims b ": create-delims \left[ \right]" map -docstring "Sets" global latex-insert-delims s ": create-delims \{ \}" map -docstring "Large Sets" global latex-insert-delims S ": create-delims \left\{ \right\}" - hook global WinSetOption filetype=(latex) %{ - ## Create inline and display math blocks - map buffer normal "i\(\)hhi" - map buffer insert "\(\)2h" - map buffer normal "i\[\]hhi" - map buffer insert "\[\]2h" - map buffer normal ": enter-user-mode latex-insert-delims" - map buffer insert ": enter-user-mode latex-insert-delims" + ## Create delims (shortcuts) + map buffer normal ": enter-user-mode latex-insert-delimsp" + map buffer insert ": enter-user-mode latex-insert-delimsp" + map buffer normal ": enter-user-mode latex-insert-delimsg" + map buffer insert ": enter-user-mode latex-insert-delimsg" + map buffer normal "i\(\)Zhhi" + map buffer insert "\(\)Z2h" + map buffer normal "i\[\]Zhhi" + map buffer insert "\[\]Z2h" + map buffer normal ": enter-user-mode latex-insert-delims" + map buffer insert ": enter-user-mode latex-insert-delims" - ## Quickly create begin/end blocks - map buffer normal ": create-begin-block" - map buffer insert ": create-begin-block" + ## Quickly create begin/end blocks + map buffer normal ": create-begin-block" + map buffer insert ": create-begin-block" - ## Font menu - map buffer normal ": enter-user-mode latex-font" - map buffer insert ": enter-user-mode latex-font" + ## Font menu + map buffer normal ": enter-user-mode latex-font" + map buffer insert ": enter-user-mode latex-font" - ## Insert menu - map buffer normal ": enter-user-mode latex-insert-block" - map buffer insert ": enter-user-mode latex-insert-block" + ## Insert menu + map buffer normal ": enter-user-mode latex-insert-block" + map buffer insert ": enter-user-mode latex-insert-block" - ## Select math equations and environment blocks - map buffer object e -docstring "Inline Math equation \( \)" "c\\\\\\(,\\\\\\)" - map buffer object E -docstring "Display Math equation \[ \]" "c\\\\\\[,\\\\\\]" - map buffer object v -docstring "Simple environment \env{}" "c\\\\\\w+\\{,\\}" - map buffer object V -docstring "Full environment \begin{env}\end{env}" "c\\\\begin\\{\\w+\\}(?:\\{[\\w\\s]*\\})*(?:\\[[\\w\\s]*\\])*,\\\\end\\{\\w+\\}" + ## Select math equations and environment blocks + map buffer object e -docstring "Inline Math equation \( \)" "c\\\\\\(,\\\\\\)" + map buffer object E -docstring "Display Math equation \[ \]" "c\\\\\\[,\\\\\\]" + map buffer object v -docstring "Simple environment \env{}" "c\\\\\\w+\\{,\\}" + map buffer object V -docstring "Full environment \begin{env}\end{env}" "c\\\\begin\\{\\w+\\}(?:\\{[\\w\\s]*\\})*(?:\\[[\\w\\s]*\\])*,\\\\end\\{\\w+\\}" - ## Quickly get a new item - map buffer normal "o\item " - map buffer insert "o\item " - } + ## Quickly get a new item + map buffer normal "o\item " + map buffer insert "o\item " } diff --git a/home/kakoune/kak.nix b/home/kakoune/kak.nix index 921cab6..93ca582 100644 --- a/home/kakoune/kak.nix +++ b/home/kakoune/kak.nix @@ -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 = - # } ); - # } - ]); + ]; } diff --git a/home/kakoune/kakrc b/home/kakoune/kakrc index 5fce3aa..54d5b34 100644 --- a/home/kakoune/kakrc +++ b/home/kakoune/kakrc @@ -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 ':inc-dec-modify-numbers + %val{count}' map global normal ':inc-dec-modify-numbers - %val{count}' - -# Source any settings in the current working directory, -# recursive upwards -evaluate-commands %sh{ - $kak_config/source-pwd -} diff --git a/home/modules/programs/my-kakoune/default.nix b/home/modules/programs/my-kakoune/default.nix new file mode 100644 index 0000000..5da6e6e --- /dev/null +++ b/home/modules/programs/my-kakoune/default.nix @@ -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))); + }; +} diff --git a/home/kakoune/kak-lsp.nix b/home/modules/programs/my-kakoune/kak-lsp.nix similarity index 99% rename from home/kakoune/kak-lsp.nix rename to home/modules/programs/my-kakoune/kak-lsp.nix index 1f3a234..7018d42 100644 --- a/home/kakoune/kak-lsp.nix +++ b/home/modules/programs/my-kakoune/kak-lsp.nix @@ -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" = {