This repository has been archived by the owner on Mar 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rainbow.kak
60 lines (55 loc) · 1.95 KB
/
rainbow.kak
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
declare-option -hidden range-specs rainbow
declare-option regex rainbow_opening "[\[{(]"
declare-option bool rainbow_highlight_background false
declare-option str-list rainbow_faces "bright-red" "bright-green" "bright-yellow" "bright-blue" "bright-magenta" "bright-cyan"
define-command -docstring "highlight the current buffer once" rainbow %{
set-option window rainbow "%val{timestamp}"
try %{
add-highlighter window/ ranges rainbow
}
evaluate-commands -save-regs '/' -draft %{
set-register / "%opt{rainbow_opening}"
execute-keys \%
try %{
rainbow-selection 0
}
}
}
define-command -hidden rainbow-selection -params 1 %{
evaluate-commands %sh{
index=$1
eval "set -- $kak_quoted_opt_rainbow_faces"
length=$#
next_index=$(( (index + 1) % (length - 1) ))
index=$(( index + 1 ))
eval face=\$$index
select_ends=""
if ! $kak_opt_rainbow_highlight_background; then
select_ends="execute-keys <a-S>"
fi
echo "
execute-keys s<ret>m
evaluate-commands -draft %{
$select_ends
evaluate-commands -itersel %{
set-option -add window rainbow \"%val{selection_desc}|$face\"
}
}
execute-keys <a-K>\A..\z<ret> #if there is no content do not recurse
evaluate-commands -itersel -draft %{
execute-keys H<a-\;>L
try %{
rainbow-selection $next_index
}
}
"
}
}
define-command -docstring "highlight the current buffer continuously" rainbow-enable %{
hook -group rainbow window InsertIdle .* %{ rainbow }
hook -group rainbow window NormalIdle .* %{ rainbow }
}
define-command -docstring "stop highlighting the current buffer" rainbow-disable %{
remove-highlighter window/ranges_rainbow
remove-hooks window rainbow
}