From 67a8e8ca3c342e49a4f43353a55c11caf81e0848 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Fri, 14 Oct 2016 19:16:45 +0300 Subject: [PATCH 1/5] Remove all references to `formatcmd` Initializing the `formatcmd` variable in the default language support scripts created a dependency to the `formatter.kak` script, which we do not want. Examples of such cases are when users haven't loaded the `formatter.kak` script, or when Kakoune runs its test suite and selectively loads some language scripts for testing purposes. --- rc/base/d.kak | 1 - rc/base/go.kak | 2 -- rc/base/perl.kak | 1 - rc/base/ruby.kak | 5 ----- rc/core/c-family.kak | 2 -- rc/core/python.kak | 2 -- 6 files changed, 13 deletions(-) diff --git a/rc/base/d.kak b/rc/base/d.kak index a080a776..8822d9a6 100644 --- a/rc/base/d.kak +++ b/rc/base/d.kak @@ -111,7 +111,6 @@ hook global WinSetOption filetype=d %{ hook window InsertChar \{ -group d-indent _d-indent-on-opening-curly-brace hook window InsertChar \} -group d-indent _d-indent-on-closing-curly-brace - set window formatcmd "dfmt" set window comment_selection_chars "/+:+/" } diff --git a/rc/base/go.kak b/rc/base/go.kak index bbb83092..c4b20791 100644 --- a/rc/base/go.kak +++ b/rc/base/go.kak @@ -92,8 +92,6 @@ hook global WinSetOption filetype=go %{ hook window InsertChar \n -group go-indent _go-indent-on-new-line hook window InsertChar \{ -group go-indent _go-indent-on-opening-curly-brace hook window InsertChar \} -group go-indent _go-indent-on-closing-curly-brace - - set window formatcmd "gofmt" } hook -group go-highlight global WinSetOption filetype=(?!go).* %{ rmhl go } diff --git a/rc/base/perl.kak b/rc/base/perl.kak index 086ec4e4..2c7b0009 100644 --- a/rc/base/perl.kak +++ b/rc/base/perl.kak @@ -118,7 +118,6 @@ hook global WinSetOption filetype=perl %{ hook window InsertChar \{ -group perl-indent _perl-indent-on-opening-curly-brace hook window InsertChar \} -group perl-indent _perl-indent-on-closing-curly-brace - set window formatcmd "perltidy" set window comment_selection_chars "" set window comment_line_chars "#" } diff --git a/rc/base/ruby.kak b/rc/base/ruby.kak index a4e8b181..82984197 100644 --- a/rc/base/ruby.kak +++ b/rc/base/ruby.kak @@ -161,11 +161,6 @@ hook global WinSetOption filetype=ruby %{ set window comment_line_chars '#' set window comment_selection_chars '^begin=:^=end' - - # Rubocop requires a filepath that will be used when generating the errors summary, - # even though it's reading anonymous data on stdin - # It also leaves an ugly separator on the first line on the output - set window formatcmd 'rubocop --auto-correct --stdin - -o /dev/null | sed 1d' } hook -group ruby-highlight global WinSetOption filetype=(?!ruby).* %{ rmhl ruby } diff --git a/rc/core/c-family.kak b/rc/core/c-family.kak index 293c7335..e8c81613 100644 --- a/rc/core/c-family.kak +++ b/rc/core/c-family.kak @@ -240,8 +240,6 @@ hook global WinSetOption filetype=(c|cpp|objc) %[ hook -group c-family-insert window InsertChar \n _c-family-insert-on-newline alias window alt c-family-alternative-file - - set window formatcmd "astyle" ] hook global WinSetOption filetype=(?!(c|cpp|objc)$).* %[ diff --git a/rc/core/python.kak b/rc/core/python.kak index 69da651a..42d9d449 100644 --- a/rc/core/python.kak +++ b/rc/core/python.kak @@ -75,8 +75,6 @@ hook global WinSetOption filetype=python %{ hook window InsertChar \n -group python-indent _python_indent_on_new_line # cleanup trailing whitespaces on current line insert end hook window InsertEnd .* -group python-indent %{ try %{ exec -draft \; s ^\h+$ d } } - - set window formatcmd "autopep8 -" } hook -group python-highlight global WinSetOption filetype=(?!python).* %{ rmhl python } From 5db1d1beef2a4bcfff22538789ee63f061e3a794 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Fri, 14 Oct 2016 22:12:01 +0300 Subject: [PATCH 2/5] Move the commenting variables back to `commenting.kak` Initialising the `comment_line_chars` and `comment_selection_chars` variables in language support scripts created a hard dependency of those scripts to `commenting.kak`, which would create errors when this script was not loaded, e.g. when running tests. --- rc/base/css.kak | 2 -- rc/base/d.kak | 2 -- rc/base/html.kak | 2 -- rc/base/lua.kak | 5 ----- rc/base/perl.kak | 3 --- rc/base/ruby.kak | 5 ----- rc/core/commenting.kak | 44 ++++++++++++++++++++++++++++++++++++++++++ rc/core/makefile.kak | 3 --- rc/extra/coffee.kak | 5 ----- rc/extra/latex.kak | 4 ---- rc/extra/moon.kak | 5 ----- 11 files changed, 44 insertions(+), 36 deletions(-) diff --git a/rc/base/css.kak b/rc/base/css.kak index 8ebc6a8a..06c483aa 100644 --- a/rc/base/css.kak +++ b/rc/base/css.kak @@ -72,8 +72,6 @@ hook global WinSetOption filetype=css %[ hook window InsertEnd .* -group css-hooks _css_filter_around_selections hook window InsertChar \n -group css-indent _css_indent_on_new_line hook window InsertChar \} -group css-indent _css_indent_on_closing_curly_brace - - set comment_line_chars "" ] hook -group css-highlight global WinSetOption filetype=(?!css).* %{ rmhl css } diff --git a/rc/base/d.kak b/rc/base/d.kak index 8822d9a6..52dfd539 100644 --- a/rc/base/d.kak +++ b/rc/base/d.kak @@ -110,8 +110,6 @@ hook global WinSetOption filetype=d %{ hook window InsertChar \n -group d-indent _d-indent-on-new-line hook window InsertChar \{ -group d-indent _d-indent-on-opening-curly-brace hook window InsertChar \} -group d-indent _d-indent-on-closing-curly-brace - - set window comment_selection_chars "/+:+/" } hook -group d-highlight global WinSetOption filetype=(?!d).* %{ rmhl d } diff --git a/rc/base/html.kak b/rc/base/html.kak index bbb2d5ec..066a01a2 100644 --- a/rc/base/html.kak +++ b/rc/base/html.kak @@ -69,8 +69,6 @@ hook global WinSetOption filetype=html %{ hook window InsertEnd .* -group html-hooks _html_filter_around_selections hook window InsertChar .* -group html-indent _html_indent_on_char hook window InsertChar \n -group html-indent _html_indent_on_new_line - - set window comment_selection_chars '' } hook -group html-highlight global WinSetOption filetype=(?!html).* %{ rmhl html } diff --git a/rc/base/lua.kak b/rc/base/lua.kak index 73c058ba..609f5036 100644 --- a/rc/base/lua.kak +++ b/rc/base/lua.kak @@ -1,8 +1,6 @@ # http://lua.org # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ -# require commenting.kak - # Detection # ‾‾‾‾‾‾‾‾‾ @@ -103,9 +101,6 @@ hook global WinSetOption filetype=lua %{ hook window InsertChar \n -group lua-indent _lua_indent_on_new_line alias window alt lua-alternative-file - - set window comment_line_chars '--' - set window comment_selection_chars '\Q--[[:]]' } hook -group lua-highlight global WinSetOption filetype=(?!lua).* %{ rmhl lua } diff --git a/rc/base/perl.kak b/rc/base/perl.kak index 2c7b0009..d4c30695 100644 --- a/rc/base/perl.kak +++ b/rc/base/perl.kak @@ -117,9 +117,6 @@ hook global WinSetOption filetype=perl %{ hook window InsertChar \n -group perl-indent _perl-indent-on-new-line hook window InsertChar \{ -group perl-indent _perl-indent-on-opening-curly-brace hook window InsertChar \} -group perl-indent _perl-indent-on-closing-curly-brace - - set window comment_selection_chars "" - set window comment_line_chars "#" } hook -group perl-highlight global WinSetOption filetype=(?!perl).* %{ rmhl perl } diff --git a/rc/base/ruby.kak b/rc/base/ruby.kak index 82984197..185db608 100644 --- a/rc/base/ruby.kak +++ b/rc/base/ruby.kak @@ -1,8 +1,6 @@ # http://ruby-lang.org # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ -# require commenting.kak - # Detection # ‾‾‾‾‾‾‾‾‾ @@ -158,9 +156,6 @@ hook global WinSetOption filetype=ruby %{ hook window InsertChar \n -group ruby-insert _ruby_insert_on_new_line alias window alt ruby-alternative-file - - set window comment_line_chars '#' - set window comment_selection_chars '^begin=:^=end' } hook -group ruby-highlight global WinSetOption filetype=(?!ruby).* %{ rmhl ruby } diff --git a/rc/core/commenting.kak b/rc/core/commenting.kak index 8cec5de7..c2b7054a 100644 --- a/rc/core/commenting.kak +++ b/rc/core/commenting.kak @@ -4,6 +4,50 @@ decl str-list comment_selection_chars "/*:*/" ## Characters that will be inserted at the beginning of a line to comment decl str comment_line_chars "//" +## Default characters for all languages +hook global BufSetOption filetype=coffee %{ + set buffer comment_line_chars '#' + set buffer comment_selection_chars '###:###' +} + +hook global BufSetOption filetype=css %{ + set buffer comment_line_chars '' +} + +hook global BufSetOption filetype=d %{ + set buffer comment_selection_chars '/+:+/' +} + +hook global BufSetOption filetype=html %{ + set buffer comment_line_chars '' + set buffer comment_selection_chars '' +} + +hook global BufSetOption filetype=latex %{ + set buffer comment_line_chars '%' + set buffer comment_selection_chars '' +} + +hook global BufSetOption filetype=lua %{ + set buffer comment_line_chars '--' + set buffer comment_selection_chars '--[[:]]' +} + +hook global BufSetOption filetype=moon %{ + set buffer comment_line_chars '--' + set buffer comment_selection_chars '' +} + +hook global BufSetOption filetype=(perl|makefile) %{ + set buffer comment_line_chars '#' + set buffer comment_selection_chars '' +} + +hook global BufSetOption filetype=ruby %{ + set buffer comment_line_chars '#' + set buffer comment_selection_chars '^begin=:^=end' +} + def comment-selection -docstring "Comment/uncomment the current selection" %{ %sh{ function exec_proof { diff --git a/rc/core/makefile.kak b/rc/core/makefile.kak index f60bec10..7b06eef7 100644 --- a/rc/core/makefile.kak +++ b/rc/core/makefile.kak @@ -58,9 +58,6 @@ hook -group makefile-highlight global WinSetOption filetype=makefile %{ addhl re hook global WinSetOption filetype=makefile %{ hook window InsertChar \n -group makefile-indent _makefile-indent-on-new-line - - set window comment_selection_chars "" - set window comment_line_chars "#" } hook -group makefile-highlight global WinSetOption filetype=(?!makefile).* %{ rmhl makefile } diff --git a/rc/extra/coffee.kak b/rc/extra/coffee.kak index 21f5f5ed..3090e365 100644 --- a/rc/extra/coffee.kak +++ b/rc/extra/coffee.kak @@ -1,8 +1,6 @@ # http://coffeescript.org # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ -# require commenting.kak - # Detection # ‾‾‾‾‾‾‾‾‾ @@ -80,9 +78,6 @@ hook -group coffee-highlight global WinSetOption filetype=coffee %{ addhl ref co hook global WinSetOption filetype=coffee %{ hook window InsertEnd .* -group coffee-hooks _coffee_filter_around_selections hook window InsertChar \n -group coffee-indent _coffee_indent_on_new_line - - set window comment_line_chars '#' - set window comment_selection_chars '###:###' } hook -group coffee-highlight global WinSetOption filetype=(?!coffee).* %{ rmhl coffee } diff --git a/rc/extra/latex.kak b/rc/extra/latex.kak index 86889365..ea6e22ed 100644 --- a/rc/extra/latex.kak +++ b/rc/extra/latex.kak @@ -35,8 +35,4 @@ addhl -group /latex/content regex '\\textbf\{([^}]+)\}' 1:default+b hook -group latex-highlight global WinSetOption filetype=latex %{ addhl ref latex } -hook global WinSetOption filetype=latex %{ - set window comment_line_chars '%' -} - hook -group latex-highlight global WinSetOption filetype=(?!latex).* %{ rmhl latex } diff --git a/rc/extra/moon.kak b/rc/extra/moon.kak index 191ef3cb..e5f790f3 100644 --- a/rc/extra/moon.kak +++ b/rc/extra/moon.kak @@ -1,8 +1,6 @@ # http://moonscript.org # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ -# require commenting.kak - # Detection # ‾‾‾‾‾‾‾‾‾ @@ -106,9 +104,6 @@ hook global WinSetOption filetype=moon %{ hook window InsertChar \n -group moon-indent _moon_indent_on_new_line alias window alt moon-alternative-file - - set window comment_line_chars '--' - set window comment_selection_chars '' } hook -group moon-highlight global WinSetOption filetype=(?!moon).* %{ rmhl moon } From 68d3eda2705308099cd95dc7003442628a531c8f Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Fri, 14 Oct 2016 22:15:35 +0300 Subject: [PATCH 3/5] Miscellaneous fixes to the `commenting.kak` script This commit properly produces backslash characters within double quote strings instead of hoping the shell will not recognize the escape sequence that they form with the following character. Use the proper POSIX function declaration form. The uncommenting logic now also ignores trailing newline characters, which shortens the amount of operations needed to uncomment a selection. --- rc/core/commenting.kak | 45 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/rc/core/commenting.kak b/rc/core/commenting.kak index c2b7054a..8b749047 100644 --- a/rc/core/commenting.kak +++ b/rc/core/commenting.kak @@ -50,7 +50,7 @@ hook global BufSetOption filetype=ruby %{ def comment-selection -docstring "Comment/uncomment the current selection" %{ %sh{ - function exec_proof { + exec_proof() { ## Replace the '<' sign that is interpreted differently in `exec` printf %s\\n "$@" | sed 's,<,,g' } @@ -63,51 +63,52 @@ def comment-selection -docstring "Comment/uncomment the current selection" %{ exit fi - printf %s\\n "try %{ + printf %s\\n "eval -draft %{ try %{ ## The selection is empty - exec -draft %{\A[\h\v\n]*\z} + exec \\A[\\h\\v\\n]*\\z try %{ ## The selection has already been commented - exec -draft %{\A\Q${opening}\E.*\Q${closing}\E\z} + exec %{\\A\\Q${opening}\\E.*\\Q${closing}\\E\\n*\\z} ## Comment the selection - exec %{a${closing}i${opening}${#opening}H} + exec -draft %{a${closing}i${opening}} } catch %{ ## Uncomment the commented selection - exec -draft %{s(\A\Q${opening}\E)|(\Q${closing}\E\z)d} + exec -draft %{s(\\A\\Q${opening}\\E)|(\\Q${closing}\\E\\n*\\z)d} } - }" + } }" } } def comment-line -docstring "Comment/uncomment the current line" %{ %sh{ readonly opening="${kak_opt_comment_line_chars}" - readonly opening_escaped="\Q${opening}\E" + readonly opening_escaped="\\Q${opening}\\E" if [ -z "${opening}" ]; then echo "echo -debug 'The \`comment_line_chars\` variable is empty, could not comment the line'" exit fi - printf %s\\n " - ## Select the content of the line, without indentation - exec %{I} - - try %{ - ## There's no text on the line - exec -draft %{\A[\h\v\n]*\z} + printf %s\\n "eval -draft %{ + ## Select the content of the line, without indentation + exec I try %{ - ## The line has already been commented - exec -draft %{\A${opening_escaped}} + ## There's no text on the line + exec \\A[\\h\\v\\n]*\\z - ## Comment the line - exec %{i${opening}${#opening}H} - } catch %{ - ## Uncomment the line - exec -draft %{s\A${opening_escaped}\h*d} + try %{ + ## The line has already been commented + exec %{\\A${opening_escaped}} + + ## Comment the line + exec -draft %{i${opening}} + } catch %{ + ## Uncomment the line + exec -draft %{s\\A${opening_escaped}\\h*d} + } } }" } From ac42ea414e939c7f54a18015125ac247785a15f6 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Sat, 15 Oct 2016 11:04:43 +0300 Subject: [PATCH 4/5] Add commenting characters to all supported languages The default commenting character is now '#', considering the superior amount of files that use it for comments compared to the previous C-style comment characters. The logic now also prioritize the opening commenting characters if they contain a colon, to be able to use selection commenting on markdown files. --- rc/core/commenting.kak | 70 +++++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/rc/core/commenting.kak b/rc/core/commenting.kak index 8b749047..151502ef 100644 --- a/rc/core/commenting.kak +++ b/rc/core/commenting.kak @@ -1,23 +1,50 @@ -## Characters that will be used to surround a selection with -decl str-list comment_selection_chars "/*:*/" - ## Characters that will be inserted at the beginning of a line to comment -decl str comment_line_chars "//" +decl str comment_line_chars "#" + +## Characters that will be used to surround a selection with +decl str-list comment_selection_chars "" ## Default characters for all languages +hook global BufSetOption filetype=asciidoc %{ + set buffer comment_selection_chars '///:///' +} + +hook global BufSetOption filetype=(c|cpp|go|java|javascript|objc|sass|scala|scss|swift) %{ + set buffer comment_line_chars '//' + set buffer comment_selection_chars '/*:*/' +} + +hook global BufSetOption filetype=(cabal|haskell|moon) %{ + set buffer comment_line_chars '--' +} + +hook global BufSetOption filetype=clojure %{ + set buffer comment_line_chars '#_ ' + set buffer comment_selection_chars '(comment :)' +} + hook global BufSetOption filetype=coffee %{ - set buffer comment_line_chars '#' set buffer comment_selection_chars '###:###' } hook global BufSetOption filetype=css %{ set buffer comment_line_chars '' + set buffer comment_selection_chars '/*:*/' } hook global BufSetOption filetype=d %{ + set buffer comment_line_chars '//' set buffer comment_selection_chars '/+:+/' } +hook global BufSetOption filetype=(gas|ini) %{ + set buffer comment_line_chars ';' +} + +hook global BufSetOption filetype=haml %{ + set buffer comment_line_chars '-#' +} + hook global BufSetOption filetype=html %{ set buffer comment_line_chars '' set buffer comment_selection_chars '' @@ -25,7 +52,11 @@ hook global BufSetOption filetype=html %{ hook global BufSetOption filetype=latex %{ set buffer comment_line_chars '%' - set buffer comment_selection_chars '' +} + +hook global BufSetOption filetype=lisp %{ + set buffer comment_line_chars ';' + set buffer comment_selection_chars '#|:|#' } hook global BufSetOption filetype=lua %{ @@ -33,18 +64,29 @@ hook global BufSetOption filetype=lua %{ set buffer comment_selection_chars '--[[:]]' } -hook global BufSetOption filetype=moon %{ - set buffer comment_line_chars '--' - set buffer comment_selection_chars '' +hook global BufSetOption filetype=markdown %{ + set buffer comment_line_chars '' + set buffer comment_selection_chars '[//]: # (:)' } -hook global BufSetOption filetype=(perl|makefile) %{ - set buffer comment_line_chars '#' - set buffer comment_selection_chars '' +hook global BufSetOption filetype=perl %{ + set buffer comment_selection_chars '#[:]' +} + +hook global BufSetOption filetype=(pug|rust) %{ + set buffer comment_line_chars '//' +} + +hook global BufSetOption filetype=python %{ + set buffer comment_selection_chars '""":"""' +} + +hook global BufSetOption filetype=ragel %{ + set buffer comment_line_chars '%%' + set buffer comment_selection_chars '%%{:}%%' } hook global BufSetOption filetype=ruby %{ - set buffer comment_line_chars '#' set buffer comment_selection_chars '^begin=:^=end' } @@ -55,7 +97,7 @@ def comment-selection -docstring "Comment/uncomment the current selection" %{ printf %s\\n "$@" | sed 's,<,,g' } - readonly opening=$(exec_proof "${kak_opt_comment_selection_chars%%:*}") + readonly opening=$(exec_proof "${kak_opt_comment_selection_chars%:*}") readonly closing=$(exec_proof "${kak_opt_comment_selection_chars##*:}") if [ -z "${opening}" ] || [ -z "${closing}" ]; then From 617a5b72e25e7f60ce05ef095c8b3675029c5246 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Sat, 15 Oct 2016 13:36:19 +0300 Subject: [PATCH 5/5] Remove a script loaded in a test that's not required anymore --- test/regression/860-python-incorrect-commenting/rc | 1 - 1 file changed, 1 deletion(-) diff --git a/test/regression/860-python-incorrect-commenting/rc b/test/regression/860-python-incorrect-commenting/rc index 4eec08e1..909f53ff 100644 --- a/test/regression/860-python-incorrect-commenting/rc +++ b/test/regression/860-python-incorrect-commenting/rc @@ -1,4 +1,3 @@ source "%val{runtime}/colors/default.kak" -source "%val{runtime}/rc/core/formatter.kak" source "%val{runtime}/rc/core/python.kak" set buffer filetype python