-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathipynb.kak
36 lines (31 loc) · 1.13 KB
/
ipynb.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
hook -group ipynb global BufOpenFile .*[.](ipynb) %{
set-option buffer filetype ipynb
}
hook -group ipynb global WinSetOption filetype=ipynb %{
require-module json
require-module ipynb
add-highlighter window/ipynb ref json
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ipynb }
set-option window formatcmd "jq ."
map window normal <ret> ":decode-field<ret>"
}
provide-module ipynb %{
define-command -hidden decode-field %{
try %{
evaluate-commands -save-regs j %{
execute-keys <a-a>r <">jy
edit -scratch "*ipynb-cell*"
set-option buffer filetype python
execute-keys -draft <">jP ggI{<">text<">:<esc>gea}<esc> <%> | jq<space>-r<space>'.text|join("")' <ret>
map buffer normal <ret> ":replace-field<ret>"
}
}
}
define-command -hidden replace-field %{
evaluate-commands -save-regs j %{
execute-keys -draft <%> | "jq -Rs ." <ret> <">jy
delete-buffer
execute-keys -draft <">jR s <\><\>n<"> <ret> Hd jd
}
}
}