summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank LENORMAND <lenormf@gmail.com>2020-09-18 14:47:21 +0300
committerFrank LENORMAND <lenormf@gmail.com>2020-09-18 15:12:13 +0300
commit2a51ebf10515f6511c8b4af2de03bb96551d75c2 (patch)
tree20d1930a5292db475ad4ae299c6a27cb15209e04
parent2d78b0760d2d755321dbc3321cb2e47d5d08c90f (diff)
rc modeline: Factorise the use of `kakquote`
-rw-r--r--rc/detection/modeline.kak55
1 files changed, 34 insertions, 21 deletions
diff --git a/rc/detection/modeline.kak b/rc/detection/modeline.kak
index dc092a1c..39f35966 100644
--- a/rc/detection/modeline.kak
+++ b/rc/detection/modeline.kak
@@ -16,35 +16,48 @@ define-command -hidden modeline-parse-impl %{
# Translate a vim option into the corresponding kakoune one
translate_opt_vim() {
- readonly key="$1"
- readonly value="$2"
+ key="$1"
+ value="$2"
tr=""
case "${key}" in
- so|scrolloff) tr=$(kakquote scrolloff "${value},${kak_opt_scrolloff##*,}");;
- siso|sidescrolloff) tr=$(kakquote scrolloff "${kak_opt_scrolloff%%,*},${value}");;
- ts|tabstop) tr=$(kakquote tabstop "${value}");;
- sw|shiftwidth) tr=$(kakquote indentwidth "${value}");;
- tw|textwidth) tr=$(kakquote autowrap_column "${value}");;
+ so|scrolloff)
+ key="scrolloff";
+ value="${value},${kak_opt_scrolloff##*,}";;
+ siso|sidescrolloff)
+ key="scrolloff";
+ value="${kak_opt_scrolloff%%,*},${value}";;
+ ts|tabstop) key="tabstop";;
+ sw|shiftwidth) key="indentwidth";;
+ tw|textwidth) key="autowrap_column";;
ff|fileformat)
+ key="eolformat";
case "${value}" in
- unix) tr="eolformat lf";;
- dos) tr="eolformat crlf";;
- *) printf 'echo -debug %s' "$(kakquote "Unsupported file format: ${value}")" \
- | kak -p "${kak_session}";;
+ unix) value="lf";;
+ dos) value="crlf";;
+ *)
+ printf 'echo -debug %s' "$(kakquote "Unsupported file format: ${value}")" \
+ | kak -p "${kak_session}";
+ return;;
esac
;;
- ft|filetype) tr=$(kakquote filetype "{value}");;
- bomb) tr="BOM utf8";;
- nobomb) tr="BOM none";;
- spelllang|spl) tr=$(kakquote spell_lang "{value%%,*}");;
- *) printf 'echo -debug %s' "$(kakquote "Unsupported vim variable: ${key}")" \
- | kak -p "${kak_session}";;
+ ft|filetype) key="filetype";;
+ bomb)
+ key="BOM";
+ value="utf8";;
+ nobomb)
+ 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
- if [ -n "${tr}" ]; then
- printf 'set-option buffer %s\n' "${tr}"
- fi
+ printf 'set-option buffer %s %s\n' "${key}" "$(kakquote "${value}")"
}
# Pass a few whitelisted options to kakoune directly
@@ -59,7 +72,7 @@ define-command -hidden modeline-parse-impl %{
return;;
esac
- printf 'set-option buffer %s' "$(kakquote "${key}" "${value}")"
+ printf 'set-option buffer %s %s\n' "${key}" "$(kakquote "${value}")"
}
case "${kak_selection}" in