Pass a generic pattern to printf calls, use echo when possible

This commit is contained in:
Frank LENORMAND 2016-04-23 08:47:01 +03:00
parent 664f382ab2
commit a20f5fc6a2
28 changed files with 135 additions and 142 deletions

View File

@ -7,7 +7,7 @@ decl str-list ctagsfiles 'tags'
def -params 0..1 \ def -params 0..1 \
-shell-completion ' -shell-completion '
( for tags in $(printf %s "${kak_opt_ctagsfiles}" | tr \':\' \'\n\'); ( for tags in $(printf %s\\n "${kak_opt_ctagsfiles}" | tr \':\' \'\n\');
do readtags -t "${tags}" -p "$1" do readtags -t "${tags}" -p "$1"
done ) | cut -f 1 | sort | uniq' \ done ) | cut -f 1 | sort | uniq' \
-docstring 'Jump to tag definition' \ -docstring 'Jump to tag definition' \
@ -15,7 +15,7 @@ def -params 0..1 \
%{ %sh{ %{ %sh{
export tagname=${1:-${kak_selection}} export tagname=${1:-${kak_selection}}
( (
for tags in $(printf %s "${kak_opt_ctagsfiles}" | tr ':' '\n'); do for tags in $(printf %s\\n "${kak_opt_ctagsfiles}" | tr ':' '\n'); do
readtags -t "${tags}" ${tagname} readtags -t "${tags}" ${tagname}
done done
) | awk -F '\t|\n' -e ' ) | awk -F '\t|\n' -e '
@ -34,7 +34,7 @@ def tag-complete -docstring "Insert completion candidates for the current select
%sh{ ( %sh{ (
compl=$(readtags -p "$kak_selection" | cut -f 1 | sort | uniq | sed -e 's/:/\\:/g' | sed -e 's/\n/:/g' ) compl=$(readtags -p "$kak_selection" | cut -f 1 | sort | uniq | sed -e 's/:/\\:/g' | sed -e 's/\n/:/g' )
compl="${kak_cursor_line}.${kak_cursor_column}+${#kak_selection}@${kak_timestamp}:${compl}" compl="${kak_cursor_line}.${kak_cursor_column}+${#kak_selection}@${kak_timestamp}:${compl}"
printf %s "set buffer=$kak_bufname ctags_completions '${compl}'" | kak -p ${kak_session} printf %s\\n "set buffer=$kak_bufname ctags_completions '${compl}'" | kak -p ${kak_session}
) > /dev/null 2>&1 < /dev/null & } ) > /dev/null 2>&1 < /dev/null & }
}} }}
@ -45,7 +45,7 @@ def ctags-funcinfo -docstring "Display ctags information about a selected functi
%sh{ %sh{
sigs=$(readtags -e ${kak_selection%(} | grep kind:f | sed -re 's/^(\S+).*((class|struct|namespace):(\S+))?.*signature:(.*)$/\5 [\4::\1]/') sigs=$(readtags -e ${kak_selection%(} | grep kind:f | sed -re 's/^(\S+).*((class|struct|namespace):(\S+))?.*signature:(.*)$/\5 [\4::\1]/')
if [ -n "$sigs" ]; then if [ -n "$sigs" ]; then
printf %s "eval -client ${kak_client} %{info -anchor $kak_cursor_line.$kak_cursor_column -placement above '$sigs'}" printf %s\\n "eval -client ${kak_client} %{info -anchor $kak_cursor_line.$kak_cursor_column -placement above '$sigs'}"
fi fi
} }
} }
@ -75,7 +75,7 @@ def ctags-generate -docstring 'Generate tag file asynchronously' %{
msg="tags generation failed" msg="tags generation failed"
fi fi
printf %s "eval -client $kak_client echo -color Information '${msg}'" | kak -p ${kak_session} printf %s\\n "eval -client $kak_client echo -color Information '${msg}'" | kak -p ${kak_session}
) > /dev/null 2>&1 < /dev/null & } ) > /dev/null 2>&1 < /dev/null & }
} }

View File

@ -53,7 +53,7 @@ addhl -group /dlang/code regex "\b(this)\b\s*[^(]" 1:value
decorators="disable|property|nogc|safe|trusted|system" decorators="disable|property|nogc|safe|trusted|system"
# Add the language's grammar to the static completion list # Add the language's grammar to the static completion list
printf %s "hook global WinSetOption filetype=dlang %{ printf %s\\n "hook global WinSetOption filetype=dlang %{
set window static_words '${keywords}:${attributes}:${types}:${values}:${decorators}' set window static_words '${keywords}:${attributes}:${types}:${values}:${decorators}'
}" | sed 's,|,:,g' }" | sed 's,|,:,g'

View File

