├── README.md ├── UNLICENSE ├── doc.kak ├── git.kak ├── locations.kak └── surround.kak /README.md: -------------------------------------------------------------------------------- 1 | # kakoune-boost 2 | 3 | This is a place for work-in-progress and experimental scripts that are 4 | intended to be added to the [Kakoune editor](https://github.com/mawww/kakoune). 5 | 6 | If a change graduates to a ready-to-use Kakoune patch, it should be removed 7 | from kakoune-boost. This keeps us honest - we should nurse patches in our 8 | individual forks. 9 | 10 | # Usage 11 | 12 | We currently require a development version of Kakoune (>= 2024-02) and Git. 13 | 14 | git clone https://github.com/krobelus/kakoune-boost ~/.config/kak/autoload/ 15 | kak -e ' 16 | map global user g %{:enter-user-mode git} -docstring git... 17 | ' 18 | 19 | The scripts are idempotent; after making a change you can source them again, 20 | no need to restart the editor. 21 | 22 | # Contributing 23 | 24 | Send feedback and patches to [~krobelus/kakoune@lists.sr.ht](mailto:~krobelus/kakoune@lists.sr.ht) (see 25 | [public archives](https://lists.sr.ht/~krobelus/kakoune)) or use GitHub or IM. 26 | -------------------------------------------------------------------------------- /UNLICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /doc.kak: -------------------------------------------------------------------------------- 1 | define-command -override doc-key -docstring "show the documentation of a key in normal mode" %{ 2 | # Read a single key. 3 | evaluate-commands -verbatim on-key %{ 4 | # Switch to the documentation of keys, or open it. 5 | try %{ 6 | buffer *doc-keys* 7 | } catch %{ 8 | doc keys 9 | } 10 | # Jump to the line where this key is documented. 11 | evaluate-commands execute-keys %sh{ 12 | kakquote() { printf %s "$*" | sed "s/'/''/g; 1s/^/'/; \$s/\$/'/"; } 13 | key=$(printf %s "$kak_key" | 14 | sed ' 15 | s//;/; 16 | s/-semicolon/-;/; 17 | s//; 18 | ') 19 | kakquote "$(printf "/^\Q%svv" "$key")" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /git.kak: -------------------------------------------------------------------------------- 1 | remove-hooks global boost-git 2 | 3 | ## Clipboard 4 | # TODO Replace/move this. 5 | declare-option str clipboard_copy_cmd wl-copy 6 | define-command -override clipboard-yank %{ 7 | evaluate-commands -save-regs t %{ 8 | set-register t %val{client_env_SSH_TTY} 9 | execute-keys -draft %{,ySSH_TTY=${kak_reg_t} ${kak_opt_clipboard_copy_cmd} >/dev/null 2>&1} 10 | } 11 | } 12 | 13 | # Github issue #5048 14 | define-command -override git-jump -docstring %{ 15 | If inside a diff, run git-diff-goto-source, 16 | Else show the Git object at cursor. 17 | } %{ evaluate-commands -save-regs c %{ 18 | try %{ 19 | execute-keys -draft l[px^diff 20 | set-register c git-diff-goto-source 21 | } catch %{ 22 | execute-keys -draft x "^Staged changes$" 23 | set-register c git diff --staged 24 | } catch %{ 25 | execute-keys -draft x "^Unstaged changes$" 26 | set-register c git diff 27 | } catch %{ 28 | evaluate-commands -draft %{ 29 | try %{ 30 | execute-keys w 31 | } catch %{ 32 | fail git-jump: no word at cursor 33 | } 34 | try %{ 35 | evaluate-commands %sh{ 36 | [ "$(git rev-parse --revs-only "$kak_selection")" ] || echo fail 37 | } 38 | } catch %{ 39 | fail "git-jump: bad revision '%val{selection}'" 40 | } 41 | set-register c git show %val{selection} -- 42 | } 43 | } 44 | %reg{c} 45 | }} 46 | hook -group boost-git global WinSetOption filetype=git-(?:commit|diff|log|notes|rebase) %{ 47 | map buffer normal %exp{:git-jump # %val{hook_param}} -docstring 'Jump to source from git diff' 48 | hook -once -always window WinSetOption filetype=.* %exp{ 49 | unmap buffer normal %%{:git-jump # %val{hook_param}} 50 | } 51 | } 52 | 53 | ## Conflict resolution. TODO Better shortcuts? 54 | define-command -override git-conflict-use-ours -docstring "choose the first side of a conflict hunk" %{ 55 | evaluate-commands -draft %{ 56 | execute-keys l^{4}xd 57 | execute-keys h/^(={4}|\|{4}|%{4}|\+{4}) 58 | execute-keys ?^>{4}xd 59 | } 60 | } 61 | define-command -override git-conflict-use-theirs -docstring "choose the second side of a conflict hunk" %{ 62 | evaluate-commands -draft %{ 63 | execute-keys l^{4} 64 | execute-keys ?^(={4}|\+{4}|%{4})xd 65 | execute-keys />{4}xd 66 | } 67 | } 68 | 69 | define-command -override git-conflicts %{ 70 | evaluate-commands %sh{ 71 | if list=$(jj resolve --list 2>/dev/null); then 72 | echo "grep ^<<<<<<< $(printf %s "$list" | sed 's/\s.*//g' | paste -s -d' ')" 73 | elif git ls-files -d | grep -qF .jj-do-not-resolve-this-conflict; then 74 | echo "grep ^<<<<<<< ." 75 | else 76 | echo "grep ^<<<<<<< $(git ls-files -u | cut -f2 | sort -u | paste -s -d' ')" 77 | fi 78 | } 79 | } -docstring "find all conflicts" 80 | 81 | ## Generic Git integration 82 | define-command -override git-select-commit %{ 83 | try %{ 84 | execute-keys %{^commit \S+} 85 | execute-keys %{1s^commit (\S+)} 86 | } catch %{ 87 | try %{ 88 | execute-keys w 89 | evaluate-commands %sh{ 90 | [ "$(git rev-parse --revs-only "$kak_selection" 2>/dev/null)" ] || echo fail 91 | } 92 | } catch %{ 93 | # oneline log 94 | execute-keys x 95 | try %{ execute-keys %{s^[0-9a-f]{4,}\b} } 96 | } 97 | } 98 | } 99 | declare-option str git_editor %{ 100 | sh -c ' 101 | #!/bin/sh 102 | # Send an "edit" command to the given Kakoune session and client. 103 | session="$1"; shift 104 | client="$1"; shift 105 | wait=false 106 | if [ "$1" = --wait ]; then 107 | wait=true 108 | shift 109 | fi 110 | while [ x"$1" = x-- ] 111 | do 112 | shift 113 | done 114 | line_and_maybe_column= 115 | if printf %s "$1" | grep -q ^+; then 116 | line_and_maybe_column=$(printf %s "$1" | sed -e s,^+,, -e "s,:, ,") 117 | shift 118 | fi 119 | filename=$(realpath "$1") 120 | cmd="edit -- $filename $line_and_maybe_column" 121 | if $wait; then 122 | fifo=$(mktemp -d "${TMPDIR:-/tmp}"/kak-remote-edit.XXXXXXXX)/fifo 123 | mkfifo $fifo 124 | cmd=" 125 | $cmd 126 | define-command -override -hidden git-editor-write -params .. %{ 127 | remove-hooks buffer remote-edit 128 | write %arg{@} 129 | delete-buffer 130 | echo -to-file $fifo 0 131 | } 132 | alias buffer w git-editor-write 133 | evaluate-commands -verbatim hook -group remote-edit buffer BufClose .* %{ 134 | echo -to-file $fifo 1 135 | } 136 | " 137 | fi 138 | printf %s "evaluate-commands -client $client %{$cmd}" | 139 | kak -p "$session" 140 | if $wait; then 141 | read status < $fifo 142 | rm -r $(dirname $fifo) 143 | exit $status 144 | fi 145 | ' --} 146 | define-command -override boost-git -params 1.. %{ evaluate-commands -draft %{ nop %sh{ 147 | ( 148 | response=git-log-default 149 | prepend_git=true 150 | while true; do { 151 | if [ "$1" = -no-refresh ]; then { 152 | response=nop 153 | shift 154 | } elif [ "$1" = -no-git ]; then { 155 | prepend_git=false 156 | shift 157 | } else { 158 | break 159 | } fi 160 | } done 161 | if $prepend_git; then 162 | set -- git "$@" 163 | fi 164 | commit=$kak_selection eval set -- "$@" 165 | escape2() { printf %s "$*" | sed "s/'/''''/g"; } 166 | escape3() { printf %s "$*" | sed "s/'/''''''''/g"; } 167 | if output=$( 168 | EDITOR="$kak_opt_git_editor ${kak_session} ${kak_client} --wait" \ 169 | "$@" 2>&1 170 | ); then { 171 | response="' 172 | $response 173 | echo -debug $ ''$(escape2 "$@") <<<'' 174 | echo -debug -- ''$(escape2 "$output")>>>'' 175 | '" 176 | } else { 177 | response="' 178 | $response 179 | echo -debug failed to run ''$(escape2 "$@")'' 180 | echo -debug ''git output: <<<'' 181 | echo -debug -- ''$(escape2 "$output")>>>'' 182 | hook -once buffer NormalIdle .* '' 183 | echo -markup ''''{Error}{\\}failed to run $(escape3 "$@"), see *debug* buffer'''' 184 | '' 185 | '" 186 | } fi 187 | echo "evaluate-commands -client ${kak_client} $response" | 188 | kak -p ${kak_session} 189 | ) >/dev/null 2>&1 d 204 | } 205 | set-option global git_line %val{cursor_line} 206 | } catch %{ 207 | set-option global git_line 1 208 | } 209 | } 210 | evaluate-commands -draft %{ 211 | try %{ 212 | buffer *git* 213 | rename-buffer *git*.bak 214 | } 215 | } 216 | try %{ delete-buffer *git-log* } 217 | git log --oneline %arg{@} 218 | hook -once buffer NormalIdle .* %{ 219 | execute-keys %opt{git_line}g 220 | execute-keys -draft \ 221 | %{gk!} \ 222 | %{git diff --quiet || echo "Unstaged changes";} \ 223 | %{git diff --quiet --cached || echo "Staged changes";} \ 224 | 225 | } 226 | rename-buffer *git-log* 227 | evaluate-commands -draft %{ 228 | try %{ 229 | buffer *git*.bak 230 | rename-buffer *git* 231 | } 232 | } 233 | } 234 | define-command -override git-log-default -params .. %{ 235 | # TODO Use upstream/fork point 236 | git-log -50 %arg{@} 237 | } 238 | define-command -override git-fixup %{ evaluate-commands -draft %{ 239 | git-select-commit 240 | git commit --fixup %val{selection} 241 | }} 242 | define-command -override git-yank -params 1 %{ 243 | evaluate-commands -save-regs t %{ 244 | set-register t %val{client_env_SSH_TTY} 245 | evaluate-commands -draft %{ 246 | git-select-commit 247 | evaluate-commands %sh{ 248 | x=$(git log -1 "${kak_selection}" --format="$1") 249 | printf %s "set-register dquote '$(printf %s "$x" | sed "s/'/''/g")'" 250 | printf %s "$x" | SSH_TTY=${kak_reg_t} "${kak_opt_clipboard_copy_cmd}" >/dev/null 2>&1 251 | } 252 | } 253 | } 254 | } 255 | define-command -override git-yank-reference %{ 256 | evaluate-commands -save-regs t %{ 257 | set-register t %val{client_env_SSH_TTY} 258 | evaluate-commands -draft %{ 259 | git-select-commit 260 | evaluate-commands %sh{ 261 | x=$(git log -1 "${kak_selection}" --pretty=reference) 262 | printf %s "set-register dquote '$(printf %s "$x" | sed "s/'/''/g")'" 263 | printf %s "$x" | SSH_TTY=${kak_reg_t} "${kak_opt_clipboard_copy_cmd}" >/dev/null 2>&1 264 | } 265 | } 266 | } 267 | } 268 | 269 | ## Third-party Git tools 270 | ### Tig - http://jonas.github.io/tig/ 271 | define-command -override tig -params .. %{ 272 | terminal env "EDITOR=kak -c %val{session}" tig %arg{@} 273 | } 274 | define-command -override tig-blame -docstring "Run tig blame on the current line" %{ 275 | tig -C %sh{git rev-parse --show-toplevel} blame -C "+%val{cursor_line}" -- %sh{ 276 | dir="$(git rev-parse --show-toplevel)" 277 | printf %s "${kak_buffile##$dir/}" 278 | } 279 | } 280 | define-command -override tig-blame-selection -docstring "Run tig -L on the selected lines" %{ 281 | evaluate-commands -save-regs d %{ 282 | evaluate-commands -draft %{ 283 | execute-keys 284 | set-register d %sh{git rev-parse --show-toplevel} 285 | } 286 | tig -C %reg{d} %sh{ 287 | anchor=${kak_selection_desc%,*} 288 | anchor_line=${anchor%.*} 289 | cursor=${kak_selection_desc#*,} 290 | cursor_line=${cursor%.*} 291 | d=$kak_reg_d 292 | printf %s "-L$anchor_line,$cursor_line:${kak_buffile##$d/}" 293 | } 294 | } 295 | } 296 | 297 | ### git-revise - https://github.com/mystor/git-revise 298 | define-command -override git-revise -params .. %{ git-with-commit revise %arg{@} } 299 | hook -group boost-git global BufCreate .*/git-revise-todo %{ 300 | set-option buffer filetype git-rebase 301 | } 302 | 303 | ### git-autofixup - https://github.com/torbiak/git-autofixup 304 | declare-option str git_fork_point %{ 305 | #!/bin/sh 306 | upstream=@{upstream} 307 | gitdir=$(git rev-parse --git-dir) 308 | if test -d "$gitdir"/rebase-merge; then 309 | branch=$(cat "$gitdir"/rebase-merge/head-name) 310 | branch=${branch#refs/heads/} 311 | upstream="$branch@{upstream}" 312 | fi 313 | git merge-base --fork-point HEAD "$upstream" || 314 | git merge-base HEAD "$upstream" 315 | } 316 | define-command -override git-autofixup %{ 317 | boost-git autofixup %sh{eval "${kak_opt_git_fork_point}"} 318 | } 319 | define-command -override git-autofixup-and-apply %{ 320 | evaluate-commands %sh{ 321 | fork_point=$(sh -c "${kak_opt_git_fork_point}") 322 | git-autofixup "$fork_point" --exit-code >&2 323 | if [ $? -ge 2 ]; then { 324 | echo "fail 'error running git-autofixup $fork_point'" 325 | } fi 326 | } 327 | boost-git -c sequence.editor=true revise -i --autosquash %sh{eval "${kak_opt_git_fork_point}"} 328 | } 329 | 330 | try %{ declare-user-mode git } 331 | try %{ declare-user-mode git-am } 332 | try %{ declare-user-mode git-apply } 333 | try %{ declare-user-mode git-bisect } 334 | try %{ declare-user-mode git-blame } 335 | try %{ declare-user-mode git-cherry-pick } 336 | try %{ declare-user-mode git-commit } 337 | try %{ declare-user-mode git-diff } 338 | try %{ declare-user-mode git-fetch } 339 | try %{ declare-user-mode git-merge } 340 | try %{ declare-user-mode git-push } 341 | try %{ declare-user-mode git-rebase } 342 | try %{ declare-user-mode git-reset } 343 | try %{ declare-user-mode git-revert } 344 | try %{ declare-user-mode git-revise } 345 | try %{ declare-user-mode git-yank } 346 | try %{ declare-user-mode git-stash } 347 | 348 | ## User modes 349 | map global git 1 %{:git-conflict-use-ours} -docstring "conflict: use ours" 350 | map global git 2 %{:git-conflict-use-theirs} -docstring "conflict: use theirs" 351 | map global git a %{:enter-user-mode git-apply} -docstring "apply/revert/stage/unstage selection..." 352 | map global git A %{:enter-user-mode git-cherry-pick} -docstring 'cherry-pick...' 353 | map global git B %{:enter-user-mode git-bisect} -docstring 'bisect...' 354 | map global git b %{:enter-user-mode git-blame} -docstring "blame..." 355 | map global git c %{:enter-user-mode git-commit} -docstring "commit..." 356 | map global git d %{:enter-user-mode git-diff} -docstring "diff..." 357 | map global git e %{:git edit } -docstring "edit..." 358 | map global git f %{:enter-user-mode git-fetch} -docstring 'fetch...' 359 | map global git l %{:git-log-default} -docstring 'log' 360 | map global git L %{:git-log } -docstring 'log...' 361 | map global git m %{:enter-user-mode git-am} -docstring 'am...' 362 | map global git M %{:enter-user-mode git-merge} -docstring 'merge...' 363 | map global git o %{:enter-user-mode git-reset} -docstring "reset..." 364 | map global git p %{:enter-user-mode git-push} -docstring 'push...' 365 | map global git r %{:enter-user-mode git-rebase} -docstring "rebase..." 366 | map global git s %{:git show} -docstring 'git show' 367 | map global git %{:buffer -matching \*git\b.*} -docstring "switch to most recent *git* buffer" 368 | map global git t %{:enter-user-mode git-revert} -docstring "revert..." 369 | map global git v %{:enter-user-mode git-revise} -docstring "revise..." 370 | map global git y %{:enter-user-mode git-yank} -docstring "yank..." 371 | map global git z %{:enter-user-mode git-stash} -docstring "stash..." 372 | 373 | map global git-am a %{:boost-git am --abort} -docstring 'abort' 374 | map global git-am r %{:boost-git am --continue} -docstring 'continue' 375 | map global git-am s %{:boost-git am --skip} -docstring 'skip' 376 | 377 | map global git-apply a %{:git apply} -docstring 'apply' 378 | map global git-apply 3 %{:git apply --3way} -docstring 'apply using 3way merge' 379 | map global git-apply r %{:git apply --reverse} -docstring 'reverse' 380 | map global git-apply t %{:git apply --reverse --index} -docstring 'revert and unstage' 381 | map global git-apply s %{:git apply --cached} -docstring 'stage' 382 | map global git-apply u %{:git apply --reverse --cached} -docstring 'unstage' 383 | map global git-apply i %{:git apply --index} -docstring 'apply and stage' 384 | 385 | map global git-bisect B %{:git-with-commit bisect bad %{"$commit"}} -docstring 'mark commit as bad' 386 | map global git-bisect G %{:git-with-commit bisect good %{"$commit"}} -docstring 'mark commit as good' 387 | 388 | map global git-blame t %{:tig-blame} -docstring "tig: show blame at cursor line" 389 | map global git-blame s %{:tig-blame-selection} -docstring "tig: show commits that touched main selection" 390 | map global git-blame a %{:git blame} -docstring "toggle git blame annotations" 391 | map global git-blame b %{:git blame-jump} -docstring "jump to change that introduced line at cursor" 392 | 393 | map global git-cherry-pick a %{:boost-git cherry-pick --abort} -docstring 'abort' 394 | map global git-cherry-pick p %{:git-with-commit cherry-pick %{"$commit"}} -docstring 'cherry-pick selected commit' 395 | map global git-cherry-pick r %{:boost-git cherry-pick --continue} -docstring 'continue' 396 | map global git-cherry-pick s %{:boost-git cherry-pick --skip} -docstring 'skip' 397 | 398 | map global git-commit a %{:boost-git commit --amend} -docstring 'amend' 399 | map global git-commit A %{:boost-git commit --amend --all} -docstring 'stage all and amend' 400 | map global git-commit r %{:boost-git commit --amend --reset-author} -docstring 'amend resetting author' 401 | map global git-commit c %{:boost-git commit} -docstring 'commit' 402 | map global git-commit C %{:boost-git commit --all} -docstring 'stage all and commit' 403 | map global git-commit F %{:boost-git commit --fixup=} -docstring 'fixup...' 404 | map global git-commit f %{:git-fixup} -docstring 'fixup commit selected commit' 405 | map global git-commit u %{:git-autofixup} -docstring 'autofixup' 406 | map global git-commit o %{:git-autofixup-and-apply} -docstring 'autofixup and apply' 407 | 408 | map global git-diff d %{:git diff} -docstring "show unstaged changes" 409 | map global git-diff h %{:git diff HEAD} -docstring "show changes between HEAD and working tree" 410 | map global git-diff u %{:git status} -docstring "show status" 411 | map global git-diff s %{:git diff --staged} -docstring "show staged changes" 412 | map global git-diff w %{:git diff -w} -docstring "show unstaged changes ignoring whitespace" 413 | map global git-diff %{:git-select-commit:git diff %reg{.}} -docstring "show changes between selected commit and working tree" 414 | map global git-diff c %{:git-conflicts} -docstring "find all conflicts" 415 | 416 | map global git-fetch f %{:boost-git pull --rebase} -docstring 'pull' 417 | map global git-fetch a %{:boost-git fetch --all} -docstring 'fetch all' 418 | map global git-fetch o %{:boost-git fetch origin} -docstring 'fetch origin' 419 | 420 | map global git-merge a %{:boost-git merge --abort} -docstring 'abort' 421 | map global git-merge m %{:git-with-commit merge %{"$commit"}} -docstring 'merge selected commit' 422 | map global git-merge r %{:boost-git merge --continue} -docstring 'continue' 423 | map global git-merge s %{:boost-git merge --skip} -docstring 'skip' 424 | 425 | map global git-push p %{:boost-git push} -docstring 'push' 426 | map global git-push f %{:boost-git push --force} -docstring 'push --force' 427 | 428 | map global git-rebase a %{:boost-git rebase --abort} -docstring 'abort' 429 | map global git-rebase e %{:boost-git rebase --edit-todo} -docstring 'edit todo list' 430 | map global git-rebase i %{:git-with-commit rebase --interactive %{"${kak_selection}"^}} -docstring "interactive rebase from selected commit's parent" 431 | map global git-rebase r %{:boost-git rebase --continue} -docstring 'continue' 432 | map global git-rebase s %{:boost-git rebase --skip} -docstring 'skip' 433 | map global git-rebase u %{:boost-git rebase --interactive} -docstring 'interactive rebase' 434 | 435 | map global git-reset o %{:git-with-commit reset %{"$commit"}} -docstring 'mixed reset' 436 | map global git-reset s %{:git-with-commit reset --soft %{"$commit"}} -docstring 'soft reset' 437 | map global git-reset O %{:git-with-commit reset --hard %{"$commit"}} -docstring 'hard reset' 438 | 439 | map global git-revert a %{:boost-git revert --abort} -docstring 'abort' 440 | map global git-revert t %{:git-with-commit revert %{"$commit"}} -docstring 'revert' 441 | map global git-revert r %{:boost-git revert --continue} -docstring 'continue' 442 | map global git-revert s %{:boost-git revert --skip} -docstring 'skip' 443 | 444 | map global git-revise a %{:git-revise --reauthor %{"$commit"}} -docstring 'reauthor' 445 | map global git-revise e %{:git-revise --interactive --edit %sh{eval "${kak_opt_git_fork_point}"}} -docstring 'edit all since fork-point' 446 | map global git-revise E %{:git-revise --interactive --edit %{"$commit"^}} -docstring 'edit all since commit' 447 | map global git-revise f %{:git-revise %{"$commit"}} -docstring 'fixup selected commit' 448 | map global git-revise i %{:git-revise --interactive %{"${kak_selection}^"}} -docstring "interactive revise from selected commit's parent" 449 | map global git-revise u %{:git-revise --interactive %sh{eval "${kak_opt_git_fork_point}"}} -docstring 'interactive revise from fork point' 450 | map global git-revise w %{:git-revise --edit %{"$commit"}} -docstring 'edit' 451 | 452 | map global git-stash z %{:boost-git stash push} -docstring 'push' 453 | map global git-stash p %{:boost-git stash pop} -docstring 'pop' 454 | 455 | map global git-yank a %{:git-yank '%aN %aE>'} -docstring 'copy author name and email' 456 | map global git-yank m %{:git-yank '%s%n%n%b'} -docstring 'copy message' 457 | map global git-yank c %{:git-yank '%H'} -docstring 'copy commit ID' 458 | map global git-yank r %{:git-yank-reference} -docstring 'copy pretty commit reference' 459 | -------------------------------------------------------------------------------- /locations.kak: -------------------------------------------------------------------------------- 1 | ## Grep 2 | 3 | define-command -override boost-grep -docstring "grep and select matches with 4 | works best if grepcmd uses a regex flavor similar to Kakoune's 5 | " -params .. %{ 6 | try %{ 7 | evaluate-commands %sh{ [ -z "$1" ] && echo fail } 8 | set-register / "(?S)%arg{1}" 9 | grep %arg{@} 10 | } catch %{ 11 | execute-keys -save-regs '' * 12 | grep -- %sh{ printf %s "$kak_main_reg_slash" } 13 | } 14 | boost-map-quickselect 15 | } 16 | try %{ complete-command boost-grep file } 17 | 18 | define-command -override boost-map-quickselect %{ evaluate-commands -save-regs 'l' %{ 19 | evaluate-commands -try-client %opt{toolsclient} %sh{ 20 | printf %s "map buffer normal '" 21 | printf %s '%S^/^.*?:\d+(?::\d+)?:' 22 | printf %s 'l' 23 | printf %s "s$(printf %s "$kak_main_reg_slash" | sed s/"'"/"''"/g"; s//g")" 24 | printf %s "'" 25 | } 26 | }} 27 | -------------------------------------------------------------------------------- /surround.kak: -------------------------------------------------------------------------------- 1 | define-command -override -hidden surround-on-insert-open -params 2 %{ 2 | echo -debug "surround-on-insert-open" 3 | execute-keys -draft <\> a %arg{2} 4 | } 5 | 6 | define-command -override -hidden surround-on-delete-open -params 2 %{ 7 | echo -debug "surround-on-delete-open" 8 | try %{ 9 | evaluate-commands -draft -save-regs a -no-hooks %{ 10 | set-register a %arg{2} 11 | execute-keys -draft "l\Qad" 12 | } 13 | } 14 | } 15 | 16 | define-command -override -hidden surround-on-insert-close -params 2 %{ 17 | surround-on-delete-open %arg{@} 18 | } 19 | 20 | define-command -override -hidden surround-on-delete-close -params 2 %{ 21 | surround-on-insert-open %arg{@} 22 | } 23 | 24 | define-command -hidden setup-surround-pair -params 2 -override %{ 25 | evaluate-commands %sh{ 26 | escapequote() { printf "%s" "$*" | sed "s/'/''/g"; } 27 | set -- $(escapequote "$1") $(escapequote "$2") 28 | set -- "$1" "$2" $(escapequote "$1") $(escapequote "$2") 29 | printf "%s\n" "hook window -group surround InsertChar '\Q$1\E' 'surround-on-insert-open ''$3'' ''$4'' '" 30 | printf "%s\n" "hook window -group surround InsertDelete '\Q$1\E' 'surround-on-delete-open ''$3'' ''$4'' '" 31 | [ "$1" != "$2" ] && printf "%s\n" "hook window -group surround InsertChar '\Q$2\E' 'surround-on-insert-close ''$3'' ''$4'' '" 32 | [ "$1" != "$2" ] && printf "%s\n" "hook window -group surround InsertDelete '\Q$2\E' 'surround-on-delete-close ''$3'' ''$4'' '" 33 | } 34 | } 35 | 36 | define-command surround-mode -override %§ 37 | # TODO: Get these from a surround_pairs option 38 | setup-surround-pair "(" ")" 39 | setup-surround-pair "[" "]" 40 | setup-surround-pair "<" ">" 41 | setup-surround-pair "{" "}" 42 | setup-surround-pair "'" "'" 43 | setup-surround-pair '"' '"' 44 | setup-surround-pair '`' '`' 45 | 46 | # Disable https://github.com/alexherbo2/auto-pairs.kak in the surround mode 47 | # TODO: Is there a more intelligent way to do this? Maybe a more generic way 48 | # Maybe all hooks should be disabled, and ours marked -always, but that seems 49 | # Like a slippery slope as well 50 | try disable-auto-pairs 51 | execute-keys -with-hooks i 52 | 53 | hook window -group surround ModeChange pop:insert:.* %exp{ 54 | remove-hooks window surround 55 | # TODO: Remember whether auto-pairs was enabled before 56 | try enable-auto-pairs 57 | } 58 | § 59 | --------------------------------------------------------------------------------