[vim/vim] vim indent plugin: support new class/interface/enum syntaxes (PR #11928)

14 views
Skip to first unread message

lacygoill

unread,
Feb 1, 2023, 7:04:17 AM2/1/23
to vim/vim, Subscribed

Should also make it easier to support/update new syntaxes, by editing only 2 variables, BLOCKS:

const BLOCKS: list<list<string>> = [
    ['if', 'el\%[se]', 'elseif\=', 'en\%[dif]'],
    ['for', 'endfor\='],
    ['wh\%[ile]', 'endw\%[hile]'],
    ['try', 'cat\%[ch]', 'fina\|finally\=', 'endt\%[ry]'],
    ['def', 'enddef'],
    ['fu\%[nction](\@!', 'endf\%[unction]'],
    ['class', 'endclass'],
    ['interface', 'endinterface'],
    ['enum', 'endenum'],
    ['aug\%[roup]\%(\s\+[eE][nN][dD]\)\@!\s\+\S\+', 'aug\%[roup]\s\+[eE][nN][dD]'],
]

And MODIFIERS:

const MODIFIERS: dict<string> = {
    def: ['export', 'static'],
    class: ['export', 'abstract', 'export abstract'],
    interface: ['export'],
}

Also fixes a bug.

Expected:

vim9script
if (
        true)
        && true
    echo
endif

Actual:

vim9script
if (
        true)
&& true
    echo
endif

You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/11928

Commit Summary

  • 13305be support new class/interface/enum syntaxes
  • 13de3bd rename function; add comment
  • 0b01263 fix: wrong indent in multiline bracket block after :if
  • fc04b9b update "Last Change"

File Changes

(3 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11928@github.com>

lacygoill

unread,
Feb 1, 2023, 12:30:36 PM2/1/23
to vim/vim, Push

@lacygoill pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11928/push/12476413930@github.com>

codecov[bot]

unread,
Feb 2, 2023, 8:49:18 AM2/2/23
to vim/vim, Subscribed

Codecov Report

Merging #11928 (da2fc75) into master (fadc02a) will increase coverage by 0.32%.
The diff coverage is n/a.

@@            Coverage Diff             @@

##           master   #11928      +/-   ##

==========================================

+ Coverage   81.94%   82.27%   +0.32%     

==========================================

  Files         160      150      -10     

  Lines      192331   182981    -9350     

  Branches    43306    41370    -1936     

==========================================

- Hits       157613   150554    -7059     

+ Misses      21858    19872    -1986     

+ Partials    12860    12555     -305     
Flag Coverage Δ
huge-clang-none 82.62% <ø> (+0.02%) ⬆️
huge-gcc-testgui 51.58% <ø> (?)
linux 82.27% <ø> (-0.33%) ⬇️
mingw-x64-HUGE ?
mingw-x86-HUGE ?
windows ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/regexp_bt.c 78.52% <0.00%> (-9.09%) ⬇️
src/typval.c 83.19% <0.00%> (-7.19%) ⬇️
src/if_perl.xs 76.41% <0.00%> (-5.79%) ⬇️
src/json.c 77.84% <0.00%> (-5.59%) ⬇️
src/regexp_nfa.c 84.95% <0.00%> (-5.22%) ⬇️
src/libvterm/src/parser.c 55.18% <0.00%> (-4.90%) ⬇️
src/edit.c 82.81% <0.00%> (-3.73%) ⬇️
src/if_tcl.c 81.63% <0.00%> (-3.61%) ⬇️
src/gui.c 69.59% <0.00%> (-3.47%) ⬇️
src/libvterm/src/state.c 33.59% <0.00%> (-3.31%) ⬇️
... and 134 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11928/c1413774549@github.com>

Bram Moolenaar

unread,
Feb 2, 2023, 9:01:17 AM2/2/23
to vim/vim, Subscribed

I have included this, thanks.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11928/c1413792360@github.com>

Bram Moolenaar

unread,
Feb 2, 2023, 9:01:18 AM2/2/23
to vim/vim, Subscribed

Closed #11928.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11928/issue_event/8421550827@github.com>

errael

unread,
Feb 2, 2023, 2:06:06 PM2/2/23
to vim/vim, Subscribed

Using v9.0.1274, which seems to have this in it, if I open new file aa.vim and enter

vim9script

def F1
enddef

class C1
    endclass

Note that endclass is not dedented automatically while typing; but enddef was. I don't know if this is considered a bug.

BTW, if it matters, locally I've got (which points to an up to date repo of github.com/lacygoill/vim9-syntax.git)

err@harmony:~/.vim
$ ls -l import/ syntax/
import/:
total 0M
lrwxrwxrwx 1 err err 46 Sep  7 19:17 vim9Language.vim -> /ref/tools/vim9-syntax/import/vim9Language.vim
lrwxrwxrwx 1 err err 48 Feb  1 08:03 vim9SyntaxUtil.vim -> /ref/tools/vim9-syntax/import/vim9SyntaxUtil.vim

syntax/:
total 0M
lrwxrwxrwx 1 err err 37 May  5  2022 vim.vim -> /ref/tools/vim9-syntax/syntax/vim.vim


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11928/c1414225860@github.com>

lacygoill

unread,
Feb 2, 2023, 2:16:20 PM2/2/23
to vim/vim, Subscribed

There is more work to properly support Vim9 (b:match_words, gf & friends via custom mappings or maybe 'includeexpr').

In any case, this should fix the issue:

diff --git a/runtime/indent/vim.vim b/runtime/indent/vim.vim
index 2cb32372d..f390ad5c2 100644
--- a/runtime/indent/vim.vim
+++ b/runtime/indent/vim.vim
@@ -16,7 +16,7 @@ b:undo_indent = 'setlocal indentkeys< indentexpr<'
 import autoload '../autoload/dist/vimindent.vim'
 
 setlocal indentexpr=vimindent.Expr()
-setlocal indentkeys+==endif,=enddef,=endfu,=endfor,=endwh,=endtry,=},=else,=cat,=finall,=END,0\\
+setlocal indentkeys+==endif,=enddef,=endfu,=endfor,=endwh,=endtry,=endclass,=endinterface,=endenum,=},=else,=cat,=finall,=END,0\\
 execute('setlocal indentkeys+=0=\"\\\ ,0=#\\\ ')
 setlocal indentkeys-=0#
 setlocal indentkeys-=:


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11928/c1414238272@github.com>