@ -36,7 +36,7 @@ addhl -group /golang/code regex %{-?([0-9]*\.(?!0[xX]))?\b([0-9]+|0[xX][0-9a-fA-
values="false|true|nil" values="false|true|nil"
# Add the language's grammar to the static completion list # Add the language's grammar to the static completion list
printf %s "hook global WinSetOption filetype=golang %{ printf %s\\n "hook global WinSetOption filetype=golang %{
set window static_words '${keywords}:${attributes}:${types}:${values}' set window static_words '${keywords}:${attributes}:${types}:${values}'
}" | sed 's,|,:,g' }" | sed 's,|,:,g'

View File

@ -35,12 +35,12 @@ addhl -group /lua/code regex \b(and|break|do|else|elseif|end|false|for|function|
def lua-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ %sh{ def lua-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ %sh{
case $kak_buffile in case $kak_buffile in
*spec/*_spec.lua) *spec/*_spec.lua)
altfile=$(eval printf %s $(printf %s $kak_buffile | sed s+spec/+'*'/+';'s/_spec//)) altfile=$(eval printf %s\\n $(printf %s\\n $kak_buffile | sed s+spec/+'*'/+';'s/_spec//))
[ ! -f $altfile ] && printf %s "echo -color Error 'implementation file not found'" && exit [ ! -f $altfile ] && echo "echo -color Error 'implementation file not found'" && exit
;; ;;
*.lua) *.lua)
path=$kak_buffile path=$kak_buffile
dirs=$(while [ $path ]; do printf %s $path; path=${path%/*}; done | tail -n +2) dirs=$(while [ $path ]; do printf %s\\n $path; path=${path%/*}; done | tail -n +2)
for dir in $dirs; do for dir in $dirs; do
altdir=$dir/spec altdir=$dir/spec
if [ -d $altdir ]; then if [ -d $altdir ]; then
@ -48,13 +48,13 @@ def lua-alternative-file -docstring 'Jump to the alternate file (implementation
break break
fi fi
done done
[ ! -d $altdir ] && printf %s "echo -color Error 'spec/ not found'" && exit [ ! -d $altdir ] && echo "echo -color Error 'spec/ not found'" && exit
;; ;;
*) *)
printf %s "echo -color Error 'alternative file not found'" && exit echo "echo -color Error 'alternative file not found'" && exit
;; ;;
esac esac
printf %s "edit $altfile" printf %s\\n "edit $altfile"
}} }}
def -hidden _lua_filter_around_selections %{ def -hidden _lua_filter_around_selections %{

View File

@ -44,7 +44,7 @@ addhl -group /perl/comment fill comment
values="ARGV|STDERR|STDOUT|ARGVOUT|STDIN|__DATA__|__END__|__FILE__|__LINE__|__PACKAGE__" values="ARGV|STDERR|STDOUT|ARGVOUT|STDIN|__DATA__|__END__|__FILE__|__LINE__|__PACKAGE__"
# Add the language's grammar to the static completion list # Add the language's grammar to the static completion list
printf %s "hook global WinSetOption filetype=perl %{ printf %s\\n "hook global WinSetOption filetype=perl %{
set window static_words '${keywords}:${attributes}:${values}' set window static_words '${keywords}:${attributes}:${values}'
}" | sed 's,|,:,g' }" | sed 's,|,:,g'

View File

@ -65,7 +65,7 @@ addhl -group /ruby/code regex \b([A-Za-z]\w*:)|([$@][A-Za-z]\w*)|(\W\K:[A-Za-z]\
meta="require|include" meta="require|include"
# Add the language's grammar to the static completion list # Add the language's grammar to the static completion list
printf %s "hook global WinSetOption filetype=ruby %{ printf %s\\n "hook global WinSetOption filetype=ruby %{
set window static_words '${keywords}:${attributes}:${values}:${meta}' set window static_words '${keywords}:${attributes}:${values}:${meta}'
}" | sed 's,|,:,g' }" | sed 's,|,:,g'

View File

@ -5,13 +5,13 @@ def -params ..1 spell -docstring "Check spelling of the current buffer with aspe
try %{ addhl ranges 'spell_regions' } try %{ addhl ranges 'spell_regions' }
%sh{ %sh{
file=$(mktemp -d -t kak-spell.XXXXXXXX)/buffer file=$(mktemp -d -t kak-spell.XXXXXXXX)/buffer
printf %s "write ${file}" printf %s\\n "write ${file}"
printf %s "set buffer spell_tmp_file ${file}" printf %s\\n "set buffer spell_tmp_file ${file}"
} }
%sh{ %sh{
if [ $# -ge 1 ]; then if [ $# -ge 1 ]; then
if [ ${#1} -ne 2 -a ${#1} -ne 5 ]; then if [ ${#1} -ne 2 -a ${#1} -ne 5 ]; then
printf %s "echo -color Error Invalid language code (examples of expected format: en, en_US, en-US)" echo 'echo -color Error Invalid language code (examples of expected format: en, en_US, en-US)'
rm -r $(dirname $kak_opt_spell_tmp_file) rm -r $(dirname $kak_opt_spell_tmp_file)
exit 1 exit 1
else else
@ -25,20 +25,20 @@ def -params ..1 spell -docstring "Check spelling of the current buffer with aspe
while read line; do while read line; do
case $line in case $line in
\&*) \&*)
begin=$(printf %s "$line" | cut -d ' ' -f 4 | sed 's/:$//') begin=$(printf %s\\n "$line" | cut -d ' ' -f 4 | sed 's/:$//')
;& ;&
'#'*) '#'*)
word=$(printf %s "$line" | cut -d ' ' -f 2) word=$(printf %s\\n "$line" | cut -d ' ' -f 2)
begin=${begin:-$(printf %s "$line" | cut -d ' ' -f 3)} begin=${begin:-$(printf %s\\n "$line" | cut -d ' ' -f 3)}
end=$((begin + ${#word})) end=$((begin + ${#word}))
# printf %s "echo -debug -- line: $line_num, word: $word, begin: $begin, end: $end" # printf %s\\n "echo -debug -- line: $line_num, word: $word, begin: $begin, end: $end"
regions="$regions:$line_num.$begin,$line_num.$end|Error" regions="$regions:$line_num.$begin,$line_num.$end|Error"
;; ;;
'') ((++line_num)) ;; '') ((++line_num)) ;;
*) ;; *) ;;
esac esac
done done
printf %s "set buffer spell_regions %{$regions}" printf %s\\n "set buffer spell_regions %{$regions}"
} }
rm -r $(dirname $kak_opt_spell_tmp_file) rm -r $(dirname $kak_opt_spell_tmp_file)
} }

View File

@ -77,7 +77,7 @@ def -hidden _c-family-indent-on-closing-curly-brace %[
maybe_at='' maybe_at=''
fi fi
printf '%s' ' printf %s\\n '
addhl -group / regions -default code FT \ addhl -group / regions -default code FT \
string %{MAYBEAT(?<!QUOTE)"} %{(?<!\\)(\\\\)*"} "" \ string %{MAYBEAT(?<!QUOTE)"} %{(?<!\\)(\\\\)*"} "" \
comment /\* \*/ "" \ comment /\* \*/ "" \
@ -101,7 +101,7 @@ addhl -group /c/code regex %{\bNULL\b|\b-?(0x[0-9a-fA-F]+|\d+)[fdiu]?|'((\\.)?|[
types="void|char|short|int|long|signed|unsigned|float|double|size_t" types="void|char|short|int|long|signed|unsigned|float|double|size_t"
# Add the language's grammar to the static completion list # Add the language's grammar to the static completion list
printf %s "hook global WinSetOption filetype=c %{ printf %s\\n "hook global WinSetOption filetype=c %{
set window static_words '${keywords}' set window static_words '${keywords}'
set -add window static_words '${attributes}' set -add window static_words '${attributes}'
set -add window static_words '${types}' set -add window static_words '${types}'
@ -133,7 +133,7 @@ addhl -group /cpp/code regex %{\b-?(0x[0-9a-fA-F]+|\d+)[fdiu]?|'((\\.)?|[^'\\])'
values="this|true|false|NULL|nullptr" values="this|true|false|NULL|nullptr"
# Add the language's grammar to the static completion list # Add the language's grammar to the static completion list
printf %s "hook global WinSetOption filetype=cpp %{ printf %s\\n "hook global WinSetOption filetype=cpp %{
set window static_words '${keywords}' set window static_words '${keywords}'
set -add window static_words '${attributes}' set -add window static_words '${attributes}'
set -add window static_words '${types}' set -add window static_words '${types}'
@ -165,7 +165,7 @@ addhl -group /objc/code regex %{\b-?\d+[fdiu]?|'((\\.)?|[^'\\])'} 0:value
decorators="${decorators}|selector|autoreleasepool|try|catch|class|synchronized" decorators="${decorators}|selector|autoreleasepool|try|catch|class|synchronized"
# Add the language's grammar to the static completion list # Add the language's grammar to the static completion list
printf %s "hook global WinSetOption filetype=objc %{ printf %s\\n "hook global WinSetOption filetype=objc %{
set window static_words '${keywords}:${attributes}:${types}:${values}:${decorators}' set window static_words '${keywords}:${attributes}:${types}:${values}:${decorators}'
}" | sed 's,|,:,g' }" | sed 's,|,:,g'
@ -216,12 +216,12 @@ hook global WinSetOption filetype=(?!objc$).* %[ rmhl objc ]
decl str c_include_guard_style "ifdef" decl str c_include_guard_style "ifdef"
def -hidden _c-family-insert-include-guards %{ def -hidden _c-family-insert-include-guards %{
%sh{ %sh{
case "${kak_opt_c_include_guard_style,,}" in case "${kak_opt_c_include_guard_style}" in
ifdef) ifdef)
printf %s "exec ggi<c-r>%<ret><esc>ggxs\.<ret>c_<esc><space>A_INCLUDED<esc>ggxyppI#ifndef<space><esc>jI#define<space><esc>jI#endif<space>//<space><esc>O<esc>" echo 'exec ggi<c-r>%<ret><esc>ggxs\.<ret>c_<esc><space>A_INCLUDED<esc>ggxyppI#ifndef<space><esc>jI#define<space><esc>jI#endif<space>//<space><esc>O<esc>'
;; ;;
pragma) pragma)
printf %s "exec ggi#pragma<space>once<esc>" echo 'exec ggi#pragma<space>once<esc>'
;; ;;
*);; *);;
esac esac
@ -233,7 +233,7 @@ hook global BufNew .*\.(h|hh|hpp|hxx|H) _c-family-insert-include-guards
decl str-list alt_dirs ".;.." decl str-list alt_dirs ".;.."
def c-family-alternative-file -docstring "Jump to the alternate file (header/implementation)" %{ %sh{ def c-family-alternative-file -docstring "Jump to the alternate file (header/implementation)" %{ %sh{
alt_dirs=$(printf %s "${kak_opt_alt_dirs}" | sed -e 's/;/ /g') alt_dirs=$(printf %s\\n "${kak_opt_alt_dirs}" | sed -e 's/;/ /g')
file=$(basename "${kak_buffile}") file=$(basename "${kak_buffile}")
dir=$(dirname "${kak_buffile}") dir=$(dirname "${kak_buffile}")
@ -257,13 +257,13 @@ def c-family-alternative-file -docstring "Jump to the alternate file (header/imp
done done
;; ;;
*) *)
printf %s "echo -color Error 'extension not recognized'" echo "echo -color Error 'extension not recognized'"
exit exit
;; ;;
esac esac
if [ -f ${altname} ]; then if [ -f ${altname} ]; then
printf %s "edit '${altname}'" printf %s\\n "edit '${altname}'"
else else
printf %s "echo -color Error 'alternative file not found'" echo "echo -color Error 'alternative file not found'"
fi fi
}} }}

View File

@ -8,18 +8,18 @@ def comment-selection -docstring "Comment/uncomment the current selection" %{
%sh{ %sh{
function exec_proof { function exec_proof {
## Replace the '<' sign that is interpreted differently in `exec` ## Replace the '<' sign that is interpreted differently in `exec`
printf %s "$@" | sed 's,<,<lt>,g' printf %s\\n "$@" | sed 's,<,<lt>,g'
} }
readonly opening=$(exec_proof "${kak_opt_comment_selection_chars%%:*}") readonly opening=$(exec_proof "${kak_opt_comment_selection_chars%%:*}")
readonly closing=$(exec_proof "${kak_opt_comment_selection_chars##*:}") readonly closing=$(exec_proof "${kak_opt_comment_selection_chars##*:}")
if [ -z "${opening}" ] || [ -z "${closing}" ]; then if [ -z "${opening}" ] || [ -z "${closing}" ]; then
printf %s "The \`comment_selection_chars\` variable is empty, couldn't comment the selection" >&2 echo "echo -debug 'The \`comment_selection_chars\` variable is empty, could not comment the selection'"
exit exit
fi fi
printf %s "try %{ printf %s\\n "try %{
## The selection is empty ## The selection is empty
exec -draft %{<a-K>\A[\h\v\n]*\z<ret>} exec -draft %{<a-K>\A[\h\v\n]*\z<ret>}
@ -43,11 +43,11 @@ def comment-line -docstring "Comment/uncomment the current line" %{
readonly opening_escaped="\Q${opening}\E" readonly opening_escaped="\Q${opening}\E"
if [ -z "${opening}" ]; then if [ -z "${opening}" ]; then
printf %s "The \`comment_line_chars\` variable is empty, couldn't comment the line" >&2 echo "echo -debug 'The \`comment_line_chars\` variable is empty, could not comment the line'"
exit exit
fi fi
printf %s " printf %s\\n "
## Select the content of the line, without indentation ## Select the content of the line, without indentation
exec %{I<esc><a-l>} exec %{I<esc><a-l>}

View File

@ -10,7 +10,7 @@ def -hidden -params 1..2 _doc-open %{
rm ${manout} rm ${manout}
if [ "${retval}" -eq 0 ]; then if [ "${retval}" -eq 0 ]; then
printf %s " printf %s\\n "
edit! -scratch '*doc*' edit! -scratch '*doc*'
exec |cat<space>${colout}<ret>gg exec |cat<space>${colout}<ret>gg
nop %sh{rm ${colout}} nop %sh{rm ${colout}}
@ -18,11 +18,11 @@ def -hidden -params 1..2 _doc-open %{
" "
if [ $# -gt 1 ]; then if [ $# -gt 1 ]; then
needle=$(printf %s "$2" | sed 's,<,<lt>,g') needle=$(printf %s\\n "$2" | sed 's,<,<lt>,g')
printf %s "try %{ exec '%<a-s><a-k>(?i)^\h+[^\n]*?\Q${needle}\E<ret>\'' } catch %{ exec <space>gg }" printf %s\\n "try %{ exec '%<a-s><a-k>(?i)^\h+[^\n]*?\Q${needle}\E<ret>\'' } catch %{ exec <space>gg }"
fi fi
else else
printf %s "echo -color Error %{doc '$@' failed: see *debug* buffer for details}" printf %s\\n "echo -color Error %{doc '$@' failed: see *debug* buffer for details}"
rm ${colout} rm ${colout}
fi fi
} }
@ -31,7 +31,7 @@ def -hidden -params 1..2 _doc-open %{
def -params 1..2 \ def -params 1..2 \
-shell-completion %{ -shell-completion %{
find "${kak_runtime}/../doc/kak/manpages/" -type f -iname "*$@*.gz" -printf '%f\n' | while read l; do find "${kak_runtime}/../doc/kak/manpages/" -type f -iname "*$@*.gz" -printf '%f\n' | while read l; do
printf %s "${l%.*}" printf %s\\n "${l%.*}"
done done
} \ } \
doc -docstring "Open a buffer containing the documentation about a given subject" %{ doc -docstring "Open a buffer containing the documentation about a given subject" %{
@ -40,10 +40,10 @@ def -params 1..2 \
shift shift
if [ ! -f "${PATH_DOC}" ]; then if [ ! -f "${PATH_DOC}" ]; then
printf %s "echo -color Error No such doc file: ${PATH_DOC}" printf %s\\n "echo -color Error No such doc file: ${PATH_DOC}"
exit exit
fi fi
printf %s "eval -try-client %opt{docsclient} _doc-open ${PATH_DOC} $@" printf %s\\n "eval -try-client %opt{docsclient} _doc-open ${PATH_DOC} $@"
} }
} }

View File

@ -6,9 +6,9 @@ def format -docstring "Format the entire buffer with an external utility" %{
readonly x=$((kak_cursor_column - 1)) readonly x=$((kak_cursor_column - 1))
readonly y="${kak_cursor_line}" readonly y="${kak_cursor_line}"
printf %s "exec -draft %{%|${kak_opt_formatcmd// /<space>}<ret>}" printf %s\\n "exec -draft %{%|${kak_opt_formatcmd// /<space>}<ret>}"
## Try to restore the position of the cursor as it was prior to formatting ## Try to restore the position of the cursor as it was prior to formatting
printf %s "exec gg ${y}g ${x}l" printf %s\\n "exec gg ${y}g ${x}l"
fi fi
} }
} }

View File

@ -12,7 +12,7 @@ def -params .. -file-completion \
( ${kak_opt_grepcmd} "${kak_selection}" | tr -d '\r' > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null & ( ${kak_opt_grepcmd} "${kak_selection}" | tr -d '\r' > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null &
fi fi
printf %s "eval -try-client '$kak_opt_toolsclient' %{ printf %s\\n "eval -try-client '$kak_opt_toolsclient' %{
edit! -fifo ${output} -scroll *grep* edit! -fifo ${output} -scroll *grep*
set buffer filetype grep set buffer filetype grep
set buffer _grep_current_line 0 set buffer _grep_current_line 0

View File

@ -16,7 +16,7 @@ addhl -group / regions -default code kakrc \
values="default|black|red|green|yellow|blue|magenta|cyan|white" values="default|black|red|green|yellow|blue|magenta|cyan|white"
# Add the language's grammar to the static completion list # Add the language's grammar to the static completion list
printf %s "hook global WinSetOption filetype=kak %{ printf %s\\n "hook global WinSetOption filetype=kak %{
set window static_words '${keywords}:${values}' set window static_words '${keywords}:${values}'
}" | sed 's,|,:,g' }" | sed 's,|,:,g'

View File

@ -7,7 +7,7 @@ def -params .. make -docstring "Make utility wrapper" %{ %sh{
mkfifo ${output} mkfifo ${output}
( eval ${kak_opt_makecmd} "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null & ( eval ${kak_opt_makecmd} "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null &
printf %s "eval -try-client '$kak_opt_toolsclient' %{ printf %s\\n "eval -try-client '$kak_opt_toolsclient' %{
edit! -fifo ${output} -scroll *make* edit! -fifo ${output} -scroll *make*
set buffer filetype make set buffer filetype make
set buffer _make_current_error_line 0 set buffer _make_current_error_line 0

View File

@ -25,25 +25,25 @@ def -hidden -params .. _man %{ %sh{
col -b -x > ${colout} < ${manout} col -b -x > ${colout} < ${manout}
rm ${manout} rm ${manout}
if [ "${retval}" -eq 0 ]; then if [ "${retval}" -eq 0 ]; then
printf %s "edit! -scratch '*man*' printf %s\\n "edit! -scratch '*man*'
exec |cat<space>${colout}<ret>gk exec |cat<space>${colout}<ret>gk
nop %sh{rm ${colout}} nop %sh{rm ${colout}}
set buffer filetype man" set buffer filetype man"
else else
printf %s "echo -color Error %{man '$@' failed: see *debug* buffer for details }" printf %s\\n "echo -color Error %{man '$@' failed: see *debug* buffer for details }"
rm ${colout} rm ${colout}
fi fi
} } } }
def -params .. \ def -params .. \
-shell-completion %{ -shell-completion %{
prefix=$(printf %s "$1" | cut -c1-${kak_pos_in_token} 2>/dev/null) prefix=$(printf %s\\n "$1" | cut -c1-${kak_pos_in_token} 2>/dev/null)
for page in /usr/share/man/*/${prefix}*.[1-8]*; do for page in /usr/share/man/*/${prefix}*.[1-8]*; do
candidate=$(basename ${page%%.[1-8]*}) candidate=$(basename ${page%%.[1-8]*})
pagenum=$(printf %s "$page" | sed 's,^.*\.\([1-8].*\)\..*$,\1,') pagenum=$(printf %s\\n "$page" | sed 's,^.*\.\([1-8].*\)\..*$,\1,')
case $candidate in case $candidate in
*\*) ;; *\*) ;;
*) printf %s\\n $candidate\($pagenum\);; *) printf %s\\n "$candidate($pagenum)";;
esac esac
done done
} \ } \
@ -56,5 +56,5 @@ def -params .. \
subject=${subject%%\(*} subject=${subject%%\(*}
fi fi
printf %s "eval -collapse-jumps -try-client %opt{docsclient} _man $pagenum $subject" printf %s\\n "eval -collapse-jumps -try-client %opt{docsclient} _man $pagenum $subject"
} } } }

View File

@ -35,7 +35,7 @@ addhl -group /python/comment fill comment
types="bool|buffer|bytearray|complex|dict|file|float|frozenset|int|list|long|memoryview|object|set|str|tuple|unicode|xrange" types="bool|buffer|bytearray|complex|dict|file|float|frozenset|int|list|long|memoryview|object|set|str|tuple|unicode|xrange"
# Add the language's grammar to the static completion list # Add the language's grammar to the static completion list
printf %s "hook global WinSetOption filetype=python %{ printf %s\\n "hook global WinSetOption filetype=python %{
set window static_words '${values}:${meta}:${keywords}:${types}' set window static_words '${values}:${meta}:${keywords}:${types}'
}" | sed 's,|,:,g' }" | sed 's,|,:,g'

View File

@ -5,8 +5,10 @@
hook global KakBegin .* %{ hook global KakBegin .* %{
%sh{ %sh{
if [ -n "$TMUX" ]; then if [ -n "$TMUX" ]; then
printf %s "alias global focus tmux-focus" echo "
printf %s "alias global new tmux-new-horizontal" alias global focus tmux-focus
alias global new tmux-new-horizontal
"
fi fi
} }
} }
@ -15,7 +17,7 @@ hook global KakBegin .* %{
def -hidden -params 1.. tmux-new-impl %{ def -hidden -params 1.. tmux-new-impl %{
%sh{ %sh{
if [ -z "$TMUX" ]; then if [ -z "$TMUX" ]; then
printf %s "echo -color Error This command is only available in a tmux session" echo "echo -color Error 'This command is only available in a tmux session'"
exit exit
fi fi
tmux_args="$1" tmux_args="$1"
@ -41,9 +43,9 @@ def -docstring "focus given client" \
-params 0..1 -client-completion \ -params 0..1 -client-completion \
tmux-focus %{ %sh{ tmux-focus %{ %sh{
if [ $# -gt 1 ]; then if [ $# -gt 1 ]; then
printf %s "echo -color Error 'too many arguments, use focus [client]'" echo "echo -color Error 'too many arguments, use focus [client]'"
elif [ $# -eq 1 ]; then elif [ $# -eq 1 ]; then
printf %s "eval -client '$1' focus" printf %s\\n "eval -client '$1' focus"
elif [ -n "${kak_client_env_TMUX}" ]; then elif [ -n "${kak_client_env_TMUX}" ]; then
TMUX="${kak_client_env_TMUX}" tmux select-pane -t "${kak_client_env_TMUX_PANE}" > /dev/null TMUX="${kak_client_env_TMUX}" tmux select-pane -t "${kak_client_env_TMUX_PANE}" > /dev/null
fi fi

View File

@ -12,7 +12,7 @@ decl str termcmd %sh{
'xfce4-terminal -e ' ; do 'xfce4-terminal -e ' ; do
terminal=${termcmd%% *} terminal=${termcmd%% *}
if which $terminal > /dev/null 2>&1; then if which $terminal > /dev/null 2>&1; then
printf %s "'$termcmd'" printf %s\\n "'$termcmd'"
exit exit
fi fi
done done
@ -23,7 +23,7 @@ def -docstring 'create a new kak client for current session' \
-command-completion \ -command-completion \
x11-new %{ %sh{ x11-new %{ %sh{
if [ -z "${kak_opt_termcmd}" ]; then if [ -z "${kak_opt_termcmd}" ]; then
printf %s "echo -color Error 'termcmd option is not set'" echo "echo -color Error 'termcmd option is not set'"
exit exit
fi fi
if [ $# -ne 0 ]; then kakoune_params="-e '$@'"; fi if [ $# -ne 0 ]; then kakoune_params="-e '$@'"; fi
@ -34,9 +34,9 @@ def -docstring 'focus given client\'s window' \
-params 0..1 -client-completion \ -params 0..1 -client-completion \
x11-focus %{ %sh{ x11-focus %{ %sh{
if [ $# -gt 1 ]; then if [ $# -gt 1 ]; then
printf %s "echo -color Error 'too many arguments, use focus [client]'" echo "echo -color Error 'too many arguments, use focus [client]'"
elif [ $# -eq 1 ]; then elif [ $# -eq 1 ]; then
printf %s "eval -client '$1' focus" printf %s\\n "eval -client '$1' focus"
else else
xdotool windowactivate $kak_client_env_WINDOWID > /dev/null xdotool windowactivate $kak_client_env_WINDOWID > /dev/null
fi fi

View File

@ -14,12 +14,12 @@ def autorestore-restore-buffer -docstring "Restore the backup for the current fi
latest_backup_path=$(find "${buffer_dirname}" -maxdepth 1 -type f -readable -newer "${kak_bufname}" -name "\.${buffer_basename}\.kak\.*" -printf '%A@/%p\n' 2>/dev/null \ latest_backup_path=$(find "${buffer_dirname}" -maxdepth 1 -type f -readable -newer "${kak_bufname}" -name "\.${buffer_basename}\.kak\.*" -printf '%A@/%p\n' 2>/dev/null \
| sort -n -t. -k1 | sed -nr 's/^[^\/]+\///;$p') | sort -n -t. -k1 | sed -nr 's/^[^\/]+\///;$p')
if [ -z "${latest_backup_path}" ]; then if [ -z "${latest_backup_path}" ]; then
printf %s "eval -draft %{ autorestore-purge-backups }"; echo 'eval -draft %{ autorestore-purge-backups }'
exit; exit
fi fi
## Replace the content of the buffer with the content of the backup file ## Replace the content of the buffer with the content of the backup file
printf %s " printf %s\\n "
exec -draft %{ %d!cat<space>${latest_backup_path}<ret>d } exec -draft %{ %d!cat<space>${latest_backup_path}<ret>d }
echo -color Information 'Backup restored' echo -color Information 'Backup restored'
" "
@ -28,7 +28,7 @@ def autorestore-restore-buffer -docstring "Restore the backup for the current fi
## the current buffer has been saved ## the current buffer has been saved
## If the autorestore_purge_restored option has been unset right after the ## If the autorestore_purge_restored option has been unset right after the
## buffer was restored, do not remove the backup ## buffer was restored, do not remove the backup
printf %s " printf %s\\n "
hook -group autorestore global BufWritePost (.+/)?${kak_bufname} %{ hook -group autorestore global BufWritePost (.+/)?${kak_bufname} %{
nop %sh{ nop %sh{
if [ \"\${kak_opt_autorestore_purge_restored}\" = true ]; then if [ \"\${kak_opt_autorestore_purge_restored}\" = true ]; then

View File

@ -9,14 +9,14 @@ def clang-parse -params 0..1 -docstring "Parse the contents of the current buffe
%sh{ %sh{
dir=$(mktemp -d -t kak-clang.XXXXXXXX) dir=$(mktemp -d -t kak-clang.XXXXXXXX)
mkfifo ${dir}/fifo mkfifo ${dir}/fifo
printf %s "set buffer clang_tmp_dir ${dir}" printf %s\\n "set buffer clang_tmp_dir ${dir}"
printf %s "write ${dir}/buf" printf %s\\n "write ${dir}/buf"
} }
# end the previous %sh{} so that its output gets interpreted by kakoune # end the previous %sh{} so that its output gets interpreted by kakoune
# before launching the following as a background task. # before launching the following as a background task.
%sh{ %sh{
dir=${kak_opt_clang_tmp_dir} dir=${kak_opt_clang_tmp_dir}
printf %s "eval -draft %{ printf %s\\n "eval -draft %{
edit! -fifo ${dir}/fifo *clang-output* edit! -fifo ${dir}/fifo *clang-output*
set buffer filetype make set buffer filetype make
set buffer _make_current_error_line 0 set buffer _make_current_error_line 0
@ -72,11 +72,11 @@ def clang-parse -params 0..1 -docstring "Parse the contents of the current buffe
print id "|" docstrings[id] "|" menu print id "|" docstrings[id] "|" menu
} }
}' | paste -s -d ':' | sed -e "s/\\\\n/\\n/g; s/'/\\\\'/g") }' | paste -s -d ':' | sed -e "s/\\\\n/\\n/g; s/'/\\\\'/g")
printf %s "eval -client ${kak_client} echo 'clang completion done' printf %s\\n "eval -client ${kak_client} echo 'clang completion done'
set 'buffer=${kak_buffile}' clang_completions '${header}:${compl}'" | kak -p ${kak_session} set 'buffer=${kak_buffile}' clang_completions '${header}:${compl}'" | kak -p ${kak_session}
else else
clang++ -x ${ft} -fsyntax-only ${kak_opt_clang_options} - < ${dir}/buf 2> ${dir}/stderr clang++ -x ${ft} -fsyntax-only ${kak_opt_clang_options} - < ${dir}/buf 2> ${dir}/stderr
printf %s "eval -client ${kak_client} echo 'clang parsing done'" | kak -p ${kak_session} printf %s\\n "eval -client ${kak_client} echo 'clang parsing done'" | kak -p ${kak_session}
fi fi
flags=$(cat ${dir}/stderr | sed -rne " flags=$(cat ${dir}/stderr | sed -rne "
@ -90,7 +90,7 @@ def clang-parse -params 0..1 -docstring "Parse the contents of the current buffe
sed -e "s|<stdin>|${kak_bufname}|g" < ${dir}/stderr > ${dir}/fifo sed -e "s|<stdin>|${kak_bufname}|g" < ${dir}/stderr > ${dir}/fifo
printf %s "set 'buffer=${kak_buffile}' clang_flags %{${kak_timestamp}:${flags}} printf %s\\n "set 'buffer=${kak_buffile}' clang_flags %{${kak_timestamp}:${flags}}
set 'buffer=${kak_buffile}' clang_errors '${errors}'" | kak -p ${kak_session} set 'buffer=${kak_buffile}' clang_errors '${errors}'" | kak -p ${kak_session}
) > /dev/null 2>&1 < /dev/null & ) > /dev/null 2>&1 < /dev/null &
} }
@ -102,14 +102,9 @@ def -hidden clang-show-completion-info %[ try %[
eval -draft %[ eval -draft %[
exec '<space>{(<a-k>^\(<ret>b' exec '<space>{(<a-k>^\(<ret>b'
%sh[ %sh[
<<<<<<< f877c388fea0e794f663d62e3508c5d11832601e desc=$(printf %s\\n "${kak_opt_clang_completions}" | sed -ne "{ s/\([^\\]\):/\1\n/g }; /^${kak_selection}@/ { s/^[^@]\+@//; s/@.*$//; s/\\\:/:/g; P }; D")
desc=$(echo "${kak_opt_clang_completions}" | sed -ne "{ s/\([^\\]\):/\1\n/g }; /^${kak_selection}@/ { s/^[^@]\+@//; s/@.*$//; s/\\\:/:/g; P }; D")
=======
# desc=$(printf %s "${kak_opt_clang_completions}" | sed -e 's/\([^\\]\):/\1\n/g;' | sed -ne "/^${kak_selection}@/ { s/^[^@]\+@//; s/@.*$//; s/\\:/:/g; p }")
desc=$(printf %s "${kak_opt_clang_completions}" | sed -ne "{ s/\([^\\]\):/\1\n/g }; /^${kak_selection}@/ { s/^[^@]\+@//; s/@.*$//; s/\\\:/:/g; P }; D")
>>>>>>> Replace non POSIX calls to `echo` with `printf %s`
if [ -n "$desc" ]; then if [ -n "$desc" ]; then
printf %s "eval -client $kak_client %{info -anchor ${kak_cursor_line}.${kak_cursor_column} -placement above %{${desc}}}" printf %s\\n "eval -client $kak_client %{info -anchor ${kak_cursor_line}.${kak_cursor_column} -placement above %{${desc}}}"
fi fi
] ] ] ]
] ] ] ]
@ -128,21 +123,15 @@ def clang-enable-autocomplete -docstring "Enable completion with clang" %{
} }
def clang-disable-autocomplete -docstring "Disable automatic clang completion" %{ def clang-disable-autocomplete -docstring "Disable automatic clang completion" %{
set window completers %sh{ printf %s "'${kak_opt_completers}'" | sed -e 's/option=clang_completions://g' } set window completers %sh{ printf %s\\n "'${kak_opt_completers}'" | sed -e 's/option=clang_completions://g' }
rmhooks window clang-autocomplete rmhooks window clang-autocomplete
unalias window complete clang-complete unalias window complete clang-complete
} }
def -hidden clang-show-error-info %{ %sh{ def -hidden clang-show-error-info %{ %sh{
<<<<<<< f877c388fea0e794f663d62e3508c5d11832601e desc=$(printf %s\\n "${kak_opt_clang_errors}" | sed -ne "/^${kak_cursor_line},.*/ { s/^[[:digit:]]\+,//g; s/'/\\\\'/g; p }")
desc=$(printf %s "${kak_opt_clang_errors}" | sed -ne "/^${kak_cursor_line},.*/ { s/^[[:digit:]]\+,//g; s/'/\\\\'/g; p }")
if [ -n "$desc" ]; then if [ -n "$desc" ]; then
echo "info -anchor ${kak_cursor_line}.${kak_cursor_column} '${desc}'" printf %s\\n "info -anchor ${kak_cursor_line}.${kak_cursor_column} '${desc}'"
=======
printf %s "${kak_opt_clang_errors}" | grep "^${kak_cursor_line},.*" | if read line; then
desc=$(printf %s "${line}" | sed -e "s/^[[:digit:]]\+,//g; s/'/\\\\'/g")
printf %s "info -anchor ${kak_cursor_line}.${kak_cursor_column} '${desc}'"
>>>>>>> Replace non POSIX calls to `echo` with `printf %s`
fi fi
} } } }
@ -169,9 +158,9 @@ def clang-diagnostics-next -docstring "Jump to the next line that contains an er
done done
line=$((line == -1 ? first_line : line)) line=$((line == -1 ? first_line : line))
if [ ${line} -ne -1 ]; then if [ ${line} -ne -1 ]; then
printf %s "exec ${line} g" printf %s\\n "exec ${line} g"
else else
printf %s 'echo -color Error no next clang diagnostic' echo 'echo -color Error no next clang diagnostic'
fi fi
) )
} } } }

View File

@ -1,16 +1,16 @@
def editorconfig-load -docstring "Set indentation options according to editorconfig file" %{ def editorconfig-load -docstring "Set indentation options according to editorconfig file" %{
%sh{ %sh{
command -v editorconfig >/dev/null 2>&1 || { printf %s "echo -color Error The editorconfig tool could not be found"; exit 1; } command -v editorconfig >/dev/null 2>&1 || { echo 'echo -color Error The editorconfig tool could not be found'; exit 1; }
editorconfig $kak_buffile | awk -F= -- \ editorconfig $kak_buffile | awk -F= -- \
'{ '{
if ($1 == "indent_style" && $2 == "tab") { if ($1 == "indent_style" && $2 == "tab") {
print "set buffer indentwidth 0" print "set buffer indentwidth 0"
} }
else if ($1 == "indent_size" && $2 ~ "[0-9]+") { else if ($1 == "indent_size" && $2 ~ "[0-9]+") {
print "set buffer indentwidth", $2 print "set buffer indentwidth", $2
} }
else if ($1 == "tab_width" && $2 ~ "[0-9]+") { else if ($1 == "tab_width" && $2 ~ "[0-9]+") {
print "set buffer tabstop", $2 print "set buffer tabstop", $2
} }
else if ($1 == "end_of_line") { else if ($1 == "end_of_line") {
if ($2 == "lf" || $2 == "crlf") { if ($2 == "lf" || $2 == "crlf") {

View File

@ -44,7 +44,7 @@ def flake8-lint -params 0..1 -docstring "Lint the contents of the current buffer
} }
def -hidden flake8-show-error-info %{ %sh{ def -hidden flake8-show-error-info %{ %sh{
desc=$(printf %s "${kak_opt_flake8_errors}" | sed -ne "/^${kak_cursor_line},.*/ { s/^[[:digit:]]\+,//g; s/'/\\\\'/g; p }") desc=$(printf %s\\n "${kak_opt_flake8_errors}" | sed -ne "/^${kak_cursor_line},.*/ { s/^[[:digit:]]\+,//g; s/'/\\\\'/g; p }")
if [ -n "$desc" ]; then if [ -n "$desc" ]; then
echo "info -anchor ${kak_cursor_line}.${kak_cursor_column} '${desc}'" echo "info -anchor ${kak_cursor_line}.${kak_cursor_column} '${desc}'"
fi fi

View File

@ -26,10 +26,10 @@ decl line-flags git_diff_flags
face GitBlame default,magenta face GitBlame default,magenta
def -params 1.. \ def -params 1.. \
-docstring %sh{printf "%%{Git wrapping helper\navailable commands:\n add\n rm\n blame\n commit\n checkout\n diff\n hide-blame\n log\n show\n show-diff\n status\n update-diff}"} \ -docstring %sh{printf '%%{Git wrapping helper\navailable commands:\n add\n rm\n blame\n commit\n checkout\n diff\n hide-blame\n log\n show\n show-diff\n status\n update-diff}'} \
-shell-completion %{ -shell-completion %{
shift $(expr ${kak_token_to_complete}) shift $(expr ${kak_token_to_complete})
prefix=$(printf %s "${1}" | cut -c1-${kak_pos_in_token} 2>/dev/null) prefix=$(printf %s\\n "${1}" | cut -c1-${kak_pos_in_token} 2>/dev/null)
( (
for cmd in add rm blame commit checkout diff hide-blame log show show-diff status update-diff; do for cmd in add rm blame commit checkout diff hide-blame log show show-diff status update-diff; do
expr "${cmd}" : "^\(${prefix}.*\)$" expr "${cmd}" : "^\(${prefix}.*\)$"
@ -48,7 +48,7 @@ def -params 1.. \
mkfifo ${output} mkfifo ${output}
( git "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null & ( git "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null &
printf %s "eval -try-client '$kak_opt_docsclient' %{ printf %s\\n "eval -try-client '$kak_opt_docsclient' %{
edit! -fifo ${output} *git* edit! -fifo ${output} *git*
set buffer filetype '${filetype}' set buffer filetype '${filetype}'
hook -group fifo buffer BufCloseFifo .* %{ hook -group fifo buffer BufCloseFifo .* %{
@ -60,7 +60,7 @@ def -params 1.. \
run_git_blame() { run_git_blame() {
( (
printf %s "eval -client '$kak_client' %{ printf %s\\n "eval -client '$kak_client' %{
try %{ addhl flag_lines GitBlame git_blame_flags } try %{ addhl flag_lines GitBlame git_blame_flags }
set buffer=$kak_bufname git_blame_flags '$kak_timestamp' set buffer=$kak_bufname git_blame_flags '$kak_timestamp'
}" | kak -p ${kak_session} }" | kak -p ${kak_session}
@ -120,9 +120,9 @@ def -params 1.. \
# Handle case where message needs not to be edited # Handle case where message needs not to be edited
if grep -E -q -e "-m|-F|-C|--message=.*|--file=.*|--reuse-message=.*|--no-edit"; then if grep -E -q -e "-m|-F|-C|--message=.*|--file=.*|--reuse-message=.*|--no-edit"; then
if git commit "$@" > /dev/null 2>&1; then if git commit "$@" > /dev/null 2>&1; then
printf %s 'echo -color Information Commit succeeded' echo 'echo -color Information Commit succeeded'
else else
printf %s 'echo -color Error Commit failed' echo 'echo -color Error Commit failed'
fi fi
exit exit
fi <<-EOF fi <<-EOF
@ -132,13 +132,13 @@ def -params 1.. \
# fails, and generate COMMIT_EDITMSG # fails, and generate COMMIT_EDITMSG
GIT_EDITOR='' EDITOR='' git commit > /dev/null 2>&1 GIT_EDITOR='' EDITOR='' git commit > /dev/null 2>&1
msgfile="$(git rev-parse --git-dir)/COMMIT_EDITMSG" msgfile="$(git rev-parse --git-dir)/COMMIT_EDITMSG"
printf %s "edit '$msgfile' printf %s\\n "edit '$msgfile'
hook buffer BufWritePost '.*\Q$msgfile\E' %{ %sh{ hook buffer BufWritePost '.*\Q$msgfile\E' %{ %sh{
if git commit -F '$msgfile' --cleanup=strip $@ > /dev/null; then if git commit -F '$msgfile' --cleanup=strip $@ > /dev/null; then
printf %s 'eval -client $kak_client echo -color Information Commit succeeded' printf %s\\n 'eval -client $kak_client echo -color Information Commit succeeded'
printf %s 'delbuf' printf %s\\n 'delbuf'
else else
printf %s 'eval -client $kak_client echo -color Error Commit failed' printf %s\\n 'eval -client $kak_client echo -color Error Commit failed'
fi fi
} }" } }"
} }
@ -147,13 +147,13 @@ def -params 1.. \
show|log|diff|status) show_git_cmd_output "$@" ;; show|log|diff|status) show_git_cmd_output "$@" ;;
blame) shift; run_git_blame "$@" ;; blame) shift; run_git_blame "$@" ;;
hide-blame) hide-blame)
printf %s "try %{ printf %s\\n "try %{
set buffer=$kak_bufname git_blame_flags '' set buffer=$kak_bufname git_blame_flags ''
rmhl hlflags_git_blame_flags rmhl hlflags_git_blame_flags
}" }"
;; ;;
show-diff) show-diff)
printf %s "try %{ addhl flag_lines default,black git_diff_flags }" echo 'try %{ addhl flag_lines default,black git_diff_flags }'
update_diff update_diff
;; ;;
update-diff) update_diff ;; update-diff) update_diff ;;
@ -165,19 +165,19 @@ def -params 1.. \
add) add)
name="${2:-${kak_buffile}}" name="${2:-${kak_buffile}}"
if git add -- "${name}" > /dev/null 2>&1; then if git add -- "${name}" > /dev/null 2>&1; then
printf %s "echo -color Information 'git: added ${name}'" printf %s\\n "echo -color Information 'git: added ${name}'"
else else
printf %s "echo -color Error 'git: unable to add ${name}'" printf %s\\n "echo -color Error 'git: unable to add ${name}'"
fi fi
;; ;;
rm) rm)
name="${2:-${kak_buffile}}" name="${2:-${kak_buffile}}"
if git rm -- "${name}" > /dev/null 2>&1; then if git rm -- "${name}" > /dev/null 2>&1; then
printf %s "echo -color Information 'git: removed ${name}'" printf %s\\n "echo -color Information 'git: removed ${name}'"
else else
printf %s "echo -color Error 'git: unable to remove ${name}'" printf %s\\n "echo -color Error 'git: unable to remove ${name}'"
fi fi
;; ;;
*) printf %s "echo -color Error %{unknown git command '$1'}"; exit ;; *) printf %s\\n "echo -color Error %{unknown git command '$1'}"; exit ;;
esac esac
}} }}

View File

@ -6,12 +6,12 @@ def jedi-complete -docstring "Complete the current selection with jedi" %{
%sh{ %sh{
dir=$(mktemp -d -t kak-jedi.XXXXXXXX) dir=$(mktemp -d -t kak-jedi.XXXXXXXX)
mkfifo ${dir}/fifo mkfifo ${dir}/fifo
printf %s "set buffer jedi_tmp_dir ${dir}" printf %s\\n "set buffer jedi_tmp_dir ${dir}"
printf %s "write ${dir}/buf" printf %s\\n "write ${dir}/buf"
} }
%sh{ %sh{
dir=${kak_opt_jedi_tmp_dir} dir=${kak_opt_jedi_tmp_dir}
printf %s "eval -draft %{ edit! -fifo ${dir}/fifo *jedi-output* }" printf %s\\n "eval -draft %{ edit! -fifo ${dir}/fifo *jedi-output* }"
( (
cd $(dirname ${kak_buffile}) cd $(dirname ${kak_buffile})
header="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}" header="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}"
@ -23,8 +23,8 @@ def jedi-complete -docstring "Complete the current selection with jedi" %{
print ':'.join([(str(c.name).replace("|", "\\|") + "|" + str(c.docstring()).replace("|", "\\|")).replace(":", "\\:") + "|" + str(c.name).replace("|", "\\|") for c in script.completions()]).replace("'", r"\\\\'") print ':'.join([(str(c.name).replace("|", "\\|") + "|" + str(c.docstring()).replace("|", "\\|")).replace(":", "\\:") + "|" + str(c.name).replace("|", "\\|") for c in script.completions()]).replace("'", r"\\\\'")
END END
) )
printf %s "${compl}" > /tmp/kak-jedi-out printf %s\\n "${compl}" > /tmp/kak-jedi-out
printf %s "eval -client ${kak_client} 'echo completed; set %{buffer=${kak_buffile}} jedi_completions \'${header}:${compl}\''" | kak -p ${kak_session} printf %s\\n "eval -client ${kak_client} 'echo completed; set %{buffer=${kak_buffile}} jedi_completions \'${header}:${compl}\''" | kak -p ${kak_session}
rm -r ${dir} rm -r ${dir}
) > /dev/null 2>&1 < /dev/null & ) > /dev/null 2>&1 < /dev/null &
} }
@ -41,7 +41,7 @@ def jedi-enable-autocomplete -docstring "Add jedi completion candidates to the c
} }
def jedi-disable-autocomplete -docstring "Disable jedi completion" %{ def jedi-disable-autocomplete -docstring "Disable jedi completion" %{
set window completers %sh{ printf %s "'${kak_opt_completers}'" | sed -e 's/option=jedi_completions://g' } set window completers %sh{ printf %s\\n "'${kak_opt_completers}'" | sed -e 's/option=jedi_completions://g' }
rmhooks window jedi-autocomplete rmhooks window jedi-autocomplete
unalias window complete jedi-complete unalias window complete jedi-complete
} }

View File

@ -35,17 +35,17 @@ def -hidden _modeline-parse %{
case "${value}" in case "${value}" in
unix) tr="eolformat lf";; unix) tr="eolformat lf";;
dos) tr="eolformat crlf";; dos) tr="eolformat crlf";;
*) printf %s "Unsupported file format: ${value}" >&2;; *) printf %s\\n "echo -debug 'Unsupported file format: ${value}'";;
esac esac
;; ;;
ft) ;& ft) ;&
filetype) tr="filetype ${value}";; filetype) tr="filetype ${value}";;
bomb) tr="BOM utf8";; bomb) tr="BOM utf8";;
nobomb) tr="BOM none";; nobomb) tr="BOM none";;
*) printf %s "Unsupported vim variable: ${key}" >&2;; *) printf %s\\n "echo -debug 'Unsupported vim variable: ${key}'";;
esac esac
[ -n "${tr}" ] && printf %s "set buffer ${tr}" [ -n "${tr}" ] && printf %s\\n "set buffer ${tr}"
} }
# Pass a few whitelisted options to kakoune directly # Pass a few whitelisted options to kakoune directly
@ -63,12 +63,12 @@ def -hidden _modeline-parse %{
BOM BOM
) )
printf %s "${OPTS_ALLOWED[@]}" | grep -qw "${key}" || { printf %s\\n "${OPTS_ALLOWED[@]}" | grep -qw "${key}" || {
printf %s "Unsupported kakoune variable: ${key}" >&2; printf %s\\n "echo -debug 'Unsupported kakoune variable: ${key}'";
return; return;
} }
printf %s "set buffer ${key} ${value}" printf %s\\n "set buffer ${key} ${value}"
} }
# The following subshell will keep the actual options of the modeline, and strip: # The following subshell will keep the actual options of the modeline, and strip:
@ -77,7 +77,7 @@ def -hidden _modeline-parse %{
# It will also convert the ':' seperators beween the option=value pairs # It will also convert the ':' seperators beween the option=value pairs
# More info: http://vimdoc.sourceforge.net/htmldoc/options.html#modeline # More info: http://vimdoc.sourceforge.net/htmldoc/options.html#modeline
options=( options=(
$(printf %s "${kak_selection}" | sed -r \ $(printf %s\\n "${kak_selection}" | sed -r \
-e 's/^(.+\s\w+:\s?(set?)?\s)//' \ -e 's/^(.+\s\w+:\s?(set?)?\s)//' \
-e 's/:?\s[^a-zA-Z0-9_=-]+$//' \ -e 's/:?\s[^a-zA-Z0-9_=-]+$//' \
-e 's/:/ /g') -e 's/:/ /g')
@ -88,7 +88,7 @@ def -hidden _modeline-parse %{
*vim:*) type_selection="vim";; *vim:*) type_selection="vim";;
*kak:*) ;& *kak:*) ;&
*kakoune:*) type_selection="kakoune";; *kakoune:*) type_selection="kakoune";;
*) printf %s "echo -debug Unsupported modeline format";; *) echo "echo -debug Unsupported modeline format";;
esac esac
[ -n "${type_selection}" ] || exit 1 [ -n "${type_selection}" ] || exit 1
@ -101,7 +101,7 @@ def -hidden _modeline-parse %{
kakoune) tr=$(translate_opt_kakoune "${name_option}" "${value_option}");; kakoune) tr=$(translate_opt_kakoune "${name_option}" "${value_option}");;
esac esac
[ -n "${tr}" ] && printf %s "${tr}" [ -n "${tr}" ] && printf %s\\n "${tr}"
done done
} }
} }

