diff options
| author | Johannes Altmanninger <aclopte@gmail.com> | 2021-04-17 10:17:01 +0200 |
|---|---|---|
| committer | Johannes Altmanninger <aclopte@gmail.com> | 2021-04-17 20:56:23 +0200 |
| commit | 0a9c90fecf21b69c9f9e5205799ec22a6ae215b3 (patch) | |
| tree | cadd11b3089c0c403b5804ecab5e90dea658fde6 /rc/filetype/php.kak | |
| parent | 0264c847420394b5f47b7fb8286f0fb0611fe24d (diff) | |
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.
Diffstat (limited to 'rc/filetype/php.kak')
| -rw-r--r-- | rc/filetype/php.kak | 14 |
1 files changed, 10 insertions, 4 deletions
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 [^/] <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-&> _ > |
