From 7903d53ba0f242831c9936a984d7fca33b0fc6d6 Mon Sep 17 00:00:00 2001 From: Filippo Berto Date: Fri, 24 Sep 2021 09:27:13 +0200 Subject: [PATCH] Add formatters --- home.nix | 2 +- modules/kakoune.nix | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/home.nix b/home.nix index 563d3d1..69e3ea4 100644 --- a/home.nix +++ b/home.nix @@ -129,7 +129,7 @@ in # ./modules/bspwm.nix ./modules/dircolors.nix ./modules/direnv.nix - ./modules/dunst.nix + # ./modules/dunst.nix # ./modules/fzf.nix ./modules/git.nix ./modules/go.nix diff --git a/modules/kakoune.nix b/modules/kakoune.nix index 50c7bde..3ed2f42 100644 --- a/modules/kakoune.nix +++ b/modules/kakoune.nix @@ -115,29 +115,40 @@ in enable = true; highlightCursor = true; }; - keyMappings = [ + keyMappings = with pkgs; [ { mode = "normal"; docstring = "Edit file"; key = ""; effect = ":edit"; } { mode = "user"; docstring = "Code actions"; key = "a"; effect = ":lsp-code-actions"; } { mode = "user"; docstring = "Comment block"; key = "b"; effect = ":comment-block"; } { mode = "user"; docstring = "Comment line"; key = "l"; effect = ":comment-line"; } - { mode = "user"; docstring = "Copy to clipboard"; key = "y"; effect = "${pkgs.xclip}/bin/xclip -i -selection clipboard"; } - { mode = "user"; docstring = "Format code"; key = "F"; effect = ":lsp-formatting-sync"; } + { mode = "user"; docstring = "Copy to clipboard"; key = "y"; effect = "${xclip}/bin/xclip -i -selection clipboard"; } + { mode = "user"; docstring = "Format code with formatter"; key = "f"; effect = ":format"; } + { mode = "user"; docstring = "Format code with LSP"; key = "F"; effect = ":lsp-formatting-sync"; } { mode = "user"; docstring = "Jump to definition"; key = "d"; effect = ":lsp-definition"; } { mode = "user"; docstring = "Jump to type definition"; key = "t"; effect = ":lsp-type-definition"; } { mode = "user"; docstring = "List project diagnostics"; key = "i"; effect = ":lsp-diagnostics"; } - { mode = "user"; docstring = "Paste from clipboard (after)"; key = "P"; effect = "${pkgs.xclip}/bin/xclip -selection clipboard -o"; } - { mode = "user"; docstring = "Paste from clipboard (before)"; key = "p"; effect = "!${pkgs.xclip}/bin/xclip -selection clipboard -o"; } + { mode = "user"; docstring = "Paste from clipboard (after)"; key = "P"; effect = "${xclip}/bin/xclip -selection clipboard -o"; } + { mode = "user"; docstring = "Paste from clipboard (before)"; key = "p"; effect = "!${xclip}/bin/xclip -selection clipboard -o"; } { mode = "user"; docstring = "Show hover info"; key = "q"; effect = ":lsp-hover"; } { mode = "user"; docstring = "Spellcheck English"; key = "S"; effect = ":spell en"; } { mode = "user"; docstring = "Spellcheck"; key = "s"; effect = ":spell "; } { mode = "normal"; docstring = "Try next snippet placeholder"; key = ""; effect = ": insert-c-n"; } ]; - hooks = [ + hooks = with pkgs; [ { name = "BufCreate"; option = ".*"; commands = "editorconfig-load"; } { name = "ModuleLoaded"; option = "auto-pairs"; commands = "auto-pairs-enable"; } { name = "ModuleLoaded"; option = "powerline"; commands = builtins.concatStringsSep "\n" [ "powerline-enable" ]; } # { name = "WinSetOption"; option = "filetype=(rust|python|c|cpp|latex|javascript|go|nix)"; commands = builtins.concatStringsSep "\n" [ "lsp-enable-window" ]; } - ]; + ] ++ ( + lib.optionals cfg.enableLatexSupport [ + { name = "BufSetOption"; option = "filetype=latex"; commands = "set-option buffer formatcmd ${texlive.bin.latexindent}/bin/latexindent"; } + + ] + ) ++ ( + lib.optionals cfg.enableDataSupport [ + { name = "BufSetOption"; option = "filetype=markdown"; commands = "set-option buffer formatcmd ${python3.pkgs.mdformat}/bin/mdformat"; } + ] + ); + # TODO add more formatters from https://github.com/mawww/kakoune/wiki/Format }; extraConfig = builtins.concatStringsSep "\n" [ "# Custom commands"