From f7e976676c189504e73edc8e362cbfd32213801a Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Sun, 25 Oct 2015 15:17:36 +0300 Subject: [PATCH 1/4] Introduce the `commenting.kak` file Centralize commenting functions into a single file, and declare variables used by those functions in language support files. The functions are `comment-selection` and `comment-line`, users should bind those functions to the keys of their liking for easy access. --- rc/c-family.kak | 43 -------------------------- rc/commenting.kak | 77 +++++++++++++++++++++++++++++++++++++++++++++++ rc/css.kak | 2 ++ rc/dlang.kak | 1 + rc/makefile.kak | 7 ++++- rc/perl.kak | 2 ++ 6 files changed, 88 insertions(+), 44 deletions(-) create mode 100644 rc/commenting.kak diff --git a/rc/c-family.kak b/rc/c-family.kak index 1e0bf1c4..cf9271d5 100644 --- a/rc/c-family.kak +++ b/rc/c-family.kak @@ -121,8 +121,6 @@ hook global WinSetOption filetype=(c|cpp|objc) %[ hook window InsertChar \} -group c-family-indent _c-family-indent-on-closing-curly-brace alias window alt c-family-alternative-file - alias window comment-selection c-family-comment-selection - alias window comment-line c-family-comment-line set window formatcmd "astyle" ] @@ -132,8 +130,6 @@ hook global WinSetOption filetype=(?!(c|cpp|objc)$).* %[ rmhooks window c-family-indent unalias window alt c-family-alternative-file - unalias window comment-selection c-family-comment-selection - unalias window comment-line c-family-comment-line ] hook global WinSetOption filetype=c %[ addhl ref c ] @@ -188,42 +184,3 @@ def c-family-alternative-file -docstring "Jump to the alternate file (header/imp echo "echo -color Error 'alternative file not found'" fi }} - -def c-family-comment-selection -docstring "Comment the current selection" %{ - try %{ - ## The selection is empty - exec -draft %{\A[\h\v\n]*\z} - - try %{ - ## The selection has already been commented - exec -draft %{\A/\*.*\*/\z} - - ## Comment the selection - exec %{a */i/* 3H} - } catch %{ - ## Uncomment the commented selection - exec -draft %{s(\A/\* )|( \*/\z)d} - } - } -} - -def c-family-comment-line -docstring "Comment the current line" %{ - ## 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} - - try %{ - ## The line has already been commented - exec -draft %{^//} - - ## Comment the line - exec %{i// 3H} - } catch %{ - ## Uncomment the line - exec -draft %{s^//\h*d} - } - } -} diff --git a/rc/commenting.kak b/rc/commenting.kak new file mode 100644 index 00000000..b8d3dbd7 --- /dev/null +++ b/rc/commenting.kak @@ -0,0 +1,77 @@ +## 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 "//" + +def comment-selection -docstring "Comment/uncomment the current selection" %{ + %sh{ + function escape_regex_chars { + ## Escape characters that can be interpreted as modifiers/repetitors by the regex engine + sed -r 's,(\*|\+|\[|\]|\{\}|\||\(|\)|\?),\\\1,g' <<< "$@" + } + + readonly opening="${kak_opt_comment_selection_chars%%:*}" + readonly closing="${kak_opt_comment_selection_chars##*:}" + readonly opening_escaped=$(escape_regex_chars "${opening}") + readonly closing_escaped=$(escape_regex_chars "${closing}") + + if [ -z "${opening}" -o -z "${closing}" ]; then + echo "The \`comment_selection_chars\` variable is empty, couldn't comment the selection" >&2 + exit + fi + + echo "try %{ + ## The selection is empty + exec -draft %{\A[\h\v\n]*\z} + + try %{ + ## The selection has already been commented + exec -draft %{\A${opening_escaped}.*${closing_escaped}\z} + + ## Comment the selection + exec %{a ${closing}i${opening} $((${#opening} + 1))H} + } catch %{ + ## Uncomment the commented selection + exec -draft %{s(\A${opening_escaped} )|( ${closing_escaped}\z)d} + } + }" + } +} + +def comment-line -docstring "Comment/uncomment the current line" %{ + %sh{ + function escape_regex_chars { + ## Escape characters that can be interpreted as modifiers/repetitors by the regex engine + sed -r 's,(\*|\+|\[|\]|\{\}|\||\(|\)|\?),\\\1,g' <<< "$@" + } + + readonly opening="${kak_opt_comment_line_chars}" + readonly opening_escaped=$(escape_regex_chars "${opening}") + + if [ -z "${opening}" ]; then + echo "The \`comment_line_chars\` variable is empty, couldn't comment the line" >&2 + exit + fi + + echo " + ## 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} + + try %{ + ## The line has already been commented + exec -draft %{^${opening_escaped}} + + ## Comment the line + exec %{i${opening} $((${#opening} + 1))H} + } catch %{ + ## Uncomment the line + exec -draft %{s^${opening_escaped}\h*d} + } + }" + } +} diff --git a/rc/css.kak b/rc/css.kak index a68ee5cd..4eae7166 100644 --- a/rc/css.kak +++ b/rc/css.kak @@ -75,6 +75,8 @@ 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 global WinSetOption filetype=(?!css).* %{ diff --git a/rc/dlang.kak b/rc/dlang.kak index d79a4270..1495fbc6 100644 --- a/rc/dlang.kak +++ b/rc/dlang.kak @@ -83,6 +83,7 @@ hook global WinSetOption filetype=dlang %{ hook window InsertChar \} -group dlang-indent _dlang-indent-on-closing-curly-brace set window formatcmd "dfmt" + set window comment_selection_chars "/+:+/" } hook global WinSetOption filetype=(?!dlang).* %{ diff --git a/rc/makefile.kak b/rc/makefile.kak index 9284aa9d..ca042c5e 100644 --- a/rc/makefile.kak +++ b/rc/makefile.kak @@ -26,5 +26,10 @@ addhl -group /makefile/content regex [+?:]= 0:operator # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ -hook global WinSetOption filetype=makefile %{ addhl ref makefile } +hook global WinSetOption filetype=makefile %{ + addhl ref makefile + + set window comment_selection_chars "" + set window comment_line_chars "#" +} hook global WinSetOption filetype=(?!makefile).* %{ rmhl makefile } diff --git a/rc/perl.kak b/rc/perl.kak index 6803a068..32f5c5d3 100644 --- a/rc/perl.kak +++ b/rc/perl.kak @@ -108,6 +108,8 @@ hook global WinSetOption filetype=perl %{ 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 "#" } hook global WinSetOption filetype=(?!perl).* %{ From cbfc6d3cd00a14f2f9003ecff8c9f2fa5baffc34 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Tue, 27 Oct 2015 17:23:04 +0300 Subject: [PATCH 2/4] Allow different type of pre-processing guards to be included in C headers. This commit introduces the `c_include_guard_style` option, which can take one of the following values: "ifdef", "pragma", "none". The corresponding type of guard will be used accordingly to the value of this variable. --- rc/c-family.kak | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/rc/c-family.kak b/rc/c-family.kak index 1e0bf1c4..a033ac10 100644 --- a/rc/c-family.kak +++ b/rc/c-family.kak @@ -145,8 +145,19 @@ hook global WinSetOption filetype=(?!cpp$).* %[ rmhl cpp ] hook global WinSetOption filetype=objc %[ addhl ref objc ] hook global WinSetOption filetype=(?!objc$).* %[ rmhl objc ] +decl str c_include_guard_style "ifdef" def -hidden _c-family-insert-include-guards %{ - exec ggi%ggxs\.c_A_INCLUDEDggxyppI#ifndefjI#definejI#endif//O + %sh{ + case "${kak_opt_c_include_guard_style,,}" in + ifdef) + echo "exec ggi%ggxs\.c_A_INCLUDEDggxyppI#ifndefjI#definejI#endif//O" + ;; + pragma) + echo "exec ggi#pragmaonce" + ;; + *);; + esac + } } hook global BufNew .*\.(h|hh|hpp|hxx|H) _c-family-insert-include-guards From 4b7b04bf599f79cdae9cd3ec5c86ac9d8e5fd48d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 28 Oct 2015 00:01:25 +0000 Subject: [PATCH 3/4] Fix mouse scrolling up stopping at line 2 Fixes #448 --- src/input_handler.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input_handler.cc b/src/input_handler.cc index 11cf161b..1b98fb19 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -134,7 +134,7 @@ private: auto clamp_line = [&](LineCount line) { return clamp(line, 0_line, line_count-1); }; auto min_coord = buffer.offset_coord(clamp_line(win_pos.line + scrolloff.line), win_pos.column); - auto max_coord = buffer.offset_coord(clamp_line(win_pos.line + win_dim.line - scrolloff.line), win_pos.column); + auto max_coord = buffer.offset_coord(clamp_line(win_pos.line + win_dim.line - 1 - scrolloff.line), win_pos.column); selections = SelectionList{buffer, clamp(cursor, min_coord, max_coord)}; From e106592f87c818f49780a7fefd9166f79c62be51 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 29 Oct 2015 13:43:16 +0000 Subject: [PATCH 4/4] Add coverity scan support to .travis.yml --- .travis.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.travis.yml b/.travis.yml index 0d09518e..5d0c94bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,9 @@ install: elif [ $TRAVIS_OS_NAME = osx ]; then brew outdated boost || brew upgrade boost; fi; +env: + global: + - secure: "R+NxqtytOslIcQ/eCbLoZhImsgYdJnljfjANdieFQGune9ACPPQL0YanXkF49c9SWGBSxrAcute0egQzv2CU2+ivSQIX/xnMebKHiOmSPYBoxX+VgxLT3U1itUYlpYwixo9rF8UnGdlgXid6oENSiCvfWtNKoM2qOL0Ttw31J9E=" addons: apt: @@ -32,5 +35,13 @@ addons: - g++-4.8 - libncursesw5-dev - libboost-regex1.55-dev + coverity_scan: + project: + name: "mawww/kakoune" + description: "Build submitted via Travis CI" + notification_email: frrrwww@gmail.com + build_command_prepend: "make clean" + build_command: "make -j4" + branch_pattern: master script: cd src && make && make test