From ac42ea414e939c7f54a18015125ac247785a15f6 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Sat, 15 Oct 2016 11:04:43 +0300 Subject: [PATCH] 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