rc modeline: Factorise the use of kakquote

This commit is contained in:
Frank LENORMAND 2020-09-18 14:47:21 +03:00
parent 2d78b0760d
commit 2a51ebf105

View File

@ -16,35 +16,48 @@ define-command -hidden modeline-parse-impl %{
# Translate a vim option into the corresponding kakoune one # Translate a vim option into the corresponding kakoune one
translate_opt_vim() { translate_opt_vim() {
readonly key="$1" key="$1"
readonly value="$2" value="$2"
tr="" tr=""
case "${key}" in case "${key}" in
so|scrolloff) tr=$(kakquote scrolloff "${value},${kak_opt_scrolloff##*,}");; so|scrolloff)
siso|sidescrolloff) tr=$(kakquote scrolloff "${kak_opt_scrolloff%%,*},${value}");; key="scrolloff";
ts|tabstop) tr=$(kakquote tabstop "${value}");; value="${value},${kak_opt_scrolloff##*,}";;
sw|shiftwidth) tr=$(kakquote indentwidth "${value}");; siso|sidescrolloff)
tw|textwidth) tr=$(kakquote autowrap_column "${value}");; key="scrolloff";
value="${kak_opt_scrolloff%%,*},${value}";;
ts|tabstop) key="tabstop";;
sw|shiftwidth) key="indentwidth";;
tw|textwidth) key="autowrap_column";;
ff|fileformat) ff|fileformat)
key="eolformat";
case "${value}" in case "${value}" in
unix) tr="eolformat lf";; unix) value="lf";;
dos) tr="eolformat crlf";; dos) value="crlf";;
*) printf 'echo -debug %s' "$(kakquote "Unsupported file format: ${value}")" \ *)
| kak -p "${kak_session}";; printf 'echo -debug %s' "$(kakquote "Unsupported file format: ${value}")" \
| kak -p "${kak_session}";
return;;
esac esac
;; ;;
ft|filetype) tr=$(kakquote filetype "{value}");; ft|filetype) key="filetype";;
bomb) tr="BOM utf8";; bomb)
nobomb) tr="BOM none";; key="BOM";
spelllang|spl) tr=$(kakquote spell_lang "{value%%,*}");; value="utf8";;
*) printf 'echo -debug %s' "$(kakquote "Unsupported vim variable: ${key}")" \ nobomb)
| kak -p "${kak_session}";; key="BOM";
value="none";;
spelllang|spl)
key="spell_lang";
value="${value%%,*}";;
*)
printf 'echo -debug %s' "$(kakquote "Unsupported vim variable: ${key}")" \
| kak -p "${kak_session}";
return;;
esac esac
if [ -n "${tr}" ]; then printf 'set-option buffer %s %s\n' "${key}" "$(kakquote "${value}")"
printf 'set-option buffer %s\n' "${tr}"
fi
} }
# Pass a few whitelisted options to kakoune directly # Pass a few whitelisted options to kakoune directly
@ -59,7 +72,7 @@ define-command -hidden modeline-parse-impl %{
return;; return;;
esac esac
printf 'set-option buffer %s' "$(kakquote "${key}" "${value}")" printf 'set-option buffer %s %s\n' "${key}" "$(kakquote "${value}")"
} }
case "${kak_selection}" in case "${kak_selection}" in