diff --git a/dotfiles/kakoune/default.nix b/dotfiles/kakoune/default.nix index c8546cb..21f5fcc 100644 --- a/dotfiles/kakoune/default.nix +++ b/dotfiles/kakoune/default.nix @@ -26,6 +26,7 @@ in { kakoune-find kakoune-idris kakoune-surround + prelude-kak shellcheck-kak smarttab-kak tug @@ -85,7 +86,8 @@ in { map global window ': tmux-terminal-vertical sh -c %{ kak -c $1 $2 } -- %val{session} %val{bufname} ' -docstring "horizontal split" # automatically match opening/closing pairs like () and [] - enable-auto-pairs + require-module auto-pairs + auto-pairs-enable # Git status hook global WinSetOption filetype=.+ %{ git show-diff } diff --git a/flake.lock b/flake.lock index f25e915..1ac601e 100644 --- a/flake.lock +++ b/flake.lock @@ -16,22 +16,6 @@ "type": "github" } }, - "auto-pairs": { - "flake": false, - "locked": { - "lastModified": 1633713473, - "narHash": "sha256-CBjmABmrL40NCMV9jIeDAy2HsVk2Hu9feGeueXO7aUM=", - "owner": "alexherbo2", - "repo": "auto-pairs.kak", - "rev": "7692c77e8f7022adc510240dd3dd1aba549e9c71", - "type": "github" - }, - "original": { - "owner": "alexherbo2", - "repo": "auto-pairs.kak", - "type": "github" - } - }, "comma": { "flake": false, "locked": { @@ -298,10 +282,25 @@ "type": "github" } }, + "prelude-kak": { + "flake": false, + "locked": { + "lastModified": 1614136066, + "narHash": "sha256-DNHORL++3Pw+Qt+jqTZDjbqkw0WGwb99+oJu/BXKzN4=", + "owner": "kakounedotcom", + "repo": "prelude.kak", + "rev": "5dbdc020c546032885c1fdb463e366cc89fc15ad", + "type": "github" + }, + "original": { + "owner": "kakounedotcom", + "repo": "prelude.kak", + "type": "github" + } + }, "root": { "inputs": { "active-window": "active-window", - "auto-pairs": "auto-pairs", "comma": "comma", "darwin": "darwin", "fzf-tab": "fzf-tab", @@ -316,6 +315,7 @@ "nixpkgs": "nixpkgs", "nixpkgs-darwin": "nixpkgs-darwin", "nixpkgs-unstable": "nixpkgs-unstable", + "prelude-kak": "prelude-kak", "shellcheck-kak": "shellcheck-kak", "similar-sort": "similar-sort", "smarttab-kak": "smarttab-kak", diff --git a/flake.nix b/flake.nix index 374aace..29a7e94 100644 --- a/flake.nix +++ b/flake.nix @@ -47,10 +47,6 @@ }; # kakoune plugins - auto-pairs = { - url = "github:alexherbo2/auto-pairs.kak"; - flake = false; - }; active-window = { url = "github:greenfork/active-window.kak"; flake = false; @@ -75,6 +71,10 @@ url = "github:h-youhei/kakoune-surround"; flake = false; }; + prelude-kak = { + url = "github:kakounedotcom/prelude.kak"; + flake = false; + }; shellcheck-kak = { url = "github:whereswaldon/shellcheck.kak"; flake = false; @@ -134,8 +134,11 @@ active-window = buildKakounePlugin "active-window" inputs.active-window; - auto-pairs = - buildKakounePlugin "auto-pairs.kak" inputs.auto-pairs; + auto-pairs = final.kakouneUtils.buildKakounePlugin { + pname = "auto-pairs"; + version = "vendored"; + src = ./vendor/auto-pairs.kak; + }; kak-ayu = final.callPackage ./pkgs/kak-ayu { }; @@ -164,6 +167,8 @@ kakoune-surround = buildKakounePlugin "kakoune-surround" inputs.kakoune-surround; + prelude-kak = buildKakounePlugin "prelude.kak" inputs.prelude-kak; + shellcheck-kak = buildKakounePlugin "shellcheck.kak" inputs.shellcheck-kak; diff --git a/vendor/auto-pairs.kak/CONTRIBUTING b/vendor/auto-pairs.kak/CONTRIBUTING new file mode 100644 index 0000000..3d438b2 --- /dev/null +++ b/vendor/auto-pairs.kak/CONTRIBUTING @@ -0,0 +1,18 @@ +The preferred way to contribute would be through GitHub pull requests, +as an alternative patches can be discussed on the IRC channel. + +When contributing your first changes, please include an empty commit for +copyright waiver using the following message (replace 'John Doe' with +your name or nickname): + + John Doe Copyright Waiver + + I dedicate any and all copyright interest in this software to the + public domain. I make this dedication for the benefit of the public at + large and to the detriment of my heirs and successors. I intend this + dedication to be an overt act of relinquishment in perpetuity of all + present and future rights to this software under copyright law. + +The command to create an empty commit from the command-line is: + + git commit --allow-empty diff --git a/vendor/auto-pairs.kak/README.md b/vendor/auto-pairs.kak/README.md new file mode 100644 index 0000000..e9cc796 --- /dev/null +++ b/vendor/auto-pairs.kak/README.md @@ -0,0 +1,71 @@ +# auto-pairs.kak + +Auto-paired characters for [Kakoune]. + +When inserting an opening pair, auto-pairs always inserts the closing pair, +unless when under a word character or preceded by a **backslash**, and for non +nestable characters (such as **apostrophes**), when preceded by word characters. + +Auto-pairing is also about pair navigation and editing (deleting existing pairs +and formatting in pair). It can move in pair `(▌)`, delete in pair `(▌)` and +post pair `()▌`, and pad in pair horizontally `(␣▌␣)` and vertically: +``` + … + foobar { + ▌ + } + … +``` +. + +When inserting an auto-paired character, if the opening and closing characters +are the same (such as double quote strings), auto-pairs will move right in pair +`"▌"` and skip additional pairing post pair `"▌`. + +## Features + +- Auto-pairing +- Vertical and horizontal padding +- No `sh` call when typing + +## Dependencies + +- [prelude.kak] + +[prelude.kak]: https://github.com/alexherbo2/prelude.kak + +## Installation + +Add [`auto-pairs.kak`](rc/auto-pairs.kak) to your autoload or source it manually. + +``` kak +require-module auto-pairs +``` + +## Usage + +Enable auto-pairs with `auto-pairs-enable`. +Auto-paired characters can be changed via the `auto_pairs` option. + +## Surrounding pairs + +By default, `auto_pairs` includes the following surrounding pairs: + +``` +Parenthesis block: ( ) +Braces block: { } +Brackets block: [ ] +Double quote string: " " +Single quote string: ' ' +Grave quote string: ` ` +Double quotation mark: “ ” +Single quotation mark: ‘ ’ +Double angle quotation mark: « » +Single angle quotation mark: ‹ › +``` + +See also [surround.kak] and [manual-indent.kak]. + +[Kakoune]: https://kakoune.org +[surround.kak]: https://github.com/alexherbo2/surround.kak +[manual-indent.kak]: https://github.com/alexherbo2/manual-indent.kak diff --git a/vendor/auto-pairs.kak/UNLICENSE b/vendor/auto-pairs.kak/UNLICENSE new file mode 100644 index 0000000..efb9808 --- /dev/null +++ b/vendor/auto-pairs.kak/UNLICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/vendor/auto-pairs.kak/rc/auto-pairs.kak b/vendor/auto-pairs.kak/rc/auto-pairs.kak new file mode 100644 index 0000000..520f5c7 --- /dev/null +++ b/vendor/auto-pairs.kak/rc/auto-pairs.kak @@ -0,0 +1,329 @@ +provide-module auto-pairs %{ + + # Modules ──────────────────────────────────────────────────────────────────── + + require-module prelude + + # Options ──────────────────────────────────────────────────────────────────── + + declare-option -docstring 'List of surrounding pairs' str-list auto_pairs ( ) { } [ ] '"' '"' "'" "'" ` ` “ ” ‘ ’ « » ‹ › + + declare-option -hidden str-list auto_pairs_saved_pairs + declare-option -hidden str auto_pairs_match_pairs + declare-option -hidden str auto_pairs_match_nestable_pairs + + # Commands ─────────────────────────────────────────────────────────────────── + + define-command auto-pairs-enable -docstring 'Enable auto-pairs' %{ + auto-pairs-save-settings + # Create mappings for padding and deleting pairs. + map global insert ': auto-pairs-insert-new-line' + map global insert ': auto-pairs-insert-space' + map global insert ': auto-pairs-delete-with-backspace' + # map global insert ': auto-pairs-delete-with-delete' + # Update auto-pairs on option changes + hook -group auto-pairs global WinSetOption auto_pairs=.* %{ + auto-pairs-save-settings + } + } + + define-command auto-pairs-disable -docstring 'Disable auto-pairs' %{ + # Remove mappings + evaluate-commands %sh{ + . "$kak_opt_prelude_path" + eval "set -- $kak_quoted_opt_auto_pairs" + for key do + kak_escape unmap global insert "$key" + done + } + unmap global insert + unmap global insert + unmap global insert + # unmap global insert + # Unset options + set-option global auto_pairs_saved_pairs + set-option global auto_pairs_match_pairs '' + set-option global auto_pairs_match_nestable_pairs '' + } + + # Option commands ──────────────────────────────────────────────────────────── + + define-command -hidden auto-pairs-save-settings %{ + # Create mappings for auto-paired characters. + # Build regexes for matching surrounding pairs. + evaluate-commands %sh{ + . "$kak_opt_prelude_path" + # Remove mappings from the previous set. + eval "set -- $kak_quoted_opt_auto_pairs_saved_pairs" + for key do + kak_escape unmap global insert "$key" + done + # Initialization + eval "set -- $kak_quoted_opt_auto_pairs" + # Regexes + match_pairs='' + match_nestable_pairs='' + while test $# -ge 2; do + opening=$1 closing=$2 + shift 2 + # Create mappings for auto-paired characters. + if test "$opening" = "$closing"; then + auto_pairs_insert_pairing=$(kak_escape auto-pairs-insert-pairing "$opening" "$closing") + kak_escape map global insert "$opening" ": $auto_pairs_insert_pairing" + else + auto_pairs_insert_opening=$(kak_escape auto-pairs-insert-opening "$opening" "$closing") + auto_pairs_insert_closing=$(kak_escape auto-pairs-insert-closing "$opening" "$closing") + kak_escape map global insert "$opening" ": $auto_pairs_insert_opening" + kak_escape map global insert "$closing" ": $auto_pairs_insert_closing" + # Build regex for matching nestable pairs. + match_nestable_pairs="$match_nestable_pairs|(\\A\\Q$opening\\E\s*\\Q$closing\\E\\z)" + fi + # Build regex for matching surrounding pairs. + match_pairs="$match_pairs|(\\A\\Q$opening\\E\s*\\Q$closing\\E\\z)" + done + # Set regex options + match_pairs=${match_pairs#|} + match_nestable_pairs=${match_nestable_pairs#|} + kak_escape set-option global auto_pairs_match_pairs "$match_pairs" + kak_escape set-option global auto_pairs_match_nestable_pairs "$match_nestable_pairs" + } + # Save surrounding pairs + set-option global auto_pairs_saved_pairs %opt{auto_pairs} + } + + # Implementation commands ──────────────────────────────────────────────────── + + define-command -hidden auto-pairs-insert-pairing -params 2 %{ + try %{ + # Move right in pair + # "▌" ⇒ ""▌ + auto-pairs-cursor-keep-fixed-string %arg{2} + auto-pairs-move-right + } catch %{ + # Insert post pair + # ""▌ ⇒ ""▌ + auto-pairs-cursor-keep-fixed-string %arg{2} 'h' + execute-keys %arg{1} + } catch %{ + # Insert closing pair + # Skip escaped pairs + auto-pairs-cursor-reject-fixed-string '\' 'h' + # Skip **on** or **preceded** by a word character. + # 🄹🄾🅹🄾 + auto-pairs-cursor-reject '\w' + # JoJo▌ + auto-pairs-cursor-reject '\w' 'h' + # Commit auto-pairing + auto-pairs-insert-pair %arg{1} %arg{2} + } catch %{ + execute-keys -with-hooks %arg{1} + } + } + + define-command -hidden auto-pairs-insert-opening -params 2 %{ + try %{ + # Skip escaped pairs + auto-pairs-cursor-reject-fixed-string '\' 'h' + # Skip **on** a word character. + # 🅹🄾🄹🄾 + auto-pairs-cursor-reject '\w' + # Commit auto-pairing + # main▌ ⇒ main(▌) + auto-pairs-insert-pair %arg{1} %arg{2} + } catch %{ + execute-keys -with-hooks %arg{1} + } + } + + define-command -hidden auto-pairs-insert-closing -params 2 %{ + try %{ + # Move right in pair + # (▌) ⇒ ()▌ + auto-pairs-cursor-keep-fixed-string %arg{2} + auto-pairs-move-right + } catch %{ + execute-keys -with-hooks %arg{2} + } + } + + define-command -hidden auto-pairs-insert-new-line %{ + try %{ + # Insert an additional line in pair + # main() {▌} + auto-pairs-keep-surrounding-pairs ';H' + # main() { + # ▌ + # } + execute-keys 'KKjA' + execute-keys -with-hooks 'i' + } catch %{ + execute-keys -with-hooks '' + } + } + + # Space padding in pair (only nestable pairs and with a padding already balanced). + define-command -hidden auto-pairs-insert-space %{ + try %{ + # Empty content + # (▌) + auto-pairs-keep-nestable-pairs ';H' + # (␣▌␣) + auto-pairs-insert-pair ' ' ' ' + } catch %{ + # Only with a padding already balanced + # (␣▌␣) + auto-pairs-keep-nestable-pairs 'LH' + auto-pairs-keep-balanced-space-padding + # (␣␣▌␣␣) + auto-pairs-insert-pair ' ' ' ' + } catch %{ + execute-keys -with-hooks '' + } + } + + # Delete in pair: "▌" + # Delete post pair: ()▌ + define-command -hidden auto-pairs-delete-with-backspace %{ + auto-pairs-delete-implementation '' ';H' 'hH' + } + + # Delete in pair: "▌" + # Delete pre pair: ▌() + define-command -hidden auto-pairs-delete-with-delete %{ + auto-pairs-delete-implementation '' ';H' ';L' + } + + # auto-pairs-delete-implementation + define-command -hidden auto-pairs-delete-implementation -params 3 %{ + try %{ + # Delete in pair + # "▌" ⇒ ▌ + auto-pairs-keep-surrounding-pairs %arg{2} + execute-keys -draft "%arg{2}d" + } catch %{ + # Delete near nestable pairs + # + # Post pair with Backspace: + # ()▌ ⇒ ▌ + # + # Pre pair with Delete: + # ▌() ⇒ ▌ + auto-pairs-keep-nestable-pairs %arg{3} + execute-keys -draft "%arg{3}d" + } catch %{ + # Delete empty line + auto-pairs-cursor-keep '^\n' + # Test a surrounding pair with the surrounding characters. + # main() { + # ▌ + # } + auto-pairs-keep-surrounding-pairs ';JGlKGl' + # Join in pair + # main() {▌} + execute-keys -draft 'd' + } catch %{ + # Space padding in pair (only nestable pairs) + # (␣␣▌␣␣) + auto-pairs-keep-nestable-pairs 'LH' + auto-pairs-keep-balanced-space-padding + # Commit padding + # (␣▌␣) + execute-keys '' + } catch %{ + execute-keys -with-hooks %arg{1} + } + } + + # Utility commands ─────────────────────────────────────────────────────────── + + # Keep surrounding pairs + define-command -hidden auto-pairs-keep-surrounding-pairs -params ..1 %{ + auto-pairs-keep %opt{auto_pairs_match_pairs} %arg{1} + } + + # Keep nestable pairs + define-command -hidden auto-pairs-keep-nestable-pairs -params ..1 %{ + auto-pairs-keep %opt{auto_pairs_match_nestable_pairs} %arg{1} + } + + # Insert pair + # Jump backwards in pair, before inserting. + define-command -hidden auto-pairs-insert-pair -params 2 %{ + auto-pairs-insert-text "%arg{1}%arg{2}" + auto-pairs-move-left + } + + # Insert text + define-command -hidden auto-pairs-insert-text -params 1 %{ + # A bit verbose, but more robust than passing text to execute-keys. + evaluate-commands -save-regs '"' %{ + set-register '"' %arg{1} + execute-keys '"' + } + } + + # Commands to move the cursor and preserve the anchor position. + define-command -hidden auto-pairs-move-left %{ + auto-pairs-move-in-pair-implementation 'h' 'H' + } + define-command -hidden auto-pairs-move-right %{ + auto-pairs-move-in-pair-implementation 'l' 'L' + } + define-command -hidden auto-pairs-move-in-pair-implementation -params 2 %{ + # If something is selected (i.e. the selection is not just the cursor), + # preserve the anchor position. + try %{ + # Test if extending + execute-keys -draft '.{2,}' + # Preserve anchor position + execute-keys '' %arg{2} + } catch %{ + # Jump without preserving + execute-keys '' %arg{1} + } + } + + # Keep balanced space padding. + define-command -hidden auto-pairs-keep-balanced-space-padding %{ + evaluate-commands -draft -save-regs '/' %{ + execute-keys -draft -save-regs '' 'h[*' + set-register / "\A%reg{/}\z" + execute-keys -draft ']' + } + } + + # Keep + define-command -hidden auto-pairs-keep-implementation -params 2..3 %{ + evaluate-commands -draft -save-regs '/' %{ + execute-keys %arg{3} + set-register / %arg{2} + execute-keys %arg{1} '' + } + } + define-command -hidden auto-pairs-keep -params 1..2 %{ + auto-pairs-keep-implementation '' %arg{@} + } + define-command -hidden auto-pairs-cursor-keep -params 1..2 %{ + auto-pairs-keep %arg{1} ";%arg{2}" + } + define-command -hidden auto-pairs-keep-fixed-string -params 1..2 %{ + auto-pairs-keep "\Q%arg{1}\E" %arg{2} + } + define-command -hidden auto-pairs-cursor-keep-fixed-string -params 1..2 %{ + auto-pairs-keep-fixed-string %arg{1} ";%arg{2}" + } + + # Reject + define-command -hidden auto-pairs-reject -params 1..2 %{ + auto-pairs-keep-implementation '' %arg{@} + } + define-command -hidden auto-pairs-cursor-reject -params 1..2 %{ + auto-pairs-reject %arg{1} ";%arg{2}" + } + define-command -hidden auto-pairs-reject-fixed-string -params 1..2 %{ + auto-pairs-reject "\Q%arg{1}\E" %arg{2} + } + define-command -hidden auto-pairs-cursor-reject-fixed-string -params 1..2 %{ + auto-pairs-reject-fixed-string %arg{1} ";%arg{2}" + } +}