From cc6fe5ae6138f901cf5de315a166584770b45e58 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 9 Feb 2022 16:13:29 +0100 Subject: [PATCH 1/8] 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/8] 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 '/*' From d6392e37c9500838beef6beea178cc0d70bd03c2 Mon Sep 17 00:00:00 2001 From: Luis Alfonso Buelvas Betancourt <38670883+eko234@users.noreply.github.com> Date: Tue, 22 Feb 2022 17:13:38 -0500 Subject: [PATCH 3/8] fennel filetype now highlights accumulate keyword --- rc/filetype/fennel.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc/filetype/fennel.kak b/rc/filetype/fennel.kak index e6d604fe..91368cc5 100644 --- a/rc/filetype/fennel.kak +++ b/rc/filetype/fennel.kak @@ -39,7 +39,7 @@ evaluate-commands %sh{ # Grammar keywords="require-macros eval-compiler doc lua hashfn macro macros import-macros pick-args pick-values macroexpand macrodebug do values if when each for fn lambda λ partial while set global var local let tset set-forcibly! doto match or and - not not= collect icollect rshift lshift bor band bnot bxor with-open" + not not= collect icollect accumulate rshift lshift bor band bnot bxor with-open" re_keywords='\\$ \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9 \\$\\.\\.\\.' builtins="_G _VERSION arg assert bit32 collectgarbage coroutine debug dofile error getfenv getmetatable io ipairs length load From f709ba63907bb6aa7bf256c1d1fce83e17d5f0ff Mon Sep 17 00:00:00 2001 From: tomKPZ Date: Tue, 8 Mar 2022 08:51:11 -0800 Subject: [PATCH 5/8] Fix buffer overflow in parse_quoted This fixes a crash when using kak-lsp with bash-language-server. The issue is that the second read() in parse_quoted may read past the end of the string. If this happens and the condition on line 126 is false, then the loop on line 119 will continue to read past the end of the buffer since it checks for state.pos != end instead of state.pos < end, which will likely result in a crash. The fix is to add a check for the buffer end before the second read. The added test fails without the change and passes with the change. --- src/command_manager.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/command_manager.cc b/src/command_manager.cc index 0f3cb749..b8784093 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -132,7 +132,7 @@ ParseResult parse_quoted(ParseState& state, Delimiter delimiter) if (c == delimiter) { auto next = state.pos; - if (read(next, end) != delimiter) + if (next == end || read(next, end) != delimiter) { if (str.empty()) return {String{String::NoCopy{}, {beg, cur}}, true}; @@ -815,15 +815,20 @@ UnitTest test_command_parsing{[] { auto check_quoted = [](StringView str, bool terminated, StringView content) { - ParseState state{str, str.begin()}; - const Codepoint delimiter = *state.pos++; - auto quoted = parse_quoted(state, delimiter); - kak_assert(quoted.terminated == terminated); - kak_assert(quoted.content == content); + auto check_quoted_impl = [&](auto type_hint) { + ParseState state{str, str.begin()}; + const decltype(type_hint) delimiter = *state.pos++; + auto quoted = parse_quoted(state, delimiter); + kak_assert(quoted.terminated == terminated); + kak_assert(quoted.content == content); + }; + check_quoted_impl(Codepoint{}); + check_quoted_impl(char{}); }; check_quoted("'abc'", true, "abc"); check_quoted("'abc''def", false, "abc'def"); check_quoted("'abc''def'''", true, "abc'def'"); + check_quoted(StringView("'abc''def'", 5), true, "abc"); auto check_balanced = [](StringView str, bool terminated, StringView content) { From 2f1cb1119454a814058d2f54b3bba8b145b9e0c1 Mon Sep 17 00:00:00 2001 From: Charles Gueunet Date: Thu, 17 Mar 2022 14:13:40 +0100 Subject: [PATCH 6/8] CMake: fix comment highlight --- rc/filetype/cmake.kak | 1 + 1 file changed, 1 insertion(+) diff --git a/rc/filetype/cmake.kak b/rc/filetype/cmake.kak index cb5c65db..86fda25d 100644 --- a/rc/filetype/cmake.kak +++ b/rc/filetype/cmake.kak @@ -25,6 +25,7 @@ add-highlighter shared/cmake/argument region -recurse '\(' '\w+\h*\(\K' '(?=\))' add-highlighter shared/cmake/code/ regex '\w+\h*(?=\()' 0:meta add-highlighter shared/cmake/argument/args default-region regex '\$\{\w+\}' 0:variable +add-highlighter shared/cmake/argument/comment region '#' '$' fill comment add-highlighter shared/cmake/argument/quoted region '"' '(? Date: Sun, 20 Mar 2022 16:15:16 +0100 Subject: [PATCH 8/8] Improved installation instructions for Ubuntu Added information on how to install from the repositories. Improved the instructions for how to build from source, for those that don't want an ancient version of Kakoune. On Ubuntu 20.04 and earlier, GCC 10 is not the default so we have to explicitly tell `make` to use GCC 10. See also: https://github.com/mawww/kakoune/issues/4571 --- README.asciidoc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index 9c94cc89..94ea4538 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -205,12 +205,17 @@ sudo zypper install kakoune [TIP] .Ubuntu ==== -Building on Ubuntu 16.04 and 18.04. -Make sure you have .local/bin in your path to make the kak binary available from your shell. +Kakoune can be found in the Ubuntu repositories. + +---------------------------- +sudo apt install kakoune +---------------------------- + +If you want to compile from source on 20.04 or earlier, you must force the build to use GCC 10, which is not the default. Also, make sure you have .local/bin in your path so that kak is available after the installation. ---------------------------------------------------------------- git clone https://github.com/mawww/kakoune.git && cd kakoune/src -make +CXX=g++-10 make PREFIX=$HOME/.local make install ---------------------------------------------------------------- ====