View File

@ -39,12 +39,12 @@ addhl -group /moon/code regex \b(and|break|catch|class|continue|do|else(if)?|exp
def moon-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ %sh{ def moon-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ %sh{
case $kak_buffile in case $kak_buffile in
*spec/*_spec.moon) *spec/*_spec.moon)
altfile=$(eval printf %s $(printf %s $kak_buffile | sed s+spec/+'*'/+';'s/_spec//)) altfile=$(eval printf %s\\n $(printf %s\\n $kak_buffile | sed s+spec/+'*'/+';'s/_spec//))
[ ! -f $altfile ] && printf %s "echo -color Error 'implementation file not found'" && exit [ ! -f $altfile ] && echo "echo -color Error 'implementation file not found'" && exit
;; ;;
*.moon) *.moon)
path=$kak_buffile path=$kak_buffile
dirs=$(while [ $path ]; do printf %s $path; path=${path%/*}; done | tail -n +2) dirs=$(while [ $path ]; do printf %s\\n $path; path=${path%/*}; done | tail -n +2)
for dir in $dirs; do for dir in $dirs; do
altdir=$dir/spec altdir=$dir/spec
if [ -d $altdir ]; then if [ -d $altdir ]; then
@ -52,13 +52,13 @@ def moon-alternative-file -docstring 'Jump to the alternate file (implementation
break break
fi fi
done done
[ ! -d $altdir ] && printf %s "echo -color Error 'spec/ not found'" && exit [ ! -d $altdir ] && echo "echo -color Error 'spec/ not found'" && exit
;; ;;
*) *)
printf %s "echo -color Error 'alternative file not found'" && exit echo "echo -color Error 'alternative file not found'" && exit
;; ;;
esac esac
printf %s "edit $altfile" printf %s\\n "edit $altfile"
}} }}
def -hidden _moon_filter_around_selections %{ def -hidden _moon_filter_around_selections %{

View File

@ -4,8 +4,10 @@
hook global KakBegin .* %{ hook global KakBegin .* %{
%sh{ %sh{
if [ -n "$TMUX" ]; then if [ -n "$TMUX" ]; then
printf %s "alias global repl tmux-repl-horizontal" echo "
printf %s "alias global send-text tmux-send-text" alias global repl tmux-repl-horizontal
alias global send-text tmux-send-text
"
fi fi
} }
} }
@ -13,7 +15,7 @@ hook global KakBegin .* %{
def -hidden -params 1..2 tmux-repl-impl %{ def -hidden -params 1..2 tmux-repl-impl %{
%sh{ %sh{
if [ -z "$TMUX" ]; then if [ -z "$TMUX" ]; then
printf %s "echo -color Error This command is only available in a tmux session" echo "echo -color Error This command is only available in a tmux session"
exit exit
fi fi
tmux_args="$1" tmux_args="$1"

View File

@ -4,7 +4,7 @@ def -docstring 'create a new window for repl interaction' \
-command-completion \ -command-completion \
x11-repl %{ %sh{ x11-repl %{ %sh{
if [ -z "${kak_opt_termcmd}" ]; then if [ -z "${kak_opt_termcmd}" ]; then
printf %s "echo -color Error 'termcmd option is not set'" echo "echo -color Error 'termcmd option is not set'"
exit exit
fi fi
if [ $# -eq 0 ]; then cmd="bash"; else cmd="$1"; fi if [ $# -eq 0 ]; then cmd="bash"; else cmd="$1"; fi
@ -13,7 +13,7 @@ def -docstring 'create a new window for repl interaction' \
def x11-send-text -docstring "send selected text to the repl window" %{ def x11-send-text -docstring "send selected text to the repl window" %{
nop %sh{ nop %sh{
printf %s "${kak_selection}" | xsel -i printf %s\\n "${kak_selection}" | xsel -i
wid=$(xdotool getactivewindow) wid=$(xdotool getactivewindow)
xdotool search --name kak_repl_window windowactivate xdotool search --name kak_repl_window windowactivate
xdotool key --clearmodifiers "Shift+Insert" xdotool key --clearmodifiers "Shift+Insert"