-
Notifications
You must be signed in to change notification settings - Fork 5
/
kakrc
706 lines (619 loc) · 26.9 KB
/
kakrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
# TODO: There have been some quoting changes -- see kak_quoted_
## Sources.
source "%val{config}/plugins/kakoune-buffers/buffers.kak"
source "%val{config}/plugins/kakoune-find/find.kak"
source "%val{config}/plugins/kakoune-phantom-selection/phantom-selection.kak"
source "%val{config}/plugins/kakoune-mark/mark.kak"
source "%val{config}/plugins/kakoune-filetree/filetree.kak"
source "%val{config}/plugins/kakoune-gdb/gdb.kak"
source "%val{config}/plugins/kakoune-expand/expand.kak"
source "%val{config}/plugins/kak-lsp/rc/lsp.kak"
source "%val{config}/scripts/select-block.kak"
source "%val{config}/scripts/colorscheme-browser.kak"
source "%val{config}/scripts/snippet.kak"
source "%val{config}/scripts/char-input.kak"
source "%val{config}/scripts/strace.kak"
def module-hook -params 2 %{ hook global ModuleLoaded %arg{1} %arg{2} }
## General settings.
set global ui_options terminal_assistant=off terminal_wheel_down_button=0
set global startup_info_version 20240518
set global grepcmd 'rg -Hn'
#module-hook x11 %{ set global termcmd 'gnome-terminal -- bash -c' }
module-hook x11 %{ set global termcmd 'gnome-terminal -- winch-runner' }
#module-hook x11 %{ set global termcmd 'alacritty -e sh -c' }
set global autocomplete prompt
set global makecmd './make'
set global indentwidth 2
set global tabstop 8
#set global modelinefmt '%val{bufname} %val{cursor_line}:%val{cursor_char_column} {{context_info}} {{mode_info}} - %val{client}@[%val{session}]' # Default modeline.
set global modelinefmt '%val{bufname} %val{cursor_line}:%val{cursor_char_column} [%val{cursor_byte_offset}] {{context_info}} {{mode_info}} - %val{client}@[%val{session}]'
set global modelinefmt "%%opt{gdb_indicator} %opt{modelinefmt}"
# None of these colorschemes do what I want: Dark background, bright colors,
# lots of contrast, easy to distinguish faces, easy to read comments... It
# doesn't seem so unreasonable.
colorscheme desertex; face global comment rgb:7ccd7c
face global PrimaryCursor black,white+fg
face global SecondaryCursor bright-black,white+fg
face global PrimaryCursorEol black,rgb:7ccd7c+fg
face global SecondaryCursorEol bright-black,rgb:9ced9c+fg
#colorscheme default
face global Whitespace cyan
hook global WinCreate .* %{
addhl window/wrap wrap
addhl window/number-lines number-lines -relative -hlcursor
addhl window/show-whitespaces show-whitespaces -tab '‣' -tabpad '―' -lf ' ' -spc ' ' -nbsp '⍽'
addhl window/show-matching show-matching
addhl window/VisibleWords regex \b(?:FIXME|TODO|XXX)\b 0:default+rb
smarttab-enable
tab-completion-enable
show-trailing-whitespace-enable; face window TrailingWhitespace default,magenta
search-highlighting-enable; face window Search +bi
volatile-highlighting-enable; face window Volatile +bi
addhl window/SnippetHole \
regex (¹)|(²)|(³)|(⁴)|(⁵)|(⁶)|(⁷) \
1:default,red \
2:default,rgb:FF8000 \
3:default,yellow \
4:default,green \
5:default,blue \
6:default,rgb:6F00FF \
7:default,rgb:9F00FF
hook window InsertKey '<mouse:press_left:.*>' %{ exec '<c-u>' }
alias window jump-to-definition ctags-search
}
## Maps.
map global normal <%> '<c-s>%' # Save position before %
map global normal <'> ': select-word-better<ret>*'
map global normal <a-'> ': select-WORD-better<ret>*'
map global normal <=> ': phantom-selection-add-selection<ret>'
map global normal <a-=> ': phantom-selection-select-all; phantom-selection-clear<ret>'
map global normal <a-plus> ': phantom-selection-clear<ret>'
map global normal <a-9> ': phantom-selection-iterate-prev<ret>'
map global normal <a-0> ': phantom-selection-iterate-next<ret>'
# Can't emulate ^E/^Y perfectly. This is close, but maybe I should just use V.
#map global normal <c-e> 'vj'; map global normal <c-y> 'vk'
map global normal <c-e> 'jvj'; map global normal <c-y> 'kvk'
map global normal <minus> 'ga' # I can probably find a better use for <minus>.
map global normal <F1> ':new '
map global normal <F2> ': new exec :<ret>'
map global normal <F3> ': Two<ret>'
map global normal <F12> ': select-word-better<ret>'
map global normal <s-F12> ': select-WORD-better<ret>'
map global normal <a-minus> ': select-word-better; jump-to-definition<ret>'
map global normal <#> ': comment-line-better<ret>'
map global normal <a-#> ': comment-block<ret>'
map global normal <c-v> ': select-block<ret>'
map global normal <c-p> ': lint<ret>'
map global normal <c-n> ': next<ret>'
map global normal <c-a-n> ': prev<ret>'
map global normal <del> ': enter-user-mode gdb<ret>'
map global normal <s-del> ': enter-user-mode -lock gdb<ret>'
map global normal D ': expand<ret>'
map global insert <a-[> '<esc>: try replace-next-hole catch snippet-word<ret>'
map global insert <c-k> '<a-;>: char-input-begin "%val{config}/scripts/char-input-digraph.txt"<ret>'
map global insert <a-k> '<a-;>: char-input-begin "%val{config}/scripts/char-input-tex.txt"<ret>'
map global insert <a-K> '<a-;>: char-input-begin "%val{config}/scripts/char-input-unicode.txt"<ret>'
map global insert <c-a-k> '<a-;>: char-input-begin "%val{config}/local/char-input-extra.txt"<ret>'
map global insert <c-\> '\<a-;>: char-input-begin "%val{config}/scripts/char-input-tex.txt" h<ret>'
map global insert <c-w> '<a-;>: exec -draft b<lt>a-d<gt><ret>'
map global prompt <a-i> '(?i)'
map global prompt <a-o> '(?S)'
map global insert <c-space> <c-n><c-p> # Open autocomplete.
map global normal 0 ': zero "enter-user-mode lsp"<ret>'
# Available normal keys:
# ^ <ret> <ins> <F4>-<F11> 0 <backspace> (with :zero/:backspace)
# <a-[1-8,\\]> <a-ret>
# <c-[acgkmqrtwx]> (\0) <c-]> () <c-/> ()
# User map.
map global user m -docstring 'make' ': make<ret>'
map global user a -docstring 'select all occurrences' ': select-all-occurrences<ret>'
map global user = -docstring 'format text' ': format-text<ret>'
map global user w -docstring 'write' ': w<ret>'
map global user q -docstring 'quit' ': q<ret>'
map global user Z -docstring 'write-quit' ': wq<ret>'
map global user n -docstring 'next lint error' ': lint-next-error<ret>'
map global user <a-n> -docstring 'prev lint error' ': lint-previous-error<ret>'
map global user e -docstring 'eval selection' ': eval %val{selection}<ret>'
map global user c -docstring 'char info' ': show-char-info<ret>'
map global user h -docstring 'selection hull' ': hull<ret>'
map global user k -docstring 'man' ': select-word-better; man-selection-with-count<ret>'
map global user g -docstring 'git' ': enter-user-mode git<ret>'
map global user b -docstring 'buffers…' ': enter-buffers-mode<ret>'
map global user B -docstring 'buffers (lock)…' ': enter-user-mode -lock buffers<ret>'
map global user P -docstring 'paste clipboard before' ': exec "!xsel -ob<lt>ret>"<ret>'
map global user p -docstring 'paste clipboard after' ': exec "<lt>a-!>xsel -ob<lt>ret>"<ret>'
map global user O -docstring 'paste primary before' ': exec "!xsel -op<lt>ret>"<ret>'
map global user o -docstring 'paste primary after' ': exec "<lt>a-!>xsel -op<lt>ret>"<ret>'
map global user y -docstring 'yank clipboard' ': exec "<lt>a-|>xsel -ib<lt>ret>"<ret>'
map global user Y -docstring 'yank primary' ': exec "<lt>a-|>xsel -ip<lt>ret>"<ret>'
map global user <minus> -docstring '.c <-> .h' ': c-family-alternative-file<ret>'
map global user <plus> -docstring 'switch to [+] buffer' ': switch-to-modified-buffer<ret>'
map global user s -docstring 'set option' ': enter-user-mode set<ret>'
map global user <,> -docstring 'choose buffer' ': buffer-chooser<ret>'
map global user <.> -docstring 'choose file' ': file-chooser<ret>'
map global user f -docstring 'format' ': format<ret>'
map global user ';' -docstring 'format paragraph' ': format-paragraph<ret>'
def format-paragraph %{ exec -draft '<a-i>p<space>=' }
map global user / ': mark-word<ret>' -docstring 'mark word'
map global user ? ': mark-clear<ret>' -docstring 'clear marks'
map global user _ ': other-client-buffer<ret>' -docstring 'other client buffer'
map global user t -docstring 'fanciness off' ': FancinessOff<ret>'
map global user T -docstring 'fanciness on' ': FancinessOn<ret>'
## Configure plugins.
# snippet.kak
set global snippet_program "%val{config}/scripts/snippet"
set global snippet_file "%val{config}/local/snippets.yaml"
set global snippet_hole_pattern %{%%%\{\w+\}%%%|[⁰¹²³⁴⁵⁶⁷💙💚💛💜💝💟🧡]}
# char-input-mode.kak
set global char_input_auto_data "%val{config}/scripts/char-input-tex.txt"
# expand.kak
set global expand_commands %{
expand-impl %{ exec '<a-i>(' }
expand-impl %{ exec '<a-a>(' }
expand-impl %< exec '<a-i>{' >
expand-impl %< exec '<a-a>}' >
expand-impl %{ exec '<a-i>[' }
expand-impl %{ exec '<a-a>[' }
expand-impl %{ exec '<a-i><' }
expand-impl %{ exec '<a-a><' }
expand-impl %{ exec '<a-i>"' }
expand-impl %{ exec '<a-a>"' }
expand-impl %{ exec "<a-i>'" }
expand-impl %{ exec "<a-a>'" }
expand-impl %{ exec '<a-i>i' }
expand-impl %{ exec '<a-:><a-;>k<a-K>^$<ret><a-i>i' }
expand-impl %{ exec '<a-:>j<a-K>^$<ret><a-i>i' }
expand-impl %{ exec '<a-i>p' }
}
## Hooks.
# I've moved most of this section elsewhere -- it's probably superfluous now.
hook global BufOpenFifo '\*make\*' %{ alias global next make-next-error; alias global prev make-previous-error }
hook global BufOpenFifo '\*grep\*' %{ alias global next grep-next-match; alias global prev grep-previous-match }
hook global BufCreate '\*find\*' %{ alias global next find-next-match; alias global prev find-previous-match }
#hook global BufSetOption 'spell_last_lang=.*' %{ alias global next spell-next; unalias global prev } # Bug: Gets triggered in every new buf, or something?
hook -group opendir global \
RuntimeError ".*\d+:\d+: '\w+' (.*): is a directory" \
%{
echo
file-chooser %val{hook_param_capture_1}
}
## File types.
def filetype-hook -params 2 %{ hook global WinSetOption "filetype=(%arg{1})" %arg{2} }
filetype-hook man %{
try %{ rmhl window/number-lines }
}
filetype-hook makefile|go %{
try smarttab-disable
set window indentwidth 0
}
filetype-hook go %{
alias window format go-format-use-goimports
alias window jump-to-definition lsp-definition
Tabby 4
# TODO: lint
lsp-enable-window
}
filetype-hook c|cpp %{
def -override FancinessOn %{ clang-enable-autocomplete; clang-enable-diagnostics }
def -override FancinessOff %{ clang-disable-autocomplete; clang-disable-diagnostics }
FancinessOn
alias window lint clang-parse
alias window lint-next-error clang-diagnostics-next
set window formatcmd clang-format
map window object ';' 'c/\*,\*/<ret>' -docstring '/* comment */'
}
module-hook clang %{ set global clang_options '-Wno-pragma-once-outside-header' }
module-hook c-family %{ set global c_include_guard_style '' }
filetype-hook '|plain' %{
basic-autoindent-enable
}
module-hook c-family %{
addhl shared/c/code/keywords-custom regex \
\b(Struct|Union|Enum|Case|Default|OrCase|OrDefault|cast|global|numof)\b \
0:keyword
}
## Defs.
def Main %{ rename-client Main; set global jumpclient Main }
def Tools %{ new rename-client Tools; set global toolsclient Tools }
def Docs %{ new rename-client Docs; set global docsclient Docs }
def IDE %{ Main; Tools; Docs }
def Alternate %{
new rename-client Alternate
set global toolsclient Alternate
set global docsclient Alternate
}
def Two %{ Main; Alternate }
module-hook grep %{ alias global g grep }
# Bind things that do't take numeric arguments to the keys 0/<backspace>.
# Usage: map global normal 0 ': zero "exec gh"<ret>'
# map global normal <backspace> ': backspace "exec h"<ret>'
def zero -params 1 %{ eval %sh{[ "$kak_count" = 0 ] && echo "$1" || echo "exec '${kak_count}0'"} }
def backspace -params 1 %{ eval %sh{[ "$kak_count" = 0 ] && echo "$1" || echo "exec '${kak_count%?}'"} }
# Sort of a replacement for gq.
#def format-text %{ exec '|fmt<ret>' }
def format-text %{
exec '|par -w%opt{autowrap_column}<a-!><ret>'
#exec '|par "rTbqR" "B=.,?_A_a Q=_s>|" -w%opt{autowrap_column}<a-!><ret>'
}
def select-word-better %{
# Note: \w doesn't use extra_word_chars.
eval -itersel %{
try %{ exec '<a-i>w' } catch %{ exec '<a-l>s\w<ret>),<a-i>w' } catch %{}
}
exec '<a-k>\w<ret>'
}
def select-WORD-better %{
eval -itersel %{
try %{ exec '<a-i><a-w>' } catch %{ exec '<a-l>s\S<ret>),<a-i><a-w>' } catch %{}
}
exec '<a-k>\S<ret>'
}
def select-all-occurrences \
-docstring 'select all occurrences of the current selection' \
%{
# Should this use * or <a-*>? * adds \b on word boundaries.
#exec -save-regs 'ab/' %{*"aZ%s<ret>"bZ"az"b<a-z>a}
exec -save-regs 'ab/' %{<a-*>"aZ%s<ret>"bZ"az"b<a-z>a}
echo
}
def switch-to-modified-buffer %{
eval -save-regs a %{
reg a ''
try %{
eval -buffer * %{
eval %sh{[ "$kak_modified" = true ] && echo "reg a %{$kak_bufname}; fail"}
}
}
eval %sh{[ -z "$kak_main_reg_a" ] && echo "fail 'No modified buffers!'"}
buffer %reg{a}
}
}
# To comment/uncomment a selection containing multiple lines:
# Drop blank lines, unless any line contains unindented text.
# Find the leftmost non-whitespace column among all lines.
# If every line has a comment string starting at this column, delete them.
# (Optional: Among the lines not ending at the comment string,
# find the smallest number of spaces shared by all of them
# immediately after the comment string, and delete that as well.)
# Otherwise insert a comment string before this column.
def comment-line-better %{
eval %sh{[ -z "$kak_opt_comment_line" ] && echo "fail '%opt{comment_line} not set!"}
eval -draft -itersel -save-regs '/"a' %{
exec 'x<a-s>gi"aZ'
try %{
exec 'gh<a-k>\S<ret>' # Fail if all (non-empty) line are indented.
exec '"az'
} catch %{
exec '"az<a-K>^$<ret>"aZ' # Drop blank lines.
}
align-cursors-left
exec '"aZ<a-l>'
try %{
reg / "\A\Q%opt{comment_line}\E"
exec -itersel 's<ret>' # Fail if if any line fails to match.
exec '<a-d>'
try %{ # Optional: Remove common whitespace.
exec '<a-l><a-K>\A$<ret><a-;>;"aZ<a-l>s\A +<ret>'
align-cursors-left
exec '"a<a-z>u<a-d>'
}
} catch %{
exec '"az'
reg '"' %opt{comment_line}
exec P
}
}
# Maybe instead of maintaining the existing selection, this should select the
# comment column or the following whitespace, so that you can insert/delete
# whitespace yourself if you want, <a-J>-style.
}
def align-cursors-left \
-docstring 'set all cursor (and anchor) columns to the column of the leftmost cursor' \
%{ eval %sh{
col=$(echo "$kak_selections_desc" | tr ' ' '\n' | sed 's/^[0-9]\+\.[0-9]\+,[0-9]\+\.//' | sort -n | head -n1)
sels=$(echo "$kak_selections_desc" | sed "s/\.[0-9]\+/.$col/g")
echo "select $sels"
}}
def selection-hull \
-docstring 'The smallest single selection containing every selection.' \
%{
eval -save-regs 'ab' %{
exec '"aZ' '<space>"bZ'
try %{ exec '"az<a-space>' }
exec -itersel '"b<a-Z>u'
exec '"bz'
echo
}
}
alias global hull selection-hull
def show-char-info \
-docstring 'show information about character under cursor' \
%{
# This is easy, but it's not a great way of getting Unicode data (doesn't have
# names for control characters, isn't up to date).
echo %sh{
python3 <<-'EOF'
import os, unicodedata
char = chr(int(os.environ['kak_cursor_char_value']))
try:
info = '{} [{}]'.format(unicodedata.name(char), unicodedata.category(char))
except ValueError as e:
info = str(e)
print('U+{:x}: {}'.format(ord(char), info))
EOF
}
}
def del-trailing-whitespace %{
try %{
eval -draft %{
exec '%s\h+$<ret><a-d>'
eval -client %val{client} echo -- \
%sh{ echo "deleted trailing whitespace on $(echo "$kak_selections_desc" | wc -w) lines" }
}
} catch %{
echo 'no trailing whitespace'
}
}
#def go-format-use-goimports %{ go-format -use-goimports }
def go-format-use-goimports %{ gopls imports }
def man-selection-with-count %{
man %sh{
page="$kak_selection"
[ "$kak_count" != 0 ] && page="${page}(${kak_count})"
echo "$page"
}
}
def -docstring %{switch to the other client's buffer} \
other-client-buffer \
%{ eval %sh{
if [ "$(echo "$kak_client_list" | wc -w)" -ne 2 ]; then
echo "fail 'only works with two clients'"
exit
fi
set -- $kak_client_list
other_client="$1"
[ "$other_client" = "$kak_client" ] && other_client="$2"
echo "eval -client '$other_client' 'eval -client ''$kak_client'' \"buffer ''%val{bufname}''\"'"
}}
def Tabby -params ..1 \
-docstring 'Tabby mode. Optional argument: Tabstop.' \
%{
try smarttab-disable
try %{ rmhl window/show-whitespaces }
addhl window/show-whitespaces show-whitespaces -tab ' ' -tabpad ' ' -lf ' ' -spc ' ' -nbsp '⍽'
set window indentwidth 0
eval %sh{
[ -n "$1" ] && echo "set window tabstop $1"
}
}
# From the wiki.
def file-chooser-rofi \
-params ..1 \
-docstring 'Select files in project using Ag and Rofi' \
%{ eval %sh{
#file=$(ag -g "" "$@" | rofi -dmenu -i -p 'file')
#file=$(find . -type f | rofi -dmenu -i -p 'file')
file=$(fd -j1 -- "$@" | rofi -dmenu -i -p 'file')
if [ -n "$file" ]; then
# TODO: Escaping!
printf 'eval -client %%{%s} '\''edit %%{%s}'\''\n' "${kak_client}" "${file}" | kak -p "${kak_session}"
fi
}}
def buffer-chooser-rofi \
-docstring 'Select an open buffer using Rofi' \
%{ eval %sh{
buffer=$(printf %s\\n "${kak_buflist}" | tr ' ' '\n' | sed "s/^'//; s/'$//" | rofi -dmenu -i -p 'buffer')
if [ -n "$buffer" ]; then
echo "eval -client '$kak_client' 'buffer ${buffer}'" | kak -p ${kak_session}
fi
}}
# TODO: Proper escaping?
def file-chooser-fzf-tmux \
-params ..1 \
-docstring 'invoke fzf to open a file' \
%{ eval %sh{
if [ -n "$1" ]; then
echo "TODO: fix file-chooser-fzf-tmux" >&2
fi
if [ -z "$TMUX" ]; then
echo 'fail "only works inside tmux"'
exit
fi
file=$(find * -type f | fzf-tmux -d 15)
#file=$(ag -g "" "$@" | fzf-tmux -d 15)
if [ -n "$file" ]; then
printf 'eval -client %%{%s} edit %%{%s}\n' "${kak_client}" "${file}" | kak -p "${kak_session}"
fi
}}
def buffer-chooser-fzf-tmux \
-params ..1 \
-docstring 'invoke fzf to select a buffer' \
%{ eval %sh{
if [ -z "$TMUX" ]; then
echo 'fail "only works inside tmux"'
exit
fi
buffer=$(printf %s\\n "${kak_buflist}" | tr ' ' '\n' | sed "s/^'//; s/'$//" | fzf-tmux -d 15)
if [ -n "$buffer" ]; then
echo "eval -client '$kak_client' 'buffer ${buffer}'" | kak -p ${kak_session}
fi
}}
alias global file-chooser file-chooser-rofi
alias global buffer-chooser buffer-chooser-rofi
## More:
def git-log-lines %{
git log -L %sh{
anchor="${kak_selection_desc%,*}"
anchor_line="${anchor%.*}"
echo "$anchor_line,$kak_cursor_line:$kak_buffile"
}
}
def git-toggle-blame %{
try %{
addhl window/git-blame group
rmhl window/git-blame
git blame
} catch %{
git hide-blame
}
}
def git-hide-diff %{ rmhl window/git-diff }
declare-user-mode git
map global git b ': git-toggle-blame<ret>' -docstring 'blame (toggle)'
map global git l ': git log<ret>' -docstring 'log'
map global git c ': git commit<ret>' -docstring 'commit'
map global git d ': git diff<ret>' -docstring 'diff'
map global git s ': git status<ret>' -docstring 'status'
map global git h ': git show-diff<ret>' -docstring 'show diff'
map global git H ': git-hide-diff<ret>' -docstring 'hide diff'
map global git w ': git blame-jump<ret>' -docstring 'blame-jump'
map global git L ': git-log-lines<ret>' -docstring 'log blame'
# gdb extras.
declare-option str executable
def gdb-session-new-defaults %{
eval %sh{[ -z "$kak_opt_executable" ] && echo "fail '%opt{executable} not set'"}
gdb-session-new %opt{executable}
}
# Not sure about tbreak vs. advance. They do similar things in slightly different ways?
# tbreak has a problem with leftover temporary breakpoints?
# advance had some other problem I don't remember
def gdb-tbreak %{
eval %sh{
if [ "$kak_selection_desc" != "$kak_selections_desc" ]; then
echo "fail 'multiple selections'"
exit
fi
cursor="%{kak_selection_desc#*,}"
cursor_line="%{cursor%.*}"
selection_line="${kak_selection_desc%%.*}"
filename="$kak_buffile"
echo "gdb-cmd tbreak $filename:$selection_line"
}
}
def gdb-to-cursor %{ gdb-tbreak; gdb-continue-or-run }
hook global GlobalSetOption 'gdb_program_running=true' %{ face global GdbBreakpoint red,default }
hook global GlobalSetOption 'gdb_program_running=false' %{ face global GdbBreakpoint yellow,default }
declare-user-mode gdb
map global gdb <ret> ': gdb-session-new-defaults<ret>' -docstring 'new session'
map global gdb <backspace> ': gdb-session-stop<ret>' -docstring 'stop session'
map global gdb r ': gdb-run<ret>' -docstring 'run'
map global gdb R ': gdb-cmd start<ret>' -docstring 'start'
map global gdb k ': gdb-cmd kill<ret>' -docstring 'kill'
map global gdb s ': gdb-step<ret>' -docstring 'step'
map global gdb n ': gdb-next<ret>' -docstring 'next line'
map global gdb f ': gdb-finish<ret>' -docstring 'finish'
map global gdb c ': gdb-continue<ret>' -docstring 'continue' # swap with C?
map global gdb C ': gdb-continue-or-run<ret>' -docstring 'continue/run'
map global gdb j ': gdb-jump-to-location<ret>' -docstring 'jump to IP'
map global gdb J ': gdb-toggle-autojump<ret>' -docstring 'toggle autojump'
map global gdb b ': gdb-toggle-breakpoint<ret>' -docstring 'toggle breakpoint'
map global gdb p ': gdb-print<ret>' -docstring 'print selection expression'
map global gdb t ': gdb-backtrace<ret>' -docstring 'backtrace'
map global gdb <up> ': gdb-backtrace-up<ret>' -docstring 'backtrace ↑'
map global gdb <down> ': gdb-backtrace-down<ret>' -docstring 'backtrace ↓'
map global gdb : ':gdb-cmd ' -docstring 'custom command' # ?
map global gdb <space> ': gdb-to-cursor<ret>' -docstring 'to cursor'
map global gdb m ': gdb-cmd kill; make<ret>' -docstring 'kill and make' # ?
# Other gdb commands:
# gdb-{set,clear}-breakpoint gdb-{enable,disable}-autojump gdb-session-connect
# For some reason gdb-start is less well-behaved than gdb-cmd start?
# In particular gdb-start; gdb-cmd advance file:line doesn't work well,
# because it gets stopped on the temporary breakpoint gdb-start sets (?).
# smarttab.kak?
# Emulate expandtab smarttab, kind of.
# Due to #2122 this can only be done as a hook, not a map.
def smarttab-enable %{
hook -group smarttab window InsertChar \t %{ exec -draft -itersel "h%opt{indentwidth}@" }
hook -group smarttab window InsertDelete ' ' %{
eval -draft -itersel %{ try %{
exec 'hGh' "s\A(( {%opt{indentwidth}})*) *\z<ret>" '"1R'
}}
}
}
def smarttab-disable %{ rmhooks window smarttab }
# Highlight trailing whitespace in normal mode, with the TrailingWhitespace face.
# What I really want is to only not highlight trailing whitespace as I'm
# inserting it, but that doesn't seem possible right now.
def show-trailing-whitespace-enable %{
addhl window/TrailingWhitespace regex \h+$ 0:TrailingWhitespaceActive
face window TrailingWhitespaceActive TrailingWhitespace
hook -group trailing-whitespace window ModeChange '(push|pop):normal:insert' \
%{ face window TrailingWhitespaceActive '' }
hook -group trailing-whitespace window ModeChange '(push|pop):insert:normal' \
%{ face window TrailingWhitespaceActive TrailingWhitespace }
}
def show-trailing-whitespace-disable %{
try %{ rmhl window/TrailingWhitespace }
rmhooks window trailing-whitespace
}
face global TrailingWhitespace ''
# Tab completion.
def tab-completion-enable %{
hook -group tab-completion window InsertCompletionShow .* %{
try %{
#exec -draft 'h<a-K>\s<ret>'
map window insert <tab> <c-n>
map window insert <s-tab> <c-p>
}
}
hook -group tab-completion window InsertCompletionHide .* %{
unmap window insert <tab> <c-n>
unmap window insert <s-tab> <c-p>
}
}
def tab-completion-disable %{ rmhooks window tab-completion }
# Basic autoindent.
def -hidden basic-autoindent-on-newline %{
eval -draft -itersel %{
try %{ exec -draft ';K<a-&>' } # copy indentation from previous line
#try %{ exec -draft ';k<a-x><a-k>^\h+$<ret>H<a-d>' } # remove whitespace from autoindent on previous line
try %{ exec -draft ';kx<a-k>^\h+$<ret>H<a-d>' } # remove whitespace from autoindent on previous line
}
}
def -hidden basic-autoindent-trim %{
try %{ exec -draft 'x' '1s^(\h+)$<ret>' '<a-d>' }
}
def basic-autoindent-enable %{
hook -group basic-autoindent window InsertChar '\n' basic-autoindent-on-newline
hook -group basic-autoindent window ModeChange 'pop:insert:normal' basic-autoindent-trim
hook -group basic-autoindent window WinSetOption 'filetype=.*' basic-autoindent-disable
}
def basic-autoindent-disable %{ rmhooks window basic-autoindent }
# This is also kind of silly.
declare-user-mode set
map global set g ':set global ' -docstring 'global'
map global set b ':set buffer ' -docstring 'buffer'
map global set w ':set window ' -docstring 'window'
# volatile-highlighting.kak with some changes. Mainly:
# * Match more keys in the deactivate hook
# * Remove the deactivate hook when not active, to clean up debug hook log
def -hidden volatile-highlighting-deactivate %{
try %{ rmhl window/VolatileHighlighting }
rmhooks window volatile-highlighting-active
}
face global VolatileHighlighting white,yellow
def volatile-highlighting-enable %{
hook window -group volatile-highlighting NormalKey [ydcpP] %{ try %{
addhl window/VolatileHighlighting dynregex '\Q%reg{"}\E' 0:Volatile
hook window -group volatile-highlighting-active NormalKey '[^ydcpP]|..+' volatile-highlighting-deactivate
hook window -group volatile-highlighting-active InsertKey '.*' volatile-highlighting-deactivate
}}
}
def volatile-highlighting-disable %{
volatile-highlighting-deactivate
rmhooks window volatile-highlighting
}
# search-highlighting.kak, simplified
face global Search white,yellow
def search-highlighting-enable %{
hook window -group search-highlighting NormalKey [/?*nN]|<a-[/?*nN]> %{ try %{
addhl window/SearchHighlighting dynregex '%reg{/}' 0:Search
}}
hook window -group search-highlighting NormalKey <esc> %{ try %{ rmhl window/SearchHighlighting } }
}
def search-highlighting-disable %{
try %{ rmhl window/SearchHighlighting }
rmhooks window search-highlighting
}
# More things.
eval %sh{[ -r "$kak_config/local/kakrc" ] && echo 'source "%val{config}/local/kakrc"' || echo 'echo -debug "no local kakrc"' }