1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-23 07:15:52 +03:00

rc: use a separate *-insert hook to auto-insert comments

This should cover all filetypes that already auto-insert comments,
except for rust.kak, which is left for a follow-up.

Most of these are straightforward, some explanation for special cases:

rc/filetype/zig.kak rc/filetype/cue.kak

  These indent hooks used their own logic to indent after "{" only if
  no comment was inserted. Replace this logic by checking if a comment
  was inserted. This works because these "*-insert" hooks are run
  before their respective "*-indent" hooks.
 
rc/filetype/php.kak

  This also has some logic to insert "*" after "/*" lines. Basic
  usage seems to work still. In future this should borrow from the
  c-family one, which works a bit better.
This commit is contained in:
Johannes Altmanninger 2021-04-17 10:17:01 +02:00
parent 0264c84742
commit 0a9c90fecf
32 changed files with 241 additions and 57 deletions

View File

@ -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 <a-x> s \h+$ <ret> 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 <a-x> s ^\h*\K--\h* <ret> y gh j P ]
]
]
define-command -hidden cabal-indent-on-new-line %[
evaluate-commands -draft -itersel %[
# preserve previous line indent
try %[ execute-keys -draft <semicolon> K <a-&> ]
# filter previous line

View File

@ -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 <a-x> s '^\h*\K#\h*' <ret> y gh j P }
}
}
define-command -hidden coffee-indent-on-new-line %{
evaluate-commands -draft -itersel %{
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# filter previous line

View File

@ -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 <a-x> s \h+$ <ret> 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 <a-x> s ^\h*\K#\h* <ret> y gh j P }
}
}
define-command -hidden cucumber-indent-on-new-line %{
evaluate-commands -draft -itersel %{
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# filter previous line

View File

@ -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 <a-x> s \h+$ <ret> 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 <a-x> s ^\h*\K//[!/]?\h* <ret> y gh j P
} catch %|
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
try %{ execute-keys -draft <semicolon><c-s>k<a-x> s ^\h*\K//[!/]?\h* <ret> y<c-o>P<esc> }
>
~
define-command -hidden cue-indent-on-new-line %~
evaluate-commands -draft -itersel %<
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
try %<
# only if we didn't copy a comment
execute-keys -draft <a-x> <a-K> ^\h*// <ret>
# indent after lines ending with { or (
try %[ execute-keys -draft k <a-x> <a-k> [{(]\h*$ <ret> j <a-gt> ]
# indent after lines ending with [{(].+ and move first parameter to own line
try %< execute-keys -draft [c[({],[)}] <ret> <a-k> \A[({][^\n]+\n[^\n]*\n?\z <ret> L i<ret><esc> <gt> <a-S> <a-&> >
# deindent closing brace(s) when after cursor
try %< execute-keys -draft <a-x> <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> >
|
>
# filter previous line
try %{ execute-keys -draft k : cue-trim-indent <ret> }
>

View File

@ -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 <a-x>s^\h+$<ret>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 <semicolon><c-s>k<a-x> s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
=
~
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<a-x> s \h+$ <ret>d }
# align to opening paren of previous line
try %{ execute-keys -draft [( <a-k> \A\([^\n]+\n[^\n]*\n?\z <ret> s \A\(\h*.|.\z <ret> '<a-;>' & }
# copy // comments prefix and following white spaces
try %{ execute-keys -draft <semicolon><c-s>k<a-x> s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
# indent after a switch's case/default statements
try %[ execute-keys -draft k<a-x> <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
# indent after if|else|while|for

View File

@ -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 <a-x>s^\h+$<ret>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 <semicolon><c-s>k<a-x> s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
=
~
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<a-x> s \h+$ <ret>d }
# align to opening paren of previous line
try %{ execute-keys -draft [( <a-k> \A\([^\n]+\n[^\n]*\n?\z <ret> s \A\(\h*.|.\z <ret> '<a-;>' & }
# copy // comments prefix and following white spaces
try %{ execute-keys -draft <semicolon><c-s>k<a-x> s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
# indent after a switch's case/default statements
try %[ execute-keys -draft k<a-x> <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
# indent after if|else|while|for

View File

@ -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 <a-x> s \h+$ <ret> 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 <a-x> s ^\h*\K--\h* <ret> 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 <a-&> }
# filter previous line

View File

@ -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 <a-x> s \h+$ <ret> 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 <a-x> s ^\h*\K--\h* <ret> y gh j P }
}
}
define-command -hidden elixir-indent-on-new-line %{
evaluate-commands -draft -itersel %{
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# indent after line ending with:

View File

@ -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 <semicolon> k x <a-k> ^\\h*if|[=(]$|\\b(case\\h+[\\w']+\\h+of|let|in)$|(\\{\\h+\\w+|\\w+\\h+->)$ <ret> j <a-gt>
"
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 <a-x> s ^\h*\K--\h* <ret> y gh j P }
}
}
define-command -hidden elm-indent-on-new-line %{
evaluate-commands -draft -itersel %{
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# align to first clause

View File

@ -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 <a-x> s ^\h*//\h* <ret> 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 <a-x> s ^\h*//\h* <ret> y jgh P }
# preserve previous line indent
try %{ execute-keys -draft \; K <a-&> }
# cleanup trailing whitespaces from previous line

View File

@ -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 <a-x> s \h+$ <ret> 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 <a-x> s ^\h*\K///?\h* <ret> 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 <a-&> }
# filter previous line

View File

@ -107,8 +107,6 @@ define-command -hidden go-indent-on-new-line %~
try %{ execute-keys -draft k<a-x> s \h+$ <ret>d }
# align to opening paren of previous line
try %{ execute-keys -draft [( <a-k> \A\([^\n]+\n[^\n]*\n?\z <ret> s \A\(\h*.|.\z <ret> '<a-;>' & }
# copy // comments prefix and following white spaces
try %{ execute-keys -draft <semicolon><c-s>k<a-x> s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
# indent after a switch's case/default statements
try %[ execute-keys -draft k<a-x> <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
# 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 <semicolon><c-s>k<a-x> s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
# Wisely add '}'.
evaluate-commands -save-regs x %[
# Save previous line indent in register x.

View File

@ -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 <a-x> s \h+$ <ret> 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 <a-x> s ^\h*\K/\h* <ret> y gh j P }
}
}
define-command -hidden haml-indent-on-new-line %{
evaluate-commands -draft -itersel %{
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# filter previous line

View File

@ -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 <a-x> s \h+$ <ret> 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 <a-x> s ^\h*\K--\h* <ret> y gh j P }
}
}
define-command -hidden haskell-indent-on-new-line %{
evaluate-commands -draft -itersel %{
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# align to first clause

View File

@ -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 <a-x> s ^\h*\K/\h* <ret> y j p }
}
}
define-command -hidden hbs-indent-on-new-line %{
evaluate-commands -draft -itersel %{
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# filter previous line

View File

@ -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 <a-x>s^\h+$<ret>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<a-x> s ^\h*#\h* <ret> y jgh P }
=
~
define-command -hidden i3-indent-on-new-line %~
evaluate-commands -draft -itersel %=
# preserve previous line indent
try %{ execute-keys -draft <semicolon>K<a-&> }
# indent after lines ending with {

View File

@ -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 <a-x>s^\h+$<ret>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 "(?<!\w)@\w+\b" 0:meta
# Commands
# ‾‾‾‾‾‾‾‾
define-command -hidden java-insert-on-new-line %[
# copy // comments prefix and following white spaces
try %{ execute-keys -draft <semicolon><c-s>k<a-x> s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
]
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<a-x> s \h+$ <ret>d }
# align to opening paren of previous line
try %{ execute-keys -draft [( <a-k> \A\([^\n]+\n[^\n]*\n?\z <ret> s \A\(\h*.|.\z <ret> '<a-;>' & }
# copy // comments prefix and following white spaces
try %{ execute-keys -draft <semicolon><c-s>k<a-x> s ^\h*\K/{2,}\h* <ret> y<c-o>P<esc> }
# indent after a switch's case/default statements
try %[ execute-keys -draft k<a-x> <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
# indent after keywords

View File

@ -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 <a-x> s ^\h*\K/{2,}\h* <ret> y gh j P }
>
>
define-command -hidden javascript-indent-on-new-line %<
evaluate-commands -draft -itersel %<
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# filter previous line

View File

@ -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 <a-x> s ^\h*\K--\h* <ret> y gh j P }
}
}
define-command -hidden moon-indent-on-new-line %{
evaluate-commands -draft -itersel %{
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# filter previous line

View File

@ -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 <semicolon> <a-x> s ^\h+$ <ret> 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 <a-x> s ^\h*#\h* <ret> y jgh P }
}
}
define-command -hidden nim-indent-on-new-line %{
evaluate-commands -draft -itersel %{
# preserve previous line indent
try %{ exec -draft <semicolon> K <a-&> }
# cleanup trailing whitespaces from previous line

View File

@ -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 <semicolon> <a-x> s ^\h+$ <ret> d } }
@ -84,10 +85,15 @@ define-command -hidden ninja-trim-indent %{
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> 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 <a-x> s ^\h*\K--\h* <ret> 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 <a-&> }
# filter previous line

View File

@ -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 <a-x> s ^\h*\K#\h* <ret> y gh j P }
>
>
define-command -hidden nix-indent-on-new-line %<
evaluate-commands -draft -itersel %<
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# filter previous line

View File

@ -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 <a-x>s^\h+$<ret>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 <semicolon><c-s>k<a-x> s ^\h*\K#\h* <ret> y<c-o>P<esc> }
=
~
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<a-x> s \h+$ <ret>d }
# align to opening paren of previous line
try %{ execute-keys -draft [( <a-k> \A\([^\n]+\n[^\n]*\n?\z <ret> s \A\(\h*.|.\z <ret> '<a-;>' & }
# copy # comments prefix and following white spaces
try %{ execute-keys -draft <semicolon><c-s>k<a-x> s ^\h*\K#\h* <ret> y<c-o>P<esc> }
# indent after a switch's case/default statements
try %[ execute-keys -draft k<a-x> <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
# indent after if|else|while|for

View File

@ -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 [^/] <ret> k <a-x> s ^\h*\K(?://|[*][^/])\h* <ret> y gh j P }
try %{ execute-keys -draft s [^/] <ret> k <a-x> s ^\h*\K(?://|[*][^/])\h* <ret> y gh j P
# append " * " on lines starting a multiline /** or /* comment
try %{ execute-keys -draft k <a-x> s ^\h*/[*][* ]? <ret> j gi i <space>*<space> }
>
>
define-command -hidden php-indent-on-new-line %<
evaluate-commands -draft -itersel %<
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# filter previous line
try %{ execute-keys -draft k : php-trim-indent <ret> }
# indent after lines beginning / ending with opener token
try %_ execute-keys -draft k <a-x> <a-k> ^\h*[[{]|[[{]$ <ret> j <a-gt> _
# append " * " on lines starting a multiline /** or /* comment
try %{ execute-keys -draft k <a-x> s ^\h*/[*][* ]? <ret> j gi i <space>*<space> }
# deindent closer token(s) when after cursor
try %_ execute-keys -draft <a-x> <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> _
>

View File

@ -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 <semicolon> <a-x> s ^\h+$ <ret> 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* <ret> y jgh P }
}
}
define-command -hidden pony-indent-on-new-line %{
evaluate-commands -draft -itersel %{
# preserve previous line indent
try %{ execute-keys -draft <space> K <a-&> }
# cleanup trailing whitespaces from previous line
try %{ execute-keys -draft k <a-x> s \h+$ <ret> d }
# copy '//' comment prefix and following white spaces
# try %{ execute-keys -draft k x s ^\h*//\h* <ret> y jgh P }
# indent after line ending with :
try %{ execute-keys -draft <space> k x <a-k> (\b(?:do|try|then|else)|:|=>)$ <ret> j <a-gt> }
# else, end are always de-indented

View File

@ -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 <a-x> s \h+$ <ret> 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 <a-x> s ^\h*\K--\h* <ret> y gh j P }
}
}
define-command -hidden purescript-indent-on-new-line %{
evaluate-commands -draft -itersel %{
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# align to first clause

View File

@ -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 <a-x> s ^\h*\K#\h* <ret> y gh j P }
>
>
define-command -hidden ragel-indent-on-new-line %<
evaluate-commands -draft -itersel %<
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# filter previous line

View File

@ -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 <a-x> s ^\h*\K/{2,}\h* <ret> 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 <a-x> s ^\h*\K/{2,}\h* <ret> y gh j P }
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# filter previous line

View File

@ -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 <a-x> s \h+$ <ret> 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 <a-x> s ^\h*\K#\h* <ret> y gh j P ]
try %{ execute-keys -draft <semicolon><c-s>k<a-x> s ^\h*\K#\h* <ret> y<c-o>P<esc> }
]
]
define-command -hidden scala-indent-on-new-line %[
evaluate-commands -draft -itersel %[
# preserve previous line indent
try %[ execute-keys -draft <semicolon> K <a-&> ]
# filter previous line

View File

@ -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 <a-x> s \h+$ <ret> 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 <a-x> s ^\h*\K#\h* <ret> 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 <a-x> s ^\h*\K#\h* <ret> y gh j P }
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# filter previous line

View File

@ -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 <a-x> s \h+$ <ret> 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 <a-x> s ^\h*\K#\h* <ret> y gh j P }
}
}
define-command -hidden yaml-indent-on-new-line %{
evaluate-commands -draft -itersel %{
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# filter previous line

View File

@ -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 <a-x> s \h+$ <ret> 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 <a-x> s ^\h*\K///?\h* <ret> y gh j P >
>
>
define-command -hidden zig-indent-on-new-line %<
evaluate-commands -draft -itersel %<
# preserve indent level
try %< execute-keys -draft <semicolon> K <a-&> >
try %<
# copy // or /// comments prefix and following whitespace
execute-keys -draft k <a-x> s ^\h*\K///?\h* <ret> y gh j P
# preserve indent level
try %< execute-keys -draft <semicolon> K <a-&> >
> catch %<
# preserve indent level
try %< execute-keys -draft <semicolon> K <a-&> >
# only if we didn't copy a comment
execute-keys -draft <a-x> <a-K> ^\h*// <ret>
# indent after lines ending in {
try %< execute-keys -draft k <a-x> <a-k> \{\h*$ <ret> j <a-gt> >
# deindent closing } when after cursor