diff --git a/packages/common/default.nix b/packages/common/default.nix index be4ba2a..fadb679 100644 --- a/packages/common/default.nix +++ b/packages/common/default.nix @@ -2,4 +2,5 @@ final: prev: { epfl-cups-drivers = final.callPackage ./epfl-cups-drivers { }; ttaenc = final.callPackage ./ttaenc.nix { }; suwako-cursors = final.callPackage ./suwako-cursors { }; + nki-kakoune = final.callPackage ./nki-kakoune { }; } diff --git a/packages/common/nki-kakoune/autoload/latex.kak b/packages/common/nki-kakoune/autoload/latex.kak new file mode 100644 index 0000000..4bb9c9d --- /dev/null +++ b/packages/common/nki-kakoune/autoload/latex.kak @@ -0,0 +1,133 @@ +## Author: @natsukagami (https://github.com/natsukagami) +## +## To activate, source the file into kakrc and add: +### require-module latex-kak +## +## NOTE: This overrides , so if you don't like it, remove it. + +# Create a simple begin block, put the cursors in and remove multi-cursor on exit. +define-command -hidden create-begin-block %{ + execute-keys "i\begin{b0}\end{b0}" + execute-keys "b0" + execute-keys -with-hooks -with-maps "c" + hook -once buffer ModeChange .*:normal %{ + execute-keys -with-maps ",gl" + } +} +# Create a begin block with the given parameter as block name. +define-command -params 1 create-begin-block-with %{ + execute-keys "i\begin{b0}\end{b0}" + execute-keys "b0c%arg{1}," + execute-keys "ok" + execute-keys -with-maps "gl" +} +# 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}zl" + execute-keys -with-hooks -with-maps "i" +} +define-command -params 1 create-block-with %{ + create-delims "\%arg{1}{" "}" +} + +# The font-menu +declare-user-mode latex-font +## Semantics +map -docstring "Text" global latex-font t ": create-block-with text" +map -docstring "Emphasize (emph)" global latex-font e ": create-block-with emph" +## Shape +map -docstring "Italics (textit)" global latex-font i ": create-block-with textit" +map -docstring "Upright (textup)" global latex-font u ": create-block-with textup" +# map -docstring "Slanted (textsl)" global latex-font S ": create-block-with textsl" +# map -docstring "Swash font (textsw)" global latex-font W ": create-block-with textsw" +# map -docstring "Small caps (textsc)" global latex-font C ": create-block-with textsc" +# Weight +map -docstring "Bold text (textbf)" global latex-font b ": create-block-with textbf" +# map -docstring "Medium bold (textmd)" global latex-font M ": create-block-with textmd" +# map -docstring "Normal (textnormal)" global latex-font N ": create-block-with textnormal" +## Family +# map -docstring "Serif font (textsf)" global latex-font s ": create-block-with textsf" +# map -docstring "Roman text (textrm)" global latex-font r ": create-block-with textrm" +map -docstring "Monospace (texttt)" global latex-font m ": create-block-with texttt" +## Math styles +map -docstring "Math Calligraphic (mathcal)" global latex-font ": create-block-with mathcal" +map -docstring "Math Blackboard (mathbb)" global latex-font ": create-block-with mathbb" +# map -docstring "Math Fraktur (mathfr)" global latex-font ": create-block-with mathfr" +# map -docstring "Math Roman (mathrm)" global latex-font ": create-block-with mathrm" +# map -docstring "Math Italics (mathit)" global latex-font ": create-block-with mathit" +# 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 +## Common normal text blocks +map -docstring "Unordered list" global latex-insert-block u ": create-begin-block-with itemize" +map -docstring "Ordered list" global latex-insert-block o ": create-begin-block-with enumerate" +## Common math blocks +map -docstring "Theorem" global latex-insert-block t ": create-begin-block-with theorem" +map -docstring "Definition" global latex-insert-block d ": create-begin-block-with definition" +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" +## Custom +map -docstring "Custom" global latex-insert-block c ": create-begin-block" + +# 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=(tex|latex) %{ + ## 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" + + ## 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" + + ## 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 " +} + diff --git a/packages/common/nki-kakoune/autoload/markdown.kak b/packages/common/nki-kakoune/autoload/markdown.kak new file mode 100644 index 0000000..fb10581 --- /dev/null +++ b/packages/common/nki-kakoune/autoload/markdown.kak @@ -0,0 +1,29 @@ +hook global WinSetOption filetype=(markdown) %{ + map buffer normal ": enter-user-mode markdown-menu" +} + +# A menu for common markdown actions +declare-user-mode markdown-menu + +map -docstring "Toggle the checkboxes on the same line" global markdown-menu t ": markdown-toggle-checkbox" + +define-command -hidden markdown-toggle-checkbox %{ + try %{ + execute-keys -draft "xs^\s*- \[( |x)\]h: markdown-toggle-checkbox-selections" + } +} + +define-command -hidden markdown-toggle-checkbox-selections %{ + try %{ + execute-keys -draft -itersel ": markdown-toggle-checkbox-one" + } +} + +define-command -hidden markdown-toggle-checkbox-one %{ + try %{ + execute-keys -draft "sxr " + } catch %{ + execute-keys -draft "s rx" + } +} + diff --git a/packages/common/nki-kakoune/default.nix b/packages/common/nki-kakoune/default.nix new file mode 100644 index 0000000..6e181ce --- /dev/null +++ b/packages/common/nki-kakoune/default.nix @@ -0,0 +1,3 @@ +{ callPackage, kakoune, ... }: kakoune.override { + plugins = (callPackage ./plugins.nix { }).plugins; +} diff --git a/packages/common/nki-kakoune/plugins.nix b/packages/common/nki-kakoune/plugins.nix new file mode 100644 index 0000000..a16c898 --- /dev/null +++ b/packages/common/nki-kakoune/plugins.nix @@ -0,0 +1,209 @@ +{ pkgs, symlinkJoin, writeTextDir, kakouneUtils, ... }: +with { + inherit (kakouneUtils) buildKakounePluginFrom2Nix; +}; +let + toDir = name: file: writeTextDir name (builtins.readFile file); + + writeActivationScript = script: writeTextDir "on-load.kak" '' + hook global KakBegin .* %{ + ${script} + } + ''; + + writeModuleWrapper = name: script: writeTextDir "module.kak" '' + provide-module ${name} %◍ + ${script} + ◍ + ''; + + kakounePlugin = { name, src, wrapAsModule ? false, activationScript ? null, ... }@attrs: + let + module = if wrapAsModule then writeModuleWrapper name (builtins.readFile src) else src; + in + buildKakounePluginFrom2Nix { + pname = name; + version = attrs.version or "latest"; + src = if activationScript == null then module else + symlinkJoin { + name = "${name}-src"; + paths = [ + module + (writeActivationScript activationScript) + ]; + }; + }; +in +{ + plugins = builtins.map kakounePlugin + [ + # My own scripts + { + name = "latex.kak"; + src = toDir "latex.kak" ./autoload/latex.kak; + } + { + name = "markdown.kak"; + src = toDir "markdown.kak" ./autoload/markdown.kak; + } + + # Plugins + { + name = "luar"; + src = pkgs.fetchFromGitHub { + owner = "gustavo-hms"; + repo = "luar"; + rev = "2f430316f8fc4d35db6c93165e2e77dc9f3d0450"; + sha256 = "sha256-vHn/V3sfzaxaxF8OpA5jPEuPstOVwOiQrogdSGtT6X4="; + }; + activationScript = '' + # Enable luar + require-module luar + # Use luajit + set-option global luar_interpreter ${pkgs.luajit}/bin/luajit + ''; + } + { + name = "peneira"; + src = pkgs.fetchFromGitHub { + owner = "natsukagami"; + repo = "peneira"; + rev = "743b9971472853a752475e7c070ce99089c6840c"; + sha256 = "sha256-E4ndbF9YC1p0KrvSuGgwmG1Y2IGTuGKJo/AuMixhzlM="; + }; + activationScript = '' + require-module peneira + + # Change selection color + set-face global PeneiraSelected @PrimarySelection + + # Buffers list + define-command -hidden peneira-buffers %{ + peneira 'buffers: ' %{ printf '%s\n' $kak_quoted_buflist } %{ + buffer %arg{1} + } + } + + # Grep in the current location + define-command peneira-grep %{ + peneira 'line: ' "rg -n ." %{ + lua %arg{1} %{ + local file, line = arg[1]:match("([^:]+):(%d+):") + kak.edit(file, line) + } + } + } + + # A peneira menu + declare-user-mode fuzzy-match-menu + + map -docstring "Switch to buffer" global fuzzy-match-menu b ": peneira-buffers" + map -docstring "Symbols" global fuzzy-match-menu s ": peneira-symbols" + map -docstring "Lines" global fuzzy-match-menu l ": peneira-lines" + map -docstring "Lines in the current directory" global fuzzy-match-menu g ": peneira-grep" + map -docstring "Files in project" global fuzzy-match-menu f ": peneira-files" + map -docstring "Files in currently opening file's directory" global fuzzy-match-menu F ": peneira-local-files" + + # Bind menu to user mode + map -docstring "Fuzzy matching" global user f ": enter-user-mode fuzzy-match-menu" + ''; + } + { + name = "kakoune-focus"; + src = pkgs.fetchFromGitHub { + owner = "caksoylar"; + repo = "kakoune-focus"; + rev = "949c0557cd4c476822acfa026ca3c50f3d38a3c0"; + sha256 = "sha256-ZV7jlLJQyL420YG++iC9rq1SMjo3WO5hR9KVvJNUiCs="; + }; + activationScript = '' + map global user ': focus-toggle' -docstring "toggle selections focus" + ''; + } + { + name = "kakoune-inc-dec"; + src = pkgs.fetchFromGitLab { + owner = "Screwtapello"; + repo = "kakoune-inc-dec"; + rev = "7bfe9c51"; + sha256 = "0f33wqxqbfygxypf348jf1fiscac161wf2xvnh8zwdd3rq5yybl0"; + }; + } + { + name = "racket.kak"; + src = (builtins.fetchTree { + type = "git"; + url = "https://bitbucket.org/KJ_Duncan/kakoune-racket.kak.git"; + rev = "e397042009b46916ff089d79166ec0e8ca813a18"; + narHash = "sha256-IcxFmvG0jqpMCG/dT9crVRgPgMGKkic6xwrnW5z4+bc="; + }) + "/rc"; + } + # { + # name = "kakoune-discord"; + # src = (builtins.getFlake "github:natsukagami/kakoune-discord/03f95e40d6efd8fd3de7bca31653d43de2dcfc5f").packages.${pkgs.system}.kakoune-discord-rc + "/rc"; + # } + rec { + name = "kakoune-mirror"; + src = pkgs.fetchFromGitHub + { + owner = "Delapouite"; + repo = "kakoune-mirror"; + rev = "5710635f440bcca914d55ff2ec1bfcba9efe0f15"; + sha256 = "sha256-uslx4zZhvjUylrPWvTOugsKYKKpF0EEz1drc1Ckrpjk="; + } + "/mirror.kak"; + wrapAsModule = true; + activationScript = '' + require-module ${name} + + # Bind to ${name} + map global normal ': enter-user-mode -lock mirror' + ''; + } + { + name = "unicode-math"; + src = pkgs.fetchFromGitHub { + owner = "natsukagami"; + repo = "kakoune-unicode-math"; + rev = "08dff25da2b86ee0b0777091992bc7fb28c3cb1d"; + # sha256 = lib.fakeSha256; + sha256 = "sha256-j0L1ARex1i2ma8sGLYwgkfAbh0jWKh/6QGHFaxPXIKc="; + fetchSubmodules = true; + }; + activationScript = '' + require-module unicode-math + + # Bind to the menu + map global insert ': insert-unicode ' + ''; + } + { + name = "kakoune-buffers"; + src = pkgs.fetchFromGitHub { + owner = "Delapouite"; + repo = "kakoune-buffers"; + rev = "6b2081f5b7d58c72de319a5cba7bf628b6802881"; + sha256 = "sha256-jOSrzGcLJjLK1GiTSsl2jLmQMPbPxjycR0pwF5t/eV0="; + }; + activationScript = '' + # Suggested hook + + hook global WinDisplay .* info-buffers + + # Suggested mappings + + map global user b ':enter-buffers-mode' -docstring 'buffers…' + map global normal ^ ':enter-buffers-mode' -docstring 'buffers…' + map global user B ':enter-user-mode -lock buffers' -docstring 'buffers (lock)…' + + # Suggested aliases + + alias global bd delete-buffer + alias global bf buffer-first + alias global bl buffer-last + alias global bo buffer-only + alias global bo! buffer-only-force + ''; + } + ]; +} +