From 5989903e7c492b90045aa8db778694d2c442429c Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 11 Jan 2017 13:56:48 +0000 Subject: [PATCH] Copy comments *before* copying indentation Fixes #1118 --- rc/base/fish.kak | 2 +- rc/base/haskell.kak | 4 ++-- rc/base/javascript.kak | 4 ++-- rc/base/lua.kak | 2 +- rc/base/markdown.kak | 4 ++-- rc/base/ruby.kak | 2 +- rc/base/rust.kak | 4 ++-- rc/base/scala.kak | 4 ++-- rc/base/yaml.kak | 4 ++-- rc/core/c-family.kak | 2 +- rc/core/kakrc.kak | 4 ++-- rc/core/python.kak | 4 ++-- rc/extra/cabal.kak | 4 ++-- rc/extra/coffee.kak | 4 ++-- rc/extra/cucumber.kak | 4 ++-- rc/extra/haml.kak | 4 ++-- rc/extra/hbs.kak | 4 ++-- rc/extra/moon.kak | 4 ++-- rc/extra/php.kak | 4 ++-- rc/extra/ragel.kak | 4 ++-- rc/extra/sass.kak | 4 ++-- 21 files changed, 38 insertions(+), 38 deletions(-) diff --git a/rc/base/fish.kak b/rc/base/fish.kak index 0851b64d..e12e4d34 100644 --- a/rc/base/fish.kak +++ b/rc/base/fish.kak @@ -75,8 +75,8 @@ hook -group fish-highlight global WinSetOption filetype=fish %{ add-highlighter hook global WinSetOption filetype=fish %{ hook window InsertChar .* -group fish-indent _fish_indent_on_char - hook window InsertChar \n -group fish-indent _fish_indent_on_new_line hook window InsertChar \n -group fish-insert _fish_insert_on_new_line + hook window InsertChar \n -group fish-indent _fish_indent_on_new_line } hook -group fish-highlight global WinSetOption filetype=(?!fish).* %{ remove-highlighter fish } diff --git a/rc/base/haskell.kak b/rc/base/haskell.kak index 03b928d8..d8faf1aa 100644 --- a/rc/base/haskell.kak +++ b/rc/base/haskell.kak @@ -38,14 +38,14 @@ def -hidden _haskell_filter_around_selections %{ def -hidden _haskell_indent_on_new_line %{ eval -draft -itersel %{ + # copy -- comments prefix and following white spaces + try %{ exec -draft k x s ^\h*\K--\h* y gh j P } # preserve previous line indent try %{ exec -draft K } # align to first clause try %{ exec -draft k x X s ^\h*(if|then|else)?\h*(([\w']+\h+)+=)?\h*(case\h+[\w']+\h+of|do|let|where)\h+\K.* s \`|.\' & } # filter previous line try %{ exec -draft k : _haskell_filter_around_selections } - # copy -- comments prefix and following white spaces - try %{ exec -draft k x s ^\h*\K--\h* y gh j P } # indent after lines beginning with condition or ending with expression or =( try %{ exec -draft k x ^\h*(if)|(case\h+[\w']+\h+of|do|let|where|[=(])$ j } } diff --git a/rc/base/javascript.kak b/rc/base/javascript.kak index a2ca6473..81168104 100644 --- a/rc/base/javascript.kak +++ b/rc/base/javascript.kak @@ -51,12 +51,12 @@ def -hidden _javascript_indent_on_char %< def -hidden _javascript_indent_on_new_line %< eval -draft -itersel %< + # copy // comments prefix and following white spaces + try %{ exec -draft k x s ^\h*\K#\h* y gh j P } # preserve previous line indent try %{ exec -draft K } # filter previous line try %{ exec -draft k : _javascript_filter_around_selections } - # copy // comments prefix and following white spaces - try %{ exec -draft k x s ^\h*\K#\h* y gh j P } # indent after lines beginning / ending with opener token try %_ exec -draft k x ^\h*[[{]|[[{]$ j _ > diff --git a/rc/base/lua.kak b/rc/base/lua.kak index fa35ada7..6a05157e 100644 --- a/rc/base/lua.kak +++ b/rc/base/lua.kak @@ -96,8 +96,8 @@ hook -group lua-highlight global WinSetOption filetype=lua %{ add-highlighter re hook global WinSetOption filetype=lua %{ hook window InsertChar .* -group lua-indent _lua_indent_on_char - hook window InsertChar \n -group lua-indent _lua_indent_on_new_line hook window InsertChar \n -group lua-insert _lua_insert_on_new_line + hook window InsertChar \n -group lua-indent _lua_indent_on_new_line alias window alt lua-alternative-file } diff --git a/rc/base/markdown.kak b/rc/base/markdown.kak index 19b73955..1c1e5eee 100644 --- a/rc/base/markdown.kak +++ b/rc/base/markdown.kak @@ -126,12 +126,12 @@ add-highlighter -group /markdown/content regex \H\K\h\h$ 0:PrimarySelection def -hidden _markdown_indent_on_new_line %{ eval -draft -itersel %{ + # copy block quote(s), list item prefix and following white spaces + try %{ exec -draft k x s ^\h*\K((>\h*)|[*+-])+\h* y gh j P } # preserve previous line indent try %{ exec -draft K } # remove trailing white spaces try %{ exec -draft -itersel %{ k s \h+$ d } } - # copy block quote(s), list item prefix and following white spaces - try %{ exec -draft k x s ^\h*\K((>\h*)|[*+-])+\h* y gh j P } } } diff --git a/rc/base/ruby.kak b/rc/base/ruby.kak index 0b92c4b5..3d038998 100644 --- a/rc/base/ruby.kak +++ b/rc/base/ruby.kak @@ -148,8 +148,8 @@ hook -group ruby-highlight global WinSetOption filetype=ruby %{ add-highlighter hook global WinSetOption filetype=ruby %{ hook window InsertChar .* -group ruby-indent _ruby_indent_on_char - hook window InsertChar \n -group ruby-indent _ruby_indent_on_new_line hook window InsertChar \n -group ruby-insert _ruby_insert_on_new_line + hook window InsertChar \n -group ruby-indent _ruby_indent_on_new_line alias window alt ruby-alternative-file } diff --git a/rc/base/rust.kak b/rc/base/rust.kak index 36ceac7d..bee0051f 100644 --- a/rc/base/rust.kak +++ b/rc/base/rust.kak @@ -41,12 +41,12 @@ def -hidden _rust_filter_around_selections %{ def -hidden _rust_indent_on_new_line %~ eval -draft -itersel %< + # copy // comments prefix and following white spaces + try %{ exec -draft k x s ^\h*\K//\h* y gh j P } # preserve previous line indent try %{ exec -draft K } # filter previous line try %{ exec -draft k : _rust_filter_around_selections } - # copy // comments prefix and following white spaces - try %{ exec -draft k x s ^\h*\K//\h* y gh j P } # indent after lines ending with { or ( try %[ exec -draft k [{(]\h*$ j ] # align to opening paren of previous line diff --git a/rc/base/scala.kak b/rc/base/scala.kak index 31aa1e39..8ca767e9 100644 --- a/rc/base/scala.kak +++ b/rc/base/scala.kak @@ -41,12 +41,12 @@ def -hidden _scala_filter_around_selections %{ def -hidden _scala_indent_on_new_line %[ eval -draft -itersel %[ + # copy // comments prefix and following white spaces + try %[ exec -draft k x s ^\h*\K#\h* y gh j P ] # preserve previous line indent try %[ exec -draft K ] # filter previous line try %[ exec -draft k : _scala_filter_around_selections ] - # copy // comments prefix and following white spaces - try %[ exec -draft k x s ^\h*\K#\h* y gh j P ] # indent after lines ending with { try %[ exec -draft k x \{$ j ] ] diff --git a/rc/base/yaml.kak b/rc/base/yaml.kak index 0255f7ed..caa60223 100644 --- a/rc/base/yaml.kak +++ b/rc/base/yaml.kak @@ -34,12 +34,12 @@ def -hidden _yaml_filter_around_selections %{ def -hidden _yaml_indent_on_new_line %{ eval -draft -itersel %{ + # copy '#' comment prefix and following white spaces + try %{ exec -draft k x s ^\h*\K#\h* y gh j P } # preserve previous line indent try %{ exec -draft K } # filter previous line try %{ exec -draft k : _yaml_filter_around_selections } - # copy '#' comment prefix and following white spaces - try %{ exec -draft k x s ^\h*\K#\h* y gh j P } # indent after : try %{ exec -draft k x :$ j } } diff --git a/rc/core/c-family.kak b/rc/core/c-family.kak index 3368c976..8b559605 100644 --- a/rc/core/c-family.kak +++ b/rc/core/c-family.kak @@ -238,11 +238,11 @@ hook global WinSetOption filetype=(c|cpp|objc) %[ } hook -group c-family-indent window InsertEnd .* c-family-trim-autoindent + hook -group c-family-insert window InsertChar \n c-family-insert-on-newline hook -group c-family-indent window InsertChar \n c-family-indent-on-newline hook -group c-family-indent window InsertChar \{ c-family-indent-on-opening-curly-brace hook -group c-family-indent window InsertChar \} c-family-indent-on-closing-curly-brace hook -group c-family-insert window InsertChar \} c-family-insert-on-closing-curly-brace - hook -group c-family-insert window InsertChar \n c-family-insert-on-newline alias window alt c-family-alternative-file ] diff --git a/rc/core/kakrc.kak b/rc/core/kakrc.kak index 91638a58..5125a0c9 100644 --- a/rc/core/kakrc.kak +++ b/rc/core/kakrc.kak @@ -52,12 +52,12 @@ add-highlighter -group /kakrc/shell ref sh def -hidden kak-indent-on-new-line %{ eval -draft -itersel %{ + # copy '#' comment prefix and following white spaces + try %{ exec -draft k x s ^\h*#\h* y jgh P } # preserve previous line indent try %{ exec -draft K } # cleanup trailing whitespaces from previous line try %{ exec -draft k s \h+$ d } - # copy '#' comment prefix and following white spaces - try %{ exec -draft k x s ^\h*#\h* y jgh P } # indent after line ending with %[[:punct:]] try %{ exec -draft k \%[[:punct:]]$ j } } diff --git a/rc/core/python.kak b/rc/core/python.kak index b97fa486..07462099 100644 --- a/rc/core/python.kak +++ b/rc/core/python.kak @@ -65,12 +65,12 @@ add-highlighter -group /python/comment fill comment def -hidden python-indent-on-new-line %{ eval -draft -itersel %{ + # copy '#' comment prefix and following white spaces + try %{ exec -draft k x s ^\h*#\h* y jgh P } # preserve previous line indent try %{ exec -draft K } # cleanup trailing whitespaces from previous line try %{ exec -draft k s \h+$ d } - # copy '#' comment prefix and following white spaces - try %{ exec -draft k x s ^\h*#\h* y jgh P } # indent after line ending with : try %{ exec -draft k x :$ j } } diff --git a/rc/extra/cabal.kak b/rc/extra/cabal.kak index 8913c11d..3ed4f93c 100644 --- a/rc/extra/cabal.kak +++ b/rc/extra/cabal.kak @@ -31,12 +31,12 @@ def -hidden _cabal_filter_around_selections %{ def -hidden _cabal_indent_on_new_line %[ eval -draft -itersel %[ + # copy '#' comment prefix and following white spaces + try %[ exec -draft k x s ^\h*\K#\h* y gh j P ] # preserve previous line indent try %[ exec -draft K ] # filter previous line try %[ exec -draft k : _cabal_filter_around_selections ] - # copy '#' comment prefix and following white spaces - try %[ exec -draft k x s ^\h*\K#\h* y gh j P ] # indent after lines ending with { or : try %[ exec -draft k x [:{]$ j ] ] diff --git a/rc/extra/coffee.kak b/rc/extra/coffee.kak index 384b533c..765be805 100644 --- a/rc/extra/coffee.kak +++ b/rc/extra/coffee.kak @@ -55,12 +55,12 @@ def -hidden _coffee_filter_around_selections %{ def -hidden _coffee_indent_on_new_line %{ eval -draft -itersel %{ + # copy '#' comment prefix and following white spaces + try %{ exec -draft k x s ^ \h * \K \# \h * y gh j P } # preserve previous line indent try %{ exec -draft K } # filter previous line try %{ exec -draft k : _coffee_filter_around_selections } - # copy '#' comment prefix and following white spaces - try %{ exec -draft k x s ^ \h * \K \# \h * y gh j P } # indent after start structure try %{ exec -draft k x ^ \h * (case|catch|class|else|finally|for|function|if|switch|try|while|with) \b | (=|->) $ j } } diff --git a/rc/extra/cucumber.kak b/rc/extra/cucumber.kak index 3a44c3ee..7f444003 100644 --- a/rc/extra/cucumber.kak +++ b/rc/extra/cucumber.kak @@ -63,12 +63,12 @@ def -hidden _cucumber_filter_around_selections %{ def -hidden _cucumber_indent_on_new_line %{ eval -draft -itersel %{ + # copy '#' comment prefix and following white spaces + try %{ exec -draft k x s ^\h*\K#\h* y gh j P } # preserve previous line indent try %{ exec -draft K } # filter previous line try %{ exec -draft k : _cucumber_filter_around_selections } - # copy '#' comment prefix and following white spaces - try %{ exec -draft k x s ^\h*\K#\h* y gh j P } # indent after lines containing : try %{ exec -draft k x : j } } diff --git a/rc/extra/haml.kak b/rc/extra/haml.kak index 79506af3..36e0fc80 100644 --- a/rc/extra/haml.kak +++ b/rc/extra/haml.kak @@ -40,12 +40,12 @@ def -hidden _haml_filter_around_selections %{ def -hidden _haml_indent_on_new_line %{ eval -draft -itersel %{ + # copy '/' comment prefix and following white spaces + try %{ exec -draft k x s ^\h*\K/\h* y gh j P } # preserve previous line indent try %{ exec -draft K } # filter previous line try %{ exec -draft k : _haml_filter_around_selections } - # copy '/' comment prefix and following white spaces - try %{ exec -draft k x s ^\h*\K/\h* y gh j P } # indent after lines beginning with : or - try %{ exec -draft k x ^\h*[:-] j } } diff --git a/rc/extra/hbs.kak b/rc/extra/hbs.kak index b3ae663c..04090088 100644 --- a/rc/extra/hbs.kak +++ b/rc/extra/hbs.kak @@ -41,12 +41,12 @@ def -hidden _hbs_filter_around_selections %{ def -hidden _hbs_indent_on_new_line %{ eval -draft -itersel %{ + # copy '/' comment prefix and following white spaces + try %{ exec -draft k x s ^\h*\K/\h* y j p } # preserve previous line indent try %{ exec -draft K } # filter previous line try %{ exec -draft k : _hbs_filter_around_selections } - # copy '/' comment prefix and following white spaces - try %{ exec -draft k x s ^\h*\K/\h* y j p } # indent after lines beginning with : or - try %{ exec -draft k x ^\h*[:-] j } } diff --git a/rc/extra/moon.kak b/rc/extra/moon.kak index 65c0259e..a134880f 100644 --- a/rc/extra/moon.kak +++ b/rc/extra/moon.kak @@ -76,12 +76,12 @@ def -hidden _moon_indent_on_char %{ def -hidden _moon_indent_on_new_line %{ eval -draft -itersel %{ + # copy -- comment prefix and following white spaces + try %{ exec -draft k x s ^ \h * \K -- \h * y gh j P } # preserve previous line indent try %{ exec -draft K } # filter previous line try %{ exec -draft k : _moon_filter_around_selections } - # copy -- comment prefix and following white spaces - try %{ exec -draft k x s ^ \h * \K -- \h * y gh j P } # indent after start structure try %{ exec -draft k x ^ \h * (class|else(if)?|for|if|switch|unless|when|while|with) \b | ([:=]|[-=]>) $ j } # deindent after return statements diff --git a/rc/extra/php.kak b/rc/extra/php.kak index 248c696c..01451b5b 100644 --- a/rc/extra/php.kak +++ b/rc/extra/php.kak @@ -45,12 +45,12 @@ def -hidden _php_indent_on_char %< def -hidden _php_indent_on_new_line %< eval -draft -itersel %< + # copy // comments prefix and following white spaces + try %{ exec -draft k x s ^\h*\K#\h* y gh j P } # preserve previous line indent try %{ exec -draft K } # filter previous line try %{ exec -draft k : _php_filter_around_selections } - # copy // comments prefix and following white spaces - try %{ exec -draft k x s ^\h*\K#\h* y gh j P } # indent after lines beginning / ending with opener token try %_ exec -draft k x ^\h*[[{]|[[{]$ j _ > diff --git a/rc/extra/ragel.kak b/rc/extra/ragel.kak index 3c0b2314..a0a67836 100644 --- a/rc/extra/ragel.kak +++ b/rc/extra/ragel.kak @@ -44,12 +44,12 @@ def -hidden _ragel_indent_on_char %< def -hidden _ragel_indent_on_new_line %< eval -draft -itersel %< + # copy _#_ comment prefix and following white spaces + try %{ exec -draft k x s ^\h*\K#\h* y gh j P } # preserve previous line indent try %{ exec -draft K } # filter previous line try %{ exec -draft k : _ragel_filter_around_selections } - # copy _#_ comment prefix and following white spaces - try %{ exec -draft k x s ^\h*\K#\h* y gh j P } # indent after lines ending with opener token try %< exec -draft k x [[{(*]$ j > > diff --git a/rc/extra/sass.kak b/rc/extra/sass.kak index bb5f9846..5fc8ba84 100644 --- a/rc/extra/sass.kak +++ b/rc/extra/sass.kak @@ -36,12 +36,12 @@ def -hidden _sass_filter_around_selections %{ def -hidden _sass_indent_on_new_line %{ eval -draft -itersel %{ + # copy '/' comment prefix and following white spaces + try %{ exec -draft k x s ^\h*\K/\h* y gh j P } # preserve previous line indent try %{ exec -draft K } # filter previous line try %{ exec -draft k : _sass_filter_around_selections } - # copy '/' comment prefix and following white spaces - try %{ exec -draft k x s ^\h*\K/\h* y gh j P } # avoid indent after properties and comments try %{ exec -draft k x [:/] j } }