2014-11-06 00:02:34 +03:00
|
|
|
decl -hidden str jedi_tmp_dir
|
|
|
|
decl -hidden str-list jedi_completions
|
|
|
|
|
|
|
|
def jedi-complete %{
|
|
|
|
%sh{
|
|
|
|
dir=$(mktemp -d -t kak-jedi.XXXXXXXX)
|
|
|
|
mkfifo ${dir}/fifo
|
|
|
|
echo "set buffer jedi_tmp_dir ${dir}"
|
|
|
|
echo "write ${dir}/buf"
|
|
|
|
}
|
|
|
|
%sh{
|
|
|
|
dir=${kak_opt_jedi_tmp_dir}
|
2014-11-19 16:54:36 +03:00
|
|
|
echo "eval -draft %{ edit! -fifo ${dir}/fifo *jedi-output* }"
|
2014-11-06 00:02:34 +03:00
|
|
|
(
|
|
|
|
cd $(dirname ${kak_buffile})
|
|
|
|
header="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}"
|
|
|
|
|
2014-11-06 22:17:13 +03:00
|
|
|
compl=$(python 2> "${dir}/fifo" <<-END
|
2014-11-06 00:02:34 +03:00
|
|
|
import jedi
|
|
|
|
script=jedi.Script(open('$dir/buf', 'r').read(), $kak_cursor_line, $kak_cursor_column - 1, '$kak_buffile')
|
2014-11-07 16:54:43 +03:00
|
|
|
print ':'.join([str(c.name) + "@" + str(c.description).replace(":", "\\:") for c in script.completions()])
|
2014-11-06 00:02:34 +03:00
|
|
|
END
|
|
|
|
)
|
|
|
|
echo "eval -client ${kak_client} %[ echo completed; set 'buffer=${kak_buffile}' jedi_completions %[${header}:${compl}] ]" | kak -p ${kak_session}
|
2014-11-19 16:54:36 +03:00
|
|
|
rm -r ${dir}
|
2014-11-06 00:02:34 +03:00
|
|
|
) > /dev/null 2>&1 < /dev/null &
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def jedi-enable-autocomplete %{
|
2014-11-11 16:53:57 +03:00
|
|
|
set window completers "option=jedi_completions:%opt{completers}"
|
2014-11-06 00:02:34 +03:00
|
|
|
hook window -group jedi-autocomplete InsertIdle .* %{ try %{
|
|
|
|
exec -draft <a-h><a-k>\..\'<ret>
|
|
|
|
echo 'completing...'
|
|
|
|
jedi-complete
|
|
|
|
} }
|
2014-11-18 16:55:52 +03:00
|
|
|
alias window complete jedi-complete
|
2014-11-06 00:02:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
def jedi-disable-autocomplete %{
|
|
|
|
set window completers %sh{ echo "'${kak_opt_completers}'" | sed -e 's/option=jedi_completions://g' }
|
|
|
|
rmhooks window jedi-autocomplete
|
2014-11-18 16:55:52 +03:00
|
|
|
unalias window complete jedi-complete
|
2014-11-06 00:02:34 +03:00
|
|
|
}
|