From cc6fe5ae6138f901cf5de315a166584770b45e58 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 9 Feb 2022 16:13:29 +0100 Subject: [PATCH 1/2] Add conf filetype, for generic Unix configuration files We set the "ini" filetype for files ending in one of "repo", "ini", "cfg", "properties" or "desktop". Most of these actually use Unix style comments (#) instead of DOS INI comments (;). Introduce filetype "conf" which is similar to "ini" except it uses the default # as comment_line string. Both Vim and Emacs have a filetype (or Major mode) named "conf" (hence modeline-parse of "vim ft=conf" will work). Here are references that show that the new "conf" files use #-comments: *.repo -- search for # in https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/sec-configuring_yum_and_yum_repositories *.cfg: don't know much about this one, but at least the motivating file uses # https://github.com/buildout/buildout/blob/master/buildout.cfg *.properties files: https://en.wikipedia.org/wiki/.properties *.desktop: per spec https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s03.html#comments --- rc/filetype/conf.kak | 23 +++++++++++++++++++++++ rc/filetype/ini.kak | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 rc/filetype/conf.kak diff --git a/rc/filetype/conf.kak b/rc/filetype/conf.kak new file mode 100644 index 00000000..8288a0ba --- /dev/null +++ b/rc/filetype/conf.kak @@ -0,0 +1,23 @@ +hook global BufCreate .+\.(repo|cfg|properties|desktop) %{ + set-option buffer filetype conf +} + +hook global WinSetOption filetype=conf %{ + require-module conf +} + +hook -group conf-highlight global WinSetOption filetype=conf %{ + add-highlighter window/conf ref conf + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/conf } +} + +provide-module conf %{ + +add-highlighter shared/conf regions +add-highlighter shared/conf/code default-region group +add-highlighter shared/conf/comment region '(^|\h)\K#' $ fill comment + +add-highlighter shared/conf/code/ regex "(?S)^\h*(\[.+?\])\h*$" 1:title +add-highlighter shared/conf/code/ regex "^\h*([^\[][^=\n]*)=([^\n]*)" 1:variable 2:value + +} diff --git a/rc/filetype/ini.kak b/rc/filetype/ini.kak index 1e922fdd..75762f6a 100644 --- a/rc/filetype/ini.kak +++ b/rc/filetype/ini.kak @@ -1,4 +1,4 @@ -hook global BufCreate .+\.(repo|ini|cfg|properties|desktop) %{ +hook global BufCreate .+\.ini %{ set-option buffer filetype ini } From 3a856ef57b433e6c0f11247d2b2193cf782eb3be Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 9 Feb 2022 16:13:29 +0100 Subject: [PATCH 2/2] rc conf: treat ini files as conf if they contain a #-comment *.ini files traditionally use ; but for example the "foot" terminal's foot.ini uses #. Add a hack to treat ini files as "conf" filetype if they contain a #-comment (very slim chance of false positives). This requires to explicitly set comment_line to the default #, because we set the "ini" filetype earlier. --- rc/filetype/conf.kak | 7 +++++++ rc/tools/comment.kak | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/rc/filetype/conf.kak b/rc/filetype/conf.kak index 8288a0ba..9b715893 100644 --- a/rc/filetype/conf.kak +++ b/rc/filetype/conf.kak @@ -2,6 +2,13 @@ hook global BufCreate .+\.(repo|cfg|properties|desktop) %{ set-option buffer filetype conf } +hook global WinCreate .+\.ini %{ + try %{ + execute-keys /^\h*# + set-option buffer filetype conf + } +} + hook global WinSetOption filetype=conf %{ require-module conf } diff --git a/rc/tools/comment.kak b/rc/tools/comment.kak index 8d3ee798..1094fbba 100644 --- a/rc/tools/comment.kak +++ b/rc/tools/comment.kak @@ -45,6 +45,10 @@ hook global BufSetOption filetype=coffee %{ set-option buffer comment_block_end '###' } +hook global BufSetOption filetype=conf %{ + set-option buffer comment_line '#' +} + hook global BufSetOption filetype=css %{ set-option buffer comment_line '' set-option buffer comment_block_begin '/*'