blob: e4c24bf271eb6594941363d96c1e3ae97269dbda (
plain) (
blame)
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
|
def find -docstring "find files" -menu -params 1 \
%{ edit -existing %arg{1} } \
-shell-script-candidates %{ fd -t f --hidden --color=never -E .git }
def file-manager -params .. %{
terminal-singleton files env "DAFFM_PATH_RELATIVE_TO=%val{client_env_PWD}" daffm -c @kak %arg{@}
}
def findfzf -params .. %{
terminal-singleton fzf sh -c \
'kcr edit $(fd -t f --hidden --color=never -E .git | \
fzf --prompt='':find '' --multi --min-height=100 \
--preview=''bat --color=always {}'' \
--bind ''ctrl-o:execute(kcr edit {})'' \
$@)' findfzf-cmd %arg{@}
}
def findfzf-filtered -params 1 %{
terminal-singleton fzf sh -c \
'export pat=$1; kcr edit $(fd -t f --hidden --color=never -E .git | \
grep -E ''''$pat'''' | \
fzf --prompt='':find# '' --multi --min-height=100 \
--preview=''bat --color=always {}'' \
--info-command ''printf $pat'' \
)' findfzf-cmd %arg{1}
}
declare-user-mode file
map global user f ': enter-user-mode file<ret>' -docstring 'File mode'
map global file F ': find ' -docstring 'Find files'
map global file n ': file-manager %val{buffile}<ret>' -docstring 'File manager'
map global file f ': findfzf<ret>' -docstring 'Fzf'
map global file <c-f> ': findfzf -q %val{selection}<ret>' -docstring 'Fzf selection'
declare-user-mode buffer
map global user b ': enter-user-mode -count %val{count} buffer<ret>' -docstring 'Buffer mode'
map global buffer b ': buffer ' -docstring 'Switch buffer'
map global buffer <ret> ': buffer-jump %val{count}; buffers-show<ret>' -docstring 'Jump to buffer'
map global buffer n ': buffer-next; buffers-show<ret>' -docstring 'Next buffer'
map global buffer p ': buffer-previous; buffers-show<ret>' -docstring 'Previous buffer'
map global buffer d ': delete-buffer; buffers-show<ret>' -docstring 'Delete buffer'
map global buffer s ': write<ret>' -docstring 'Save'
def buffers-show %{
info -title 'buffers' -markup %sh{
echo "$kak_quoted_buflist" | xargs -n1 | grep -v -E '^([*]debug[*])$' | while IFS= read buf; do
if [ -z "$buf" ]; then echo "{comment}<scratch>{Normal}"
elif [ "$buf" == "$kak_bufname" ]; then echo "{keyword}$buf{Normal}"
else echo "{Default}$buf{Normal}"
fi
done | nl -w 2
}
}
def buffer-jump -params 1 %{
evaluate-commands %sh{
if ! [ "$1" == "0" ]; then
buf=$(echo "$kak_quoted_buflist" | xargs -n1 | grep -v -E '^([*]debug[*])$' | head -n "$1" | tail -n1)
[ -z "$buf" ] || printf "buffer '%s'" $(echo "$buf" | sed "s/'/''/g")
fi
}
}
# Open directory (bits from explore.kak)
hook global RuntimeError '\d+:\d+: ''(?:edit|e)''(.+): is a directory' %{
file-manager %val(hook_param_capture_1)
}
hook global KakBegin .* %{ hook -once global WinCreate .* %{ hook -once global NormalIdle '' %{
try %{ evaluate-commands -draft -save-regs '/' %{
buffer *debug*
set-register / 'error while opening file ''(.+?)'':\n\h+(.+?): is a directory'
execute-keys '%1s<ret>'
evaluate-commands -draft -itersel %{
evaluate-commands -client %val(client) file-manager %reg(.)
}
}}
}}}
# Open file:linenum
hook global WinDisplay (.*):(\d+)$ %{
# Use string to eval quickly
# FIXME: Replace normalidle hack with better approach to "defer"
hook -once buffer NormalIdle .* "
delete-buffer %val{hook_param}
edit %val{hook_param_capture_1} %val{hook_param_capture_2}
"
}
|