2013-03-14 17:12:14 +04:00
|
|
|
decl str clang_options
|
2014-04-03 22:00:42 +04:00
|
|
|
|
|
|
|
decl -hidden str clang_filename
|
|
|
|
decl -hidden str-list clang_completions
|
2013-03-14 17:12:14 +04:00
|
|
|
|
|
|
|
def clang-complete %{
|
|
|
|
%sh{
|
|
|
|
filename=$(mktemp -d -t kak-clang.XXXXXXXX)/buffer.cpp
|
2013-10-30 13:38:40 +04:00
|
|
|
echo "set buffer clang_filename $filename"
|
2013-03-14 17:12:14 +04:00
|
|
|
echo "write $filename"
|
|
|
|
}
|
|
|
|
# end the previous %sh{} so that its output gets interpreted by kakoune
|
|
|
|
# before launching the following as a background task.
|
|
|
|
%sh{
|
2013-03-19 16:57:23 +04:00
|
|
|
# this runs in a detached shell, asynchronously, so that kakoune does not hang while clang is running.
|
|
|
|
# As completions references a cursor position and a buffer timestamp, only valid completions should be
|
2013-03-14 17:12:14 +04:00
|
|
|
# displayed.
|
|
|
|
(
|
2013-03-19 16:57:23 +04:00
|
|
|
pos=-:${kak_cursor_line}:${kak_cursor_column}
|
2014-03-02 05:07:29 +04:00
|
|
|
cd $(dirname ${kak_buffile})
|
2014-03-28 02:00:14 +04:00
|
|
|
clang++ -x c++ -fsyntax-only ${kak_opt_clang_options} -Xclang -code-completion-at=${pos} - < ${kak_opt_clang_filename} 2>&1 | awk -e '
|
|
|
|
function rmblocks(opening, closing, val, res) {
|
|
|
|
while (match(val, opening)) {
|
|
|
|
res = res substr(val, 1, RSTART-1)
|
|
|
|
val = substr(val, RSTART + RLENGTH)
|
|
|
|
if (match(val, closing))
|
|
|
|
val = substr(val, RSTART + RLENGTH)
|
|
|
|
}
|
|
|
|
return res val
|
|
|
|
}
|
|
|
|
BEGIN { out = ENVIRON["kak_cursor_line"] "." ENVIRON["kak_cursor_column"] "@" ENVIRON["kak_timestamp"] }
|
|
|
|
/^COMPLETION:[^:]+:/ {
|
|
|
|
gsub("^COMPLETION:[^:]+: +", ""); gsub(":", "\\:")
|
|
|
|
c = rmblocks("\\[#", "#\\]", rmblocks("<#", "#>", rmblocks("\\{#", "#\\}", $0)))
|
2014-03-29 13:11:09 +04:00
|
|
|
gsub("\\((, )+\\)", "(", c); gsub("<(, )+>", "<", c)
|
2014-03-28 02:00:14 +04:00
|
|
|
out = out ":" c
|
|
|
|
}
|
|
|
|
END {
|
|
|
|
cmd = "kak -p " ENVIRON["kak_session"]
|
|
|
|
print "eval -client " ENVIRON["kak_client"] " %[ echo completed; set buffer clang_completions %[" out "] ]" | cmd
|
|
|
|
}'
|
2013-03-14 17:12:14 +04:00
|
|
|
rm -r $(dirname ${kak_opt_clang_filename})
|
2014-03-06 07:35:38 +04:00
|
|
|
) > /dev/null 2>&1 < /dev/null &
|
2013-03-14 17:12:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def clang-enable-autocomplete %{
|
2014-03-15 07:14:23 +04:00
|
|
|
set window completers %sh{ echo "'option=clang_completions:${kak_opt_completers}'" }
|
2014-06-16 23:42:12 +04:00
|
|
|
hook window -group clang-autocomplete InsertIdle .* %{ try %{
|
2014-01-25 22:49:44 +04:00
|
|
|
exec -draft <a-h><a-k>(\.|->|::).$<ret>
|
2013-10-31 23:14:44 +04:00
|
|
|
echo 'completing...'
|
|
|
|
clang-complete
|
2013-11-07 22:50:16 +04:00
|
|
|
} }
|
2013-03-14 17:12:14 +04:00
|
|
|
}
|
2013-04-11 16:30:02 +04:00
|
|
|
|
2014-03-15 07:14:23 +04:00
|
|
|
def clang-disable-autocomplete %{
|
|
|
|
set window completers %sh{ echo "'${kak_opt_completers}'" | sed -e 's/option=clang_completions://g' }
|
|
|
|
rmhooks window clang-autocomplete
|
|
|
|
}
|