Skip to content

Commit

Permalink
modeline.kak: Replace sed with kak -quote
Browse files Browse the repository at this point in the history
  • Loading branch information
pjungkamp committed Aug 5, 2024
1 parent f957094 commit 714d3fd
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions rc/detection/modeline.kak
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ declare-option -docstring "amount of lines that will be checked at the beginning

define-command -hidden modeline-parse-impl %{
evaluate-commands %sh{
kakquote() { printf "%s" "$*" | sed "s/'/''/g; 1s/^/'/; \$s/\$/'/"; }
# Translate a vim option into the corresponding kakoune one
translate_opt_vim() {
local key="$1"
Expand Down Expand Up @@ -54,7 +52,7 @@ define-command -hidden modeline-parse-impl %{
return;;
esac
printf 'set-option buffer %s %s\n' "${key}" "$(kakquote "${value}")"
printf 'set-option buffer %s %s\n' "${key}" "$(kak -quote kakoune -- "${value}")"
}
# Pass a few whitelisted options to kakoune directly
Expand All @@ -64,19 +62,19 @@ define-command -hidden modeline-parse-impl %{
case "${key}" in
scrolloff|tabstop|indentwidth|autowrap_column|eolformat|filetype|BOM|spell_lang);;
*) printf 'echo -debug %s' "$(kakquote "Unsupported kakoune variable: ${key}")" \
*) printf 'echo -debug %s' "$(kak -quote kakoune -- "Unsupported kakoune variable: ${key}")" \
| kak -p "${kak_session}"
return;;
esac
printf 'set-option buffer %s %s\n' "${key}" "$(kakquote "${value}")"
printf 'set-option buffer %s %s\n' "${key}" "$(kak -quote kakoune -- "${value}")"
}
case "${kak_selection}" in
*vi:*|*vim:*) type_selection="vim";;
*kak:*|*kakoune:*) type_selection="kakoune";;
*)
printf 'fail %s\n' "$(kakquote "Unsupported modeline format: ${kak_selection}")"
printf 'fail %s\n' "$(kak -quote kakoune -- "Unsupported modeline format: ${kak_selection}")"
exit 1 ;;
esac
Expand Down

0 comments on commit 714d3fd

Please sign in to comment.