2014-11-05 22:02:34 +01:00
|
|
|
decl -hidden str jedi_tmp_dir
|
2016-04-01 02:27:23 +02:00
|
|
|
decl -hidden completions jedi_completions
|
2016-02-28 19:48:59 +01:00
|
|
|
decl str-list jedi_python_path ''
|
2014-11-05 22:02:34 +01:00
|
|
|
|
2015-08-03 20:44:27 +02:00
|
|
|
def jedi-complete -docstring "Complete the current selection with jedi" %{
|
2014-11-05 22:02:34 +01:00
|
|
|
%sh{
|
|
|
|
dir=$(mktemp -d -t kak-jedi.XXXXXXXX)
|
|
|
|
mkfifo ${dir}/fifo
|
2016-04-23 07:47:01 +02:00
|
|
|
printf %s\\n "set buffer jedi_tmp_dir ${dir}"
|
2016-10-03 21:29:54 +02:00
|
|
|
printf %s\\n "eval -no-hooks write ${dir}/buf"
|
2014-11-05 22:02:34 +01:00
|
|
|
}
|
|
|
|
%sh{
|
|
|
|
dir=${kak_opt_jedi_tmp_dir}
|
2016-04-23 07:47:01 +02:00
|
|
|
printf %s\\n "eval -draft %{ edit! -fifo ${dir}/fifo *jedi-output* }"
|
2014-11-05 22:02:34 +01:00
|
|
|
(
|
|
|
|
cd $(dirname ${kak_buffile})
|
|
|
|
header="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}"
|
|
|
|
|
2016-02-28 19:48:59 +01:00
|
|
|
export PYTHONPATH="$kak_opt_jedi_python_path:$PYTHONPATH"
|
2014-11-06 20:17:13 +01:00
|
|
|
compl=$(python 2> "${dir}/fifo" <<-END
|
2014-11-05 22:02:34 +01:00
|
|
|
import jedi
|
|
|
|
script=jedi.Script(open('$dir/buf', 'r').read(), $kak_cursor_line, $kak_cursor_column - 1, '$kak_buffile')
|
2016-04-01 02:27:23 +02:00
|
|
|
print ':'.join([(str(c.name).replace("|", "\\|") + "|" + str(c.docstring()).replace("|", "\\|")).replace(":", "\\:") + "|" + str(c.name).replace("|", "\\|") for c in script.completions()]).replace("'", r"\\\\'")
|
2014-11-05 22:02:34 +01:00
|
|
|
END
|
|
|
|
)
|
2016-04-23 07:47:01 +02:00
|
|
|
printf %s\\n "${compl}" > /tmp/kak-jedi-out
|
|
|
|
printf %s\\n "eval -client ${kak_client} 'echo completed; set %{buffer=${kak_buffile}} jedi_completions \'${header}:${compl}\''" | kak -p ${kak_session}
|
2014-11-19 14:54:36 +01:00
|
|
|
rm -r ${dir}
|
2014-11-05 22:02:34 +01:00
|
|
|
) > /dev/null 2>&1 < /dev/null &
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-03 20:44:27 +02:00
|
|
|
def jedi-enable-autocomplete -docstring "Add jedi completion candidates to the completer" %{
|
2014-11-11 14:53:57 +01:00
|
|
|
set window completers "option=jedi_completions:%opt{completers}"
|
2014-11-05 22:02:34 +01:00
|
|
|
hook window -group jedi-autocomplete InsertIdle .* %{ try %{
|
|
|
|
exec -draft <a-h><a-k>\..\'<ret>
|
|
|
|
echo 'completing...'
|
|
|
|
jedi-complete
|
|
|
|
} }
|
2014-11-18 14:55:52 +01:00
|
|
|
alias window complete jedi-complete
|
2014-11-05 22:02:34 +01:00
|
|
|
}
|
|
|
|
|
2015-08-03 20:44:27 +02:00
|
|
|
def jedi-disable-autocomplete -docstring "Disable jedi completion" %{
|
2016-04-23 07:47:01 +02:00
|
|
|
set window completers %sh{ printf %s\\n "'${kak_opt_completers}'" | sed -e 's/option=jedi_completions://g' }
|
2014-11-05 22:02:34 +01:00
|
|
|
rmhooks window jedi-autocomplete
|
2014-11-18 14:55:52 +01:00
|
|
|
unalias window complete jedi-complete
|
2014-11-05 22:02:34 +01:00
|
|
|
}
|