errael

unread,
Feb 2, 2023, 2:44:54 PM2/2/23
to vim/vim, Subscribed

Thanks, that does it.

There is more work to properly support Vim9

Yeah, I get it. Since class extends is close to being usable, and this PR is about indent, I thought this might have fallen through the cracks. But I see now that the fix is in vim.vim and not vimindent.vim. Thanks again.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11928/c1414274271@github.com>

Bram Moolenaar

unread,
Feb 2, 2023, 6:04:59 PM2/2/23
to vim/vim, Subscribed


> There is more work to properly support Vim9 (`b:match_words`, `gf` &

> friends via custom mappings or maybe `'includeexpr'`).
>
> In any case, this should fix the issue:
>
> ```diff
> diff --git a/runtime/indent/vim.vim b/runtime/indent/vim.vim
> index 2cb32372d..f390ad5c2 100644
> --- a/runtime/indent/vim.vim
> +++ b/runtime/indent/vim.vim
> @@ -16,7 +16,7 @@ b:undo_indent = 'setlocal indentkeys< indentexpr<'
> import autoload '../autoload/dist/vimindent.vim'
>
> setlocal indentexpr=vimindent.Expr()
> -setlocal indentkeys+==endif,=enddef,=endfu,=endfor,=endwh,=endtry,=},=else,=cat,=finall,=END,0\\
> +setlocal indentkeys+==endif,=enddef,=endfu,=endfor,=endwh,=endtry,=endclass,=endinterface,=endenum,=},=else,=cat,=finall,=END,0\\
> execute('setlocal indentkeys+=0=\"\\\ ,0=#\\\ ')
> setlocal indentkeys-=0#
> setlocal indentkeys-=:
> ```

That makes sense, I'll include this change.

--
In order for something to become clean, something else must become dirty;
but you can get everything dirty without getting anything clean.

/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11928/c1414489221@github.com>

errael

unread,
Feb 6, 2023, 5:04:52 PM2/6/23
to vim/vim, Subscribed

I've done the following locally, since begin/end is so handy. I'm not sure this is how you'd want to do it for release. I was wondering if for class you'd want to visit constructors.

diff --git a/runtime/ftplugin/vim.vim b/runtime/ftplugin/vim.vim
--- a/runtime/ftplugin/vim.vim
+++ b/runtime/ftplugin/vim.vim
@@ -102,6 +102,7 @@
        \ '\<\%(fu\%[nction]\|def\)!\=\s\+\S\+\s*(:\%(\%(^\||\)\s*\)\@<=\<retu\%[rn]\>:\%(\%(^\||\)\s*\)\@<=\<\%(endf\%[unction]\|enddef\)\>,' .
        \ '\<\(wh\%[ile]\|for\)\>:\%(\%(^\||\)\s*\)\@<=\<brea\%[k]\>:\%(\%(^\||\)\s*\)\@<=\<con\%[tinue]\>:\%(\%(^\||\)\s*\)\@<=\<end\(w\%[hile]\|fo\%[r]\)\>,' .
        \ '\<if\>:\%(\%(^\||\)\s*\)\@<=\<el\%[seif]\>:\%(\%(^\||\)\s*\)\@<=\<en\%[dif]\>,' .
+       \ '\<\(class\|interface\|enum\)\>:\<\(endclass\|endinterface\|endenum\)\>,' .
        \ '{:},' .
        \ '\<try\>:\%(\%(^\||\)\s*\)\@<=\<cat\%[ch]\>:\%(\%(^\||\)\s*\)\@<=\<fina\%[lly]\>:\%(\%(^\||\)\s*\)\@<=\<endt\%[ry]\>,' .
        \ '\<aug\%[roup]\s\+\%(END\>\)\@!\S:\<aug\%[roup]\s\+END\>,'


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11928/c1419839775@github.com>

Bram Moolenaar

unread,
Feb 9, 2023, 8:05:30 AM2/9/23
to vim/vim, Subscribed

I would not like "%" to stop at constructors, just jumping from "class" to "endclass" is what I expect.
I also don't like much that it stops at "return" statements when used on "function", but that's a personal preference.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11928/c1424163182@github.com>

errael

unread,
Feb 9, 2023, 10:53:43 AM2/9/23
to vim/vim, Subscribed

I would not like "%" to stop at constructors, just jumping from "class" to "endclass" is what I expect.
I also don't like much that it stops at "return" statements when used on "function", but that's a personal preference.

That's my personal preference as well. I mention it because I've assumed there are some that like it.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11928/c1424417425@github.com>

Reply all
Reply to author
Forward
0 new messages