diff --git a/rc/filetype/cabal.kak b/rc/filetype/cabal.kak index cb95d2d9..957b397b 100644 --- a/rc/filetype/cabal.kak +++ b/rc/filetype/cabal.kak @@ -15,6 +15,7 @@ hook global WinSetOption filetype=cabal %[ require-module cabal hook window ModeChange pop:insert:.* -group cabal-trim-indent cabal-trim-indent + hook window InsertChar \n -group cabal-insert cabal-insert-on-new-line hook window InsertChar \n -group cabal-indent cabal-indent-on-new-line hook window InsertChar \{ -group cabal-indent cabal-indent-on-opening-curly-brace hook window InsertChar \} -group cabal-indent cabal-indent-on-closing-curly-brace @@ -50,10 +51,15 @@ define-command -hidden cabal-trim-indent %{ try %{ execute-keys -draft -itersel s \h+$ d } } -define-command -hidden cabal-indent-on-new-line %[ +define-command -hidden cabal-insert-on-new-line %[ evaluate-commands -draft -itersel %[ # copy '--' comment prefix and following white spaces try %[ execute-keys -draft k s ^\h*\K--\h* y gh j P ] + ] +] + +define-command -hidden cabal-indent-on-new-line %[ + evaluate-commands -draft -itersel %[ # preserve previous line indent try %[ execute-keys -draft K ] # filter previous line diff --git a/rc/filetype/coffee.kak b/rc/filetype/coffee.kak index ecb3a1a7..7c695edf 100644 --- a/rc/filetype/coffee.kak +++ b/rc/filetype/coffee.kak @@ -15,6 +15,7 @@ hook global WinSetOption filetype=coffee %{ require-module coffee hook window ModeChange pop:insert:.* -group coffee-trim-indent coffee-trim-indent + hook window InsertChar \n -group coffee-insert coffee-insert-on-new-line hook window InsertChar \n -group coffee-indent coffee-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window coffee-.+ } @@ -70,10 +71,15 @@ define-command -hidden coffee-trim-indent %{ } } -define-command -hidden coffee-indent-on-new-line %{ +define-command -hidden coffee-insert-on-new-line %{ evaluate-commands -draft -itersel %{ # copy '#' comment prefix and following white spaces try %{ execute-keys -draft k s '^\h*\K#\h*' y gh j P } + } +} + +define-command -hidden coffee-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ # preserve previous line indent try %{ execute-keys -draft K } # filter previous line diff --git a/rc/filetype/cucumber.kak b/rc/filetype/cucumber.kak index 890985c7..25280f86 100644 --- a/rc/filetype/cucumber.kak +++ b/rc/filetype/cucumber.kak @@ -15,6 +15,7 @@ hook global WinSetOption filetype=cucumber %{ require-module cucumber hook window ModeChange pop:insert:.* -group cucumber-trim-indent cucumber-trim-indent + hook window InsertChar \n -group cucumber-insert cucumber-insert-on-new-line hook window InsertChar \n -group cucumber-indent cucumber-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window cucumber-.+ } @@ -80,10 +81,15 @@ define-command -hidden cucumber-trim-indent %{ try %{ execute-keys -draft -itersel s \h+$ d } } -define-command -hidden cucumber-indent-on-new-line %{ +define-command -hidden cucumber-insert-on-new-line %{ evaluate-commands -draft -itersel %{ # copy '#' comment prefix and following white spaces try %{ execute-keys -draft k s ^\h*\K#\h* y gh j P } + } +} + +define-command -hidden cucumber-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ # preserve previous line indent try %{ execute-keys -draft K } # filter previous line diff --git a/rc/filetype/cue.kak b/rc/filetype/cue.kak index ab46059e..c89845e4 100644 --- a/rc/filetype/cue.kak +++ b/rc/filetype/cue.kak @@ -16,6 +16,7 @@ hook global WinSetOption filetype=cue %[ # cleanup trailing whitespaces when exiting insert mode hook window ModeChange pop:insert:.* -group cue-trim-indent cue-trim-indent + hook window InsertChar \n -group cue-insert cue-insert-on-new-line hook window InsertChar \n -group cue-indent cue-indent-on-new-line hook window InsertChar \{ -group cue-indent cue-indent-on-opening-curly-brace hook window InsertChar [)}] -group cue-indent cue-indent-on-closing @@ -124,21 +125,27 @@ define-command -hidden cue-trim-indent %{ try %{ execute-keys -draft -itersel s \h+$ d } } -define-command -hidden cue-indent-on-new-line %~ +define-command -hidden cue-insert-on-new-line %~ evaluate-commands -draft -itersel %< # copy // comments prefix and following white spaces - try %{ - execute-keys -draft k s ^\h*\K//[!/]?\h* y gh j P - } catch %| - # preserve previous line indent - try %{ execute-keys -draft K } + try %{ execute-keys -draft k s ^\h*\K//[!/]?\h* yP } + > +~ + +define-command -hidden cue-indent-on-new-line %~ + evaluate-commands -draft -itersel %< + # preserve previous line indent + try %{ execute-keys -draft K } + try %< + # only if we didn't copy a comment + execute-keys -draft ^\h*// # indent after lines ending with { or ( try %[ execute-keys -draft k [{(]\h*$ j ] # indent after lines ending with [{(].+ and move first parameter to own line try %< execute-keys -draft [c[({],[)}] \A[({][^\n]+\n[^\n]*\n?\z L i > # deindent closing brace(s) when after cursor try %< execute-keys -draft ^\h*[})] gh / [})] m 1 > - | + > # filter previous line try %{ execute-keys -draft k : cue-trim-indent } > diff --git a/rc/filetype/d.kak b/rc/filetype/d.kak index 5f7e9799..f2d8a2a1 100644 --- a/rc/filetype/d.kak +++ b/rc/filetype/d.kak @@ -18,6 +18,7 @@ hook global WinSetOption filetype=d %{ # cleanup trailing whitespaces when exiting insert mode hook window ModeChange pop:insert:.* -group d-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } + hook window InsertChar \n -group d-insert d-insert-on-new-line 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 @@ -105,6 +106,13 @@ add-highlighter shared/d/code/ regex "\bmodule\s+([\w_-]+)\b" 1:module # Commands # ‾‾‾‾‾‾‾‾ +define-command -hidden d-insert-on-new-line %~ + evaluate-commands -draft -itersel %= + # copy // comments prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K/{2,}\h* yP } + = +~ + define-command -hidden d-indent-on-new-line %~ evaluate-commands -draft -itersel %= # preserve previous line indent @@ -115,8 +123,6 @@ define-command -hidden d-indent-on-new-line %~ try %{ execute-keys -draft k s \h+$ d } # align to opening paren of previous line try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } - # copy // comments prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K/{2,}\h* yP } # indent after a switch's case/default statements try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] # indent after if|else|while|for diff --git a/rc/filetype/dart.kak b/rc/filetype/dart.kak index fee017ac..8cf7d652 100644 --- a/rc/filetype/dart.kak +++ b/rc/filetype/dart.kak @@ -18,6 +18,7 @@ hook global WinSetOption filetype=dart %{ # cleanup trailing whitespaces when exiting insert mode hook window ModeChange pop:insert:.* -group dart-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } + hook window InsertChar \n -group dart-insert dart-insert-on-new-line hook window InsertChar \n -group dart-indent dart-indent-on-new-line hook window InsertChar \{ -group dart-indent dart-indent-on-opening-curly-brace hook window InsertChar \} -group dart-indent dart-indent-on-closing-curly-brace @@ -81,6 +82,13 @@ evaluate-commands %sh{ # Commands # ‾‾‾‾‾‾‾‾ +define-command -hidden dart-insert-on-new-line %~ + evaluate-commands -draft -itersel %= + # copy // comments prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K/{2,}\h* yP } + = +~ + define-command -hidden dart-indent-on-new-line %~ evaluate-commands -draft -itersel %= # preserve previous line indent @@ -91,8 +99,6 @@ define-command -hidden dart-indent-on-new-line %~ try %{ execute-keys -draft k s \h+$ d } # align to opening paren of previous line try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } - # copy // comments prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K/{2,}\h* yP } # indent after a switch's case/default statements try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] # indent after if|else|while|for diff --git a/rc/filetype/dhall.kak b/rc/filetype/dhall.kak index f3a1a861..75ebc30f 100644 --- a/rc/filetype/dhall.kak +++ b/rc/filetype/dhall.kak @@ -15,6 +15,7 @@ hook global WinSetOption filetype=dhall %{ require-module dhall hook window ModeChange pop:insert:.* -group dhall-trim-indent dhall-trim-indent + hook window InsertChar \n -group dhall-insert dhall-insert-on-new-line hook window InsertChar \n -group dhall-indent dhall-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window dhall-.+ } @@ -80,10 +81,14 @@ define-command -hidden dhall-trim-indent %{ try %{ execute-keys -draft -itersel s \h+$ d } } -define-command -hidden dhall-indent-on-new-line %{ +define-command -hidden dhall-insert-on-new-line %{ evaluate-commands -draft -itersel %{ # copy -- comments prefix and following white spaces try %{ execute-keys -draft k s ^\h*\K--\h* y gh j P } + } +} +define-command -hidden dhall-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ # preserve previous line indent try %{ execute-keys -draft \; K } # filter previous line diff --git a/rc/filetype/elixir.kak b/rc/filetype/elixir.kak index 983c351b..f06ffb1c 100644 --- a/rc/filetype/elixir.kak +++ b/rc/filetype/elixir.kak @@ -19,6 +19,7 @@ hook global WinSetOption filetype=elixir %{ require-module elixir hook window ModeChange pop:insert:.* -group elixir-trim-indent elixir-trim-indent + hook window InsertChar \n -group elixir-insert elixir-insert-on-new-line hook window InsertChar \n -group elixir-indent elixir-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window elixir-.+ } @@ -91,10 +92,15 @@ define-command -hidden elixir-trim-indent %{ try %{ execute-keys -draft -itersel s \h+$ d } } -define-command -hidden elixir-indent-on-new-line %{ +define-command -hidden elixir-insert-on-new-line %{ evaluate-commands -draft -itersel %{ # copy -- comments prefix and following white spaces try %{ execute-keys -draft k s ^\h*\K--\h* y gh j P } + } +} + +define-command -hidden elixir-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ # preserve previous line indent try %{ execute-keys -draft K } # indent after line ending with: diff --git a/rc/filetype/elm.kak b/rc/filetype/elm.kak index 39538cc5..2daf8b23 100644 --- a/rc/filetype/elm.kak +++ b/rc/filetype/elm.kak @@ -15,6 +15,7 @@ hook global WinSetOption filetype=elm %{ require-module elm hook window ModeChange pop:insert:.* -group elm-trim-indent elm-trim-indent + hook window InsertChar \n -group elm-insert elm-insert-on-new-line hook window InsertChar \n -group elm-indent elm-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window elm-.+ } @@ -61,10 +62,15 @@ define-command -hidden elm-indent-after " execute-keys -draft k x ^\\h*if|[=(]$|\\b(case\\h+[\\w']+\\h+of|let|in)$|(\\{\\h+\\w+|\\w+\\h+->)$ j " -define-command -hidden elm-indent-on-new-line %{ +define-command -hidden elm-insert-on-new-line %{ evaluate-commands -draft -itersel %{ # copy -- comments prefix and following white spaces try %{ execute-keys -draft k s ^\h*\K--\h* y gh j P } + } +} + +define-command -hidden elm-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ # preserve previous line indent try %{ execute-keys -draft K } # align to first clause diff --git a/rc/filetype/fsharp.kak b/rc/filetype/fsharp.kak index b34642f3..f534c423 100644 --- a/rc/filetype/fsharp.kak +++ b/rc/filetype/fsharp.kak @@ -15,6 +15,7 @@ hook global WinSetOption filetype=fsharp %{ require-module fsharp # indent on newline + hook window InsertChar \n -group fsharp-insert fsharp-insert-on-new-line hook window InsertChar \n -group fsharp-indent fsharp-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window fsharp-.+ } @@ -124,10 +125,15 @@ add-highlighter shared/fsharp/code/ regex "\B(\(\))\B" 0:value # Commands # ‾‾‾‾‾‾‾‾ +define-command -hidden fsharp-insert-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy // comments prefix and following white spaces + try %{ execute-keys -draft k s ^\h*//\h* y jgh P } + } +} + define-command -hidden fsharp-indent-on-new-line %{ evaluate-commands -draft -itersel %{ - # copy '//' comment prefix and following white spaces - try %{ execute-keys -draft k s ^\h*//\h* y jgh P } # preserve previous line indent try %{ execute-keys -draft \; K } # cleanup trailing whitespaces from previous line diff --git a/rc/filetype/gluon.kak b/rc/filetype/gluon.kak index 62350585..17080cb9 100644 --- a/rc/filetype/gluon.kak +++ b/rc/filetype/gluon.kak @@ -16,6 +16,7 @@ hook global WinSetOption filetype=gluon %{ set-option window extra_word_chars '_' "'" hook window ModeChange pop:insert:.* -group gluon-trim-indent gluon-trim-indent + hook window InsertChar \n -group gluon-insert gluon-insert-on-new-line hook window InsertChar \n -group gluon-indent gluon-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ @@ -78,10 +79,15 @@ define-command -hidden gluon-trim-indent %{ try %{ execute-keys -draft -itersel s \h+$ d } } -define-command -hidden gluon-indent-on-new-line %~ +define-command -hidden gluon-insert-on-new-line %~ evaluate-commands -draft -itersel %_ # copy // and /// comments prefix and following white spaces try %{ execute-keys -draft k s ^\h*\K///?\h* y gh j P } + _ +~ + +define-command -hidden gluon-indent-on-new-line %~ + evaluate-commands -draft -itersel %_ # preserve previous line indent try %{ execute-keys -draft \; K } # filter previous line diff --git a/rc/filetype/go.kak b/rc/filetype/go.kak index 43c94832..a0a33ae4 100644 --- a/rc/filetype/go.kak +++ b/rc/filetype/go.kak @@ -107,8 +107,6 @@ define-command -hidden go-indent-on-new-line %~ try %{ execute-keys -draft k s \h+$ d } # align to opening paren of previous line try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } - # copy // comments prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K/{2,}\h* yP } # indent after a switch's case/default statements try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] # deindent closing brace(s) when after cursor @@ -128,6 +126,9 @@ define-command -hidden go-indent-on-closing-curly-brace %[ define-command -hidden go-insert-on-new-line %[ evaluate-commands -no-hooks -draft -itersel %[ + # copy // comments prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K/{2,}\h* yP } + # Wisely add '}'. evaluate-commands -save-regs x %[ # Save previous line indent in register x. diff --git a/rc/filetype/haml.kak b/rc/filetype/haml.kak index 6b7d4c72..cef0f56d 100644 --- a/rc/filetype/haml.kak +++ b/rc/filetype/haml.kak @@ -15,6 +15,7 @@ hook global WinSetOption filetype=haml %{ require-module haml hook window ModeChange pop:insert:.* -group haml-trim-indent haml-trim-indent + hook window InsertChar \n -group haml-insert haml-insert-on-new-line hook window InsertChar \n -group haml-indent haml-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window haml-.+ } @@ -56,10 +57,15 @@ define-command -hidden haml-trim-indent %{ try %{ execute-keys -draft -itersel s \h+$ d } } -define-command -hidden haml-indent-on-new-line %{ +define-command -hidden haml-insert-on-new-line %{ evaluate-commands -draft -itersel %{ # copy '/' comment prefix and following white spaces try %{ execute-keys -draft k s ^\h*\K/\h* y gh j P } + } +} + +define-command -hidden haml-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ # preserve previous line indent try %{ execute-keys -draft K } # filter previous line diff --git a/rc/filetype/haskell.kak b/rc/filetype/haskell.kak index e51054e4..e3f29384 100644 --- a/rc/filetype/haskell.kak +++ b/rc/filetype/haskell.kak @@ -16,6 +16,7 @@ hook global WinSetOption filetype=haskell %{ set-option buffer extra_word_chars '_' "'" hook window ModeChange pop:insert:.* -group haskell-trim-indent haskell-trim-indent + hook window InsertChar \n -group haskell-insert haskell-insert-on-new-line hook window InsertChar \n -group haskell-indent haskell-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window haskell-.+ } @@ -103,10 +104,15 @@ define-command -hidden haskell-trim-indent %{ try %{ execute-keys -draft -itersel s \h+$ d } } -define-command -hidden haskell-indent-on-new-line %{ +define-command -hidden haskell-insert-on-new-line %{ evaluate-commands -draft -itersel %{ # copy -- comments prefix and following white spaces try %{ execute-keys -draft k s ^\h*\K--\h* y gh j P } + } +} + +define-command -hidden haskell-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ # preserve previous line indent try %{ execute-keys -draft K } # align to first clause diff --git a/rc/filetype/hbs.kak b/rc/filetype/hbs.kak index e35566ad..e3a93505 100644 --- a/rc/filetype/hbs.kak +++ b/rc/filetype/hbs.kak @@ -12,6 +12,7 @@ hook global WinSetOption filetype=hbs %{ require-module hbs hook window ModeChange pop:insert:.* -group hbs-trim-indent hbs-trim-indent + hook window InsertChar \n -group hbs-insert hbs-insert-on-new-line hook window InsertChar \n -group hbs-indent hbs-indent-on-new-line hook window InsertChar .* -group hbs-indent hbs-indent-on-char hook window InsertChar '>' -group hbs-indent html-indent-on-greater-than @@ -75,10 +76,15 @@ define-command -hidden hbs-indent-on-char %[ ] ] -define-command -hidden hbs-indent-on-new-line %{ +define-command -hidden hbs-insert-on-new-line %{ evaluate-commands -draft -itersel %{ # copy '/' comment prefix and following white spaces try %{ execute-keys -draft k s ^\h*\K/\h* y j p } + } +} + +define-command -hidden hbs-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ # preserve previous line indent try %{ execute-keys -draft K } # filter previous line diff --git a/rc/filetype/i3.kak b/rc/filetype/i3.kak index 241732bd..6b37eb96 100644 --- a/rc/filetype/i3.kak +++ b/rc/filetype/i3.kak @@ -10,6 +10,7 @@ hook global WinSetOption filetype=i3 %[ # cleanup trailing whitespaces when exiting insert mode hook window ModeChange pop:insert:.* -group i3-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } + hook window InsertChar \n -group i3-insert i3-insert-on-new-line hook window InsertChar \n -group i3-indent i3-indent-on-new-line hook window InsertChar \} -group i3-indent i3-indent-on-closing-curly-brace @@ -67,10 +68,15 @@ add-highlighter shared/i3/code/ regex "client\.(focused_inactive|focused|unfocus # Commands # ‾‾‾‾‾‾‾‾ -define-command -hidden i3-indent-on-new-line %~ +define-command -hidden i3-insert-on-new-line %~ evaluate-commands -draft -itersel %= # copy # comments prefix try %{ execute-keys -draft k s ^\h*#\h* y jgh P } + = +~ + +define-command -hidden i3-indent-on-new-line %~ + evaluate-commands -draft -itersel %= # preserve previous line indent try %{ execute-keys -draft K } # indent after lines ending with { diff --git a/rc/filetype/java.kak b/rc/filetype/java.kak index a1047665..7fe91bbc 100644 --- a/rc/filetype/java.kak +++ b/rc/filetype/java.kak @@ -10,6 +10,7 @@ hook global WinSetOption filetype=java %{ # cleanup trailing whitespaces when exiting insert mode hook window ModeChange pop:insert:.* -group java-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } + hook window InsertChar \n -group java-insert java-insert-on-new-line hook window InsertChar \n -group java-indent java-indent-on-new-line hook window InsertChar \{ -group java-indent java-indent-on-opening-curly-brace hook window InsertChar \} -group java-indent java-indent-on-closing-curly-brace @@ -40,6 +41,11 @@ add-highlighter shared/java/code/ regex "(?k s ^\h*\K/{2,}\h* yP } +] + define-command -hidden java-indent-on-new-line %~ evaluate-commands -draft -itersel %= # preserve previous line indent @@ -50,8 +56,6 @@ define-command -hidden java-indent-on-new-line %~ try %{ execute-keys -draft k s \h+$ d } # align to opening paren of previous line try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } - # copy // comments prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K/{2,}\h* yP } # indent after a switch's case/default statements try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] # indent after keywords diff --git a/rc/filetype/javascript.kak b/rc/filetype/javascript.kak index 5713d5a6..089061ab 100644 --- a/rc/filetype/javascript.kak +++ b/rc/filetype/javascript.kak @@ -17,6 +17,7 @@ hook global WinSetOption filetype=(javascript|typescript) %{ hook window ModeChange pop:insert:.* -group "%val{hook_param_capture_1}-trim-indent" javascript-trim-indent hook window InsertChar .* -group "%val{hook_param_capture_1}-indent" javascript-indent-on-char + hook window InsertChar \n -group "%val{hook_param_capture_1}-insert" javascript-insert-on-new-line hook window InsertChar \n -group "%val{hook_param_capture_1}-indent" javascript-indent-on-new-line hook -once -always window WinSetOption filetype=.* " @@ -52,10 +53,15 @@ define-command -hidden javascript-indent-on-char %< > > -define-command -hidden javascript-indent-on-new-line %< +define-command -hidden javascript-insert-on-new-line %< evaluate-commands -draft -itersel %< # copy // comments prefix and following white spaces try %{ execute-keys -draft k s ^\h*\K/{2,}\h* y gh j P } + > +> + +define-command -hidden javascript-indent-on-new-line %< + evaluate-commands -draft -itersel %< # preserve previous line indent try %{ execute-keys -draft K } # filter previous line diff --git a/rc/filetype/moon.kak b/rc/filetype/moon.kak index 1e62f464..ce68f8d0 100644 --- a/rc/filetype/moon.kak +++ b/rc/filetype/moon.kak @@ -16,6 +16,7 @@ hook global WinSetOption filetype=moon %{ hook window ModeChange pop:insert:.* -group moon-trim-indent moon-trim-indent hook window InsertChar .* -group moon-indent moon-indent-on-char + hook window InsertChar \n -group moon-insert moon-insert-on-new-line hook window InsertChar \n -group moon-indent moon-indent-on-new-line alias window alt moon-alternative-file @@ -96,10 +97,15 @@ define-command -hidden moon-indent-on-char %{ } } -define-command -hidden moon-indent-on-new-line %{ +define-command -hidden moon-insert-on-new-line %{ evaluate-commands -draft -itersel %{ # copy -- comment prefix and following white spaces try %{ execute-keys -draft k s ^\h*\K--\h* y gh j P } + } +} + +define-command -hidden moon-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ # preserve previous line indent try %{ execute-keys -draft K } # filter previous line diff --git a/rc/filetype/nim.kak b/rc/filetype/nim.kak index 1f6a8335..238804c2 100644 --- a/rc/filetype/nim.kak +++ b/rc/filetype/nim.kak @@ -16,6 +16,7 @@ hook global WinSetOption filetype=nim %{ set-option window static_words %opt{nim_static_words} + hook window InsertChar \n -group nim-insert nim-insert-on-new-line hook window InsertChar \n -group nim-indent nim-indent-on-new-line # cleanup trailing whitespaces on current line insert end hook window ModeChange pop:insert:.* -group nim-trim-indent %{ try %{ exec -draft s ^\h+$ d } } @@ -108,10 +109,15 @@ add-highlighter shared/nim/code/ regex %{'(\\([rcnlftvabe\\"']|0*[12]?\d?\d|x[0- # Commands # ‾‾‾‾‾‾‾‾ -define-command -hidden nim-indent-on-new-line %{ +define-command -hidden nim-insert-on-new-line %{ evaluate-commands -draft -itersel %{ # copy '#' comment prefix and following white spaces try %{ exec -draft k s ^\h*#\h* y jgh P } + } +} + +define-command -hidden nim-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ # preserve previous line indent try %{ exec -draft K } # cleanup trailing whitespaces from previous line diff --git a/rc/filetype/ninja.kak b/rc/filetype/ninja.kak index 0dc0132d..6ae51148 100644 --- a/rc/filetype/ninja.kak +++ b/rc/filetype/ninja.kak @@ -17,6 +17,7 @@ hook global WinSetOption filetype=ninja %{ set-option window static_words %opt{ninja_static_words} hook window ModeChange pop:insert:.* -group ninja-trim-indent ninja-trim-indent + hook window InsertChar \n -group ninja-insert ninja-insert-on-new-line hook window InsertChar \n -group ninja-indent ninja-indent-on-new-line # cleanup trailing whitespaces on current line insert end hook window ModeChange pop:insert:.* -group ninja-trim-indent %{ try %{ execute-keys -draft s ^\h+$ d } } @@ -84,10 +85,15 @@ define-command -hidden ninja-trim-indent %{ try %{ execute-keys -draft -itersel s \h+$ d } } -define-command -hidden ninja-indent-on-new-line %{ +define-command -hidden ninja-insert-on-new-line %{ evaluate-commands -draft -itersel %{ # copy -- comments prefix and following white spaces try %{ execute-keys -draft k s ^\h*\K--\h* y gh j P } + } +} + +define-command -hidden ninja-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ # preserve previous line indent try %{ execute-keys -draft \; K } # filter previous line diff --git a/rc/filetype/nix.kak b/rc/filetype/nix.kak index 34133911..87d4fc32 100644 --- a/rc/filetype/nix.kak +++ b/rc/filetype/nix.kak @@ -16,6 +16,7 @@ hook global WinSetOption filetype=nix %{ hook window ModeChange pop:insert:.* -group nix-trim-indent nix-trim-indent hook window InsertChar .* -group nix-indent nix-indent-on-char + hook window InsertChar \n -group nix-insert nix-insert-on-new-line hook window InsertChar \n -group nix-indent nix-indent-on-new-line set-option buffer extra_word_chars _ - @@ -100,10 +101,15 @@ define-command -hidden nix-indent-on-char %< > > -define-command -hidden nix-indent-on-new-line %< +define-command -hidden nix-insert-on-new-line %< evaluate-commands -draft -itersel %< # copy // comments prefix and following white spaces try %{ execute-keys -draft k s ^\h*\K#\h* y gh j P } + > +> + +define-command -hidden nix-indent-on-new-line %< + evaluate-commands -draft -itersel %< # preserve previous line indent try %{ execute-keys -draft K } # filter previous line diff --git a/rc/filetype/perl.kak b/rc/filetype/perl.kak index 1106b544..91ed3211 100644 --- a/rc/filetype/perl.kak +++ b/rc/filetype/perl.kak @@ -18,6 +18,7 @@ hook global WinSetOption filetype=perl %{ # cleanup trailing whitespaces when exiting insert mode hook window ModeChange pop:insert:.* -group perl-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } + hook window InsertChar \n -group perl-insert perl-insert-on-new-line 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 @@ -106,6 +107,13 @@ add-highlighter shared/perl/code/ regex \$(LAST_REGEXP_CODE_RESULT|LIST_SEPARATO # Commands # ‾‾‾‾‾‾‾‾ +define-command -hidden perl-insert-on-new-line %~ + evaluate-commands -draft -itersel %= + # copy # comments prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K#\h* yP } + = +~ + define-command -hidden perl-indent-on-new-line %~ evaluate-commands -draft -itersel %= # preserve previous line indent @@ -116,8 +124,6 @@ define-command -hidden perl-indent-on-new-line %~ try %{ execute-keys -draft k s \h+$ d } # align to opening paren of previous line try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } - # copy # comments prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K#\h* yP } # indent after a switch's case/default statements try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] # indent after if|else|while|for diff --git a/rc/filetype/php.kak b/rc/filetype/php.kak index 1c51df76..be03de9e 100644 --- a/rc/filetype/php.kak +++ b/rc/filetype/php.kak @@ -13,6 +13,7 @@ hook global WinSetOption filetype=php %{ hook window ModeChange pop:insert:.* -group php-trim-indent php-trim-indent hook window InsertChar .* -group php-indent php-indent-on-char + hook window InsertChar \n -group php-insert php-insert-on-new-line hook window InsertChar \n -group php-indent php-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window php-.+ } @@ -81,18 +82,23 @@ define-command -hidden php-indent-on-char %< > > -define-command -hidden php-indent-on-new-line %< +define-command -hidden php-insert-on-new-line %< evaluate-commands -draft -itersel %< # copy // comments or docblock * prefix and following white spaces - try %{ execute-keys -draft s [^/] k s ^\h*\K(?://|[*][^/])\h* y gh j P } + try %{ execute-keys -draft s [^/] k s ^\h*\K(?://|[*][^/])\h* y gh j P + # append " * " on lines starting a multiline /** or /* comment + try %{ execute-keys -draft k s ^\h*/[*][* ]? j gi i * } + > +> + +define-command -hidden php-indent-on-new-line %< + evaluate-commands -draft -itersel %< # preserve previous line indent try %{ execute-keys -draft K } # filter previous line try %{ execute-keys -draft k : php-trim-indent } # indent after lines beginning / ending with opener token try %_ execute-keys -draft k ^\h*[[{]|[[{]$ j _ - # append " * " on lines starting a multiline /** or /* comment - try %{ execute-keys -draft k s ^\h*/[*][* ]? j gi i * } # deindent closer token(s) when after cursor try %_ execute-keys -draft ^\h*[})] gh / [})] m 1 _ > diff --git a/rc/filetype/pony.kak b/rc/filetype/pony.kak index 3357553c..406c7dbb 100644 --- a/rc/filetype/pony.kak +++ b/rc/filetype/pony.kak @@ -16,6 +16,7 @@ hook global WinSetOption filetype=pony %{ set-option window static_words %opt{pony_static_words} + hook window InsertChar \n -group pony-insert pony-insert-on-new-line hook window InsertChar \n -group pony-indent pony-indent-on-new-line # cleanup trailing whitespaces on current line insert end hook window ModeChange pop:insert:.* -group pony-trim-indent %{ try %{ execute-keys -draft s ^\h+$ d } } @@ -80,14 +81,19 @@ evaluate-commands %sh{ # Commands # ‾‾‾‾‾‾‾‾ +define-command -hidden pony-insert-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy // comments prefix and following white spaces + try %{ execute-keys -draft k x s ^\h*//\h* y jgh P } + } +} + define-command -hidden pony-indent-on-new-line %{ evaluate-commands -draft -itersel %{ # preserve previous line indent try %{ execute-keys -draft K } # cleanup trailing whitespaces from previous line try %{ execute-keys -draft k s \h+$ d } - # copy '//' comment prefix and following white spaces - # try %{ execute-keys -draft k x s ^\h*//\h* y jgh P } # indent after line ending with : try %{ execute-keys -draft k x (\b(?:do|try|then|else)|:|=>)$ j } # else, end are always de-indented diff --git a/rc/filetype/purescript.kak b/rc/filetype/purescript.kak index f03d4fbb..efa0a645 100644 --- a/rc/filetype/purescript.kak +++ b/rc/filetype/purescript.kak @@ -18,6 +18,7 @@ hook global WinSetOption filetype=purescript %{ set-option buffer extra_word_chars '_' "'" hook window ModeChange pop:insert:.* -group purescript-trim-indent purescript-trim-indent + hook window InsertChar \n -group purescript-insert purescript-insert-on-new-line hook window InsertChar \n -group purescript-indent purescript-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window purescript-.+ } @@ -96,10 +97,15 @@ define-command -hidden purescript-trim-indent %{ try %{ execute-keys -draft -itersel s \h+$ d } } -define-command -hidden purescript-indent-on-new-line %{ +define-command -hidden purescript-insert-on-new-line %{ evaluate-commands -draft -itersel %{ # copy -- comments prefix and following white spaces try %{ execute-keys -draft k s ^\h*\K--\h* y gh j P } + } +} + +define-command -hidden purescript-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ # preserve previous line indent try %{ execute-keys -draft K } # align to first clause diff --git a/rc/filetype/ragel.kak b/rc/filetype/ragel.kak index eadcf1f7..b3f9230d 100644 --- a/rc/filetype/ragel.kak +++ b/rc/filetype/ragel.kak @@ -18,6 +18,7 @@ hook global WinSetOption filetype=ragel %{ hook window ModeChange pop:insert:.* -group ragel-trim-indent ragel-trim-indent hook window InsertChar .* -group ragel-indent ragel-indent-on-char + hook window InsertChar \n -group ragel-insert ragel-insert-on-new-line hook window InsertChar \n -group ragel-indent ragel-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window ragel-.+ } @@ -60,10 +61,15 @@ define-command -hidden ragel-indent-on-char %< > > -define-command -hidden ragel-indent-on-new-line %< +define-command -hidden ragel-insert-on-new-line %< evaluate-commands -draft -itersel %< # copy _#_ comment prefix and following white spaces try %{ execute-keys -draft k s ^\h*\K#\h* y gh j P } + > +> + +define-command -hidden ragel-indent-on-new-line %< + evaluate-commands -draft -itersel %< # preserve previous line indent try %{ execute-keys -draft K } # filter previous line diff --git a/rc/filetype/sass.kak b/rc/filetype/sass.kak index 02ec52aa..d315aff7 100644 --- a/rc/filetype/sass.kak +++ b/rc/filetype/sass.kak @@ -16,6 +16,7 @@ hook global WinSetOption filetype=sass %< hook window ModeChange pop:insert:.* -group sass-trim-indent sass-trim-indent hook window InsertChar \} -group sass-indent sass-indent-on-closing-brace + hook window InsertChar \n -group sass-insert sass-insert-on-new-line hook window InsertChar \n -group sass-indent sass-indent-on-new-line set-option buffer extra_word_chars '_' '-' @@ -62,10 +63,15 @@ define-command -hidden sass-indent-on-closing-brace %< > > +define-command -hidden sass-insert-on-new-line %< + evaluate-commands -draft -itersel %< + # copy // comment prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K/{2,}\h* y gh j P } + > +> + define-command -hidden sass-indent-on-new-line %< evaluate-commands -draft -itersel %< - # copy '/' comment prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K/{2,}\h* y gh j P } # preserve previous line indent try %{ execute-keys -draft K } # filter previous line diff --git a/rc/filetype/scala.kak b/rc/filetype/scala.kak index 48dfa937..ca167c9e 100644 --- a/rc/filetype/scala.kak +++ b/rc/filetype/scala.kak @@ -15,6 +15,7 @@ hook global WinSetOption filetype=scala %[ require-module scala hook window ModeChange pop:insert:.* -group scala-trim-indent scala-trim-indent + hook window InsertChar \n -group scala-insert scala-insert-on-new-line hook window InsertChar \n -group scala-indent scala-indent-on-new-line hook window InsertChar \} -group scala-indent scala-indent-on-closing-curly-brace @@ -59,10 +60,15 @@ define-command -hidden scala-trim-indent %{ try %{ execute-keys -draft -itersel s \h+$ d } } -define-command -hidden scala-indent-on-new-line %[ +define-command -hidden scala-insert-on-new-line %[ evaluate-commands -draft -itersel %[ # copy // comments prefix and following white spaces - try %[ execute-keys -draft k s ^\h*\K#\h* y gh j P ] + try %{ execute-keys -draft k s ^\h*\K#\h* yP } + ] +] + +define-command -hidden scala-indent-on-new-line %[ + evaluate-commands -draft -itersel %[ # preserve previous line indent try %[ execute-keys -draft K ] # filter previous line diff --git a/rc/filetype/toml.kak b/rc/filetype/toml.kak index d8377e69..d4adf3aa 100644 --- a/rc/filetype/toml.kak +++ b/rc/filetype/toml.kak @@ -15,6 +15,7 @@ hook global WinSetOption filetype=toml %{ require-module toml hook window ModeChange pop:insert:.* -group toml-trim-indent toml-trim-indent + hook window InsertChar \n -group toml-insert toml-insert-on-new-line hook window InsertChar \n -group toml-indent toml-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window toml-.+ } @@ -56,10 +57,15 @@ define-command -hidden toml-trim-indent %{ try %{ execute-keys -draft -itersel s \h+$ d } } +define-command -hidden toml-insert-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy # comments prefix and following white spaces + try %{ execute-keys -draft k s ^\h*\K#\h* y gh j P } + } +} + define-command -hidden toml-indent-on-new-line %{ evaluate-commands -draft -itersel %{ - # copy comment prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K#\h* y gh j P } # preserve previous line indent try %{ execute-keys -draft K } # filter previous line diff --git a/rc/filetype/yaml.kak b/rc/filetype/yaml.kak index e29a8a3e..7abaf22a 100644 --- a/rc/filetype/yaml.kak +++ b/rc/filetype/yaml.kak @@ -15,6 +15,7 @@ hook global WinSetOption filetype=yaml %{ require-module yaml hook window ModeChange pop:insert:.* -group yaml-trim-indent yaml-trim-indent + hook window InsertChar \n -group yaml-insert yaml-insert-on-new-line hook window InsertChar \n -group yaml-indent yaml-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window yaml-.+ } } @@ -49,10 +50,15 @@ define-command -hidden yaml-trim-indent %{ try %{ execute-keys -draft -itersel s \h+$ d } } -define-command -hidden yaml-indent-on-new-line %{ +define-command -hidden yaml-insert-on-new-line %{ evaluate-commands -draft -itersel %{ # copy '#' comment prefix and following white spaces try %{ execute-keys -draft k s ^\h*\K#\h* y gh j P } + } +} + +define-command -hidden yaml-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ # preserve previous line indent try %{ execute-keys -draft K } # filter previous line diff --git a/rc/filetype/zig.kak b/rc/filetype/zig.kak index beffa881..956581c4 100644 --- a/rc/filetype/zig.kak +++ b/rc/filetype/zig.kak @@ -16,6 +16,7 @@ hook global BufCreate .*[.]zig %{ hook global WinSetOption filetype=zig %< require-module zig hook window ModeChange pop:insert:.* -group zig-trim-indent zig-trim-indent + hook window InsertChar \n -group zig-insert zig-insert-on-new-line hook window InsertChar \n -group zig-indent zig-indent-on-new-line hook window InsertChar \} -group zig-indent zig-indent-on-closing @@ -99,16 +100,20 @@ define-command -hidden zig-trim-indent %{ try %{ execute-keys -draft -itersel s \h+$ d } } +define-command -hidden zig-insert-on-new-line %< + evaluate-commands -draft -itersel %< + # copy // or /// comments prefix and following whitespace + try %< execute-keys -draft k s ^\h*\K///?\h* y gh j P > + > +> + define-command -hidden zig-indent-on-new-line %< evaluate-commands -draft -itersel %< + # preserve indent level + try %< execute-keys -draft K > try %< - # copy // or /// comments prefix and following whitespace - execute-keys -draft k s ^\h*\K///?\h* y gh j P - # preserve indent level - try %< execute-keys -draft K > - > catch %< - # preserve indent level - try %< execute-keys -draft K > + # only if we didn't copy a comment + execute-keys -draft ^\h*// # indent after lines ending in { try %< execute-keys -draft k \{\h*$ j > # deindent closing } when after cursor