[vim/vim] Correct enum indentation issue #16289 (PR #16293)

36 views
Skip to first unread message

Jim Zhou

unread,
Dec 24, 2024, 11:07:40 AM12/24/24
to vim/vim, Subscribed

Specially handle commas within an enum block to prevent incorrect indentation.

Added constant string STARTS_ENUM to match where enum starts and function CacheEnumBlock to handle IsInside() call.


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

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

Commit Summary

  • 99bafea Correct enum indentation issue #16289

File Changes

(1 file)

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/16293@github.com>

Jim Zhou

unread,
Dec 24, 2024, 11:08:06 AM12/24/24
to vim/vim, Push

@JimZhouZZY pushed 1 commit.

  • 02e5a65 Remove a useless conditional statement


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16293/before/99bafea550b1546e431591d80a56619e15903dab/after/02e5a65ff24666933a5eb68c1d52285b58630cdc@github.com>

Aliaksei Budavei

unread,
Dec 24, 2024, 11:47:40 AM12/24/24
to vim/vim, Subscribed

Don't forget to update runtime/indent/testdir/vim.{in,ok}
tests to test your changes. You can peek at my changeset to
figure out what additional changes are required for CI (also
see this README.txt).

Then, test it locally as follows:

cd runtime/indent
make clean test


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/16293/c2561284466@github.com>

Aliaksei Budavei

unread,
Dec 24, 2024, 11:57:53 AM12/24/24
to vim/vim, Subscribed

I would also consider adding a more complicated test, e.g.:

" START_INDENT
enum Digits
INVALID(v:numbermax),  # The null value.
ZERO(0 * v:numbermin), ONE(2 - 1),
TWO(1 + 1), THREE(9 / 3), FOUR(1 * 4),
FIVE(1 + 2 + 2), SIX(36 / 3 / 2), SEVEN(7), EIGHT(2 * 2 * 2),
NINE(3 + 3 + 3)
const value: number
def new(this.value)
enddef
endenum
" END_INDENT


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/16293/c2561290170@github.com>

Jim Zhou

unread,
Dec 24, 2024, 12:32:41 PM12/24/24
to vim/vim, Push

@JimZhouZZY pushed 1 commit.

  • 37c56ae Place the special handling of the enum block in a more appropriate position.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16293/before/02e5a65ff24666933a5eb68c1d52285b58630cdc/after/37c56aed7f32c7d9e536261559ba7f2539bf74e7@github.com>

Aliaksei Budavei

unread,
Dec 24, 2024, 12:45:11 PM12/24/24
to vim/vim, Subscribed

@zzzyxwvut commented on this pull request.


In runtime/autoload/dist/vimindent.vim:

> @@ -461,7 +465,7 @@ export def Expr(lnum = v:lnum): number # {{{2
             return startindent + shiftwidth()
         endif
     endif
-
+   

Trailing whitespace characters.


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/16293/review/2522147184@github.com>

Aliaksei Budavei

unread,
Dec 24, 2024, 12:45:40 PM12/24/24
to vim/vim, Subscribed

@zzzyxwvut commented on this pull request.


In runtime/autoload/dist/vimindent.vim:

> @@ -588,6 +592,12 @@ export def Expr(lnum = v:lnum): number # {{{2
             return base_ind
         endif
     endif
+ 

Ditto.


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/16293/review/2522147339@github.com>

Aliaksei Budavei

unread,
Dec 24, 2024, 12:45:49 PM12/24/24
to vim/vim, Subscribed

@zzzyxwvut commented on this pull request.


In runtime/autoload/dist/vimindent.vim:

> @@ -588,6 +592,12 @@ export def Expr(lnum = v:lnum): number # {{{2
             return base_ind
         endif
     endif
+ 
+    if line_A.text =~ STARTS_ENUM
+        line_A->CacheEnumBlock()
+    elseif line_A.lnum->IsInside('EnumBlock')
+        return shiftwidth() 

Ditto.


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/16293/review/2522147405@github.com>

Aliaksei Budavei

unread,
Dec 24, 2024, 12:55:30 PM12/24/24
to vim/vim, Subscribed

@zzzyxwvut commented on this pull request.


In runtime/autoload/dist/vimindent.vim:

> @@ -314,6 +314,10 @@ const STARTS_CURLY_BLOCK: string = '\%('
 
 const STARTS_FUNCTION: string = $'^\s*\%({MODIFIERS.def}\)\=def\>!\=\s\@='
 
+# STARTS_ENUM {{{3
+
+const STARTS_ENUM: string = $'^\s*enum\>\s*'

Do you really need string interpolation 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/16293/review/2522151658@github.com>

Aliaksei Budavei

unread,
Dec 24, 2024, 12:56:18 PM12/24/24
to vim/vim, Subscribed

@zzzyxwvut commented on this pull request.


In runtime/autoload/dist/vimindent.vim:

> @@ -839,6 +849,25 @@ def CacheBracketBlock(line_A: dict<any>) # {{{2
     RegisterCacheInvalidation()
 enddef
 
+def CacheEnumBlock(line_A: dict<any>) # {{{2
+    if line_A.text !~ '^\s*enum\s'
+        return
+    endif
+
+    var pos: list<number> = getcurpos()
+    var startlnum: number = line_A.lnum + 1
+    var endlnum: number = search($'^\s*endenum$', 'nW') - 1

Do you really need string interpolation 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/16293/review/2522151950@github.com>

Jim Zhou

unread,
Dec 24, 2024, 12:59:38 PM12/24/24
to vim/vim, Push

@JimZhouZZY pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16293/before/37c56aed7f32c7d9e536261559ba7f2539bf74e7/after/0202aa87e3dfea64579fb42f2ca9e16c67defcb5@github.com>

Aliaksei Budavei

unread,
Dec 24, 2024, 1:06:11 PM12/24/24
to vim/vim, Subscribed

@zzzyxwvut commented on this pull request.


In runtime/autoload/dist/vimindent.vim:

> @@ -588,6 +592,12 @@ export def Expr(lnum = v:lnum): number # {{{2
             return base_ind
         endif
     endif
+ 
+    if line_A.text =~ STARTS_ENUM
⬇️ Suggested change
-    if line_A.text =~ STARTS_ENUM
+    if line_A.text =~# STARTS_ENUM


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/16293/review/2522156074@github.com>

Aliaksei Budavei

unread,
Dec 24, 2024, 1:06:25 PM12/24/24
to vim/vim, Subscribed

@zzzyxwvut commented on this pull request.


In runtime/autoload/dist/vimindent.vim:

> @@ -839,6 +849,25 @@ def CacheBracketBlock(line_A: dict<any>) # {{{2
     RegisterCacheInvalidation()
 enddef
 
+def CacheEnumBlock(line_A: dict<any>) # {{{2
+    if line_A.text !~ '^\s*enum\s'
⬇️ Suggested change
-    if line_A.text !~ '^\s*enum\s'
+    if line_A.text !~# '^\s*enum\s'


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/16293/review/2522156146@github.com>

Jim Zhou

unread,
Dec 24, 2024, 1:06:39 PM12/24/24
to vim/vim, Push

@JimZhouZZY pushed 1 commit.

  • 8737bb8 Modified test as @zzzyxwvut suggested

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16293/before/0202aa87e3dfea64579fb42f2ca9e16c67defcb5/after/8737bb883d9486922caccb653ca98494bb28d196@github.com>

Jim Zhou

unread,
Dec 24, 2024, 1:13:29 PM12/24/24
to vim/vim, Push

@JimZhouZZY pushed 1 commit.

  • 0ce43aa Remove trailing whitespace characters.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16293/before/8737bb883d9486922caccb653ca98494bb28d196/after/0ce43aab4605b70c68692b4535d472e88b614dd1@github.com>

Jim Zhou

unread,
Dec 24, 2024, 1:14:45 PM12/24/24
to vim/vim, Subscribed

@JimZhouZZY commented on this pull request.


In runtime/autoload/dist/vimindent.vim:

> @@ -461,7 +465,7 @@ export def Expr(lnum = v:lnum): number # {{{2
             return startindent + shiftwidth()
         endif
     endif
-
+   

Removed. Thanks!


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/16293/review/2522159464@github.com>

Aliaksei Budavei

unread,
Dec 24, 2024, 1:31:16 PM12/24/24
to vim/vim, Subscribed

@zzzyxwvut commented on this pull request.


In runtime/autoload/dist/vimindent.vim:

> @@ -839,6 +849,25 @@ def CacheBracketBlock(line_A: dict<any>) # {{{2
     RegisterCacheInvalidation()
 enddef
 
+def CacheEnumBlock(line_A: dict<any>) # {{{2
+    if line_A.text !~ '^\s*enum\s'
+        return
+    endif
+
+    var pos: list<number> = getcurpos()
+    var startlnum: number = line_A.lnum + 1
+    var endlnum: number = search($'^\s*endenum$', 'nW') - 1

Comments can follow endenums, so '^\C\s*endenum\>'; else,
you run the risk of matching some unrelated endenum.


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/16293/review/2522165590@github.com>

Aliaksei Budavei

unread,
Dec 24, 2024, 3:01:05 PM12/24/24
to vim/vim, Subscribed

@zzzyxwvut commented on this pull request.


In runtime/autoload/dist/vimindent.vim:

> @@ -314,6 +314,10 @@ const STARTS_CURLY_BLOCK: string = '\%('
 
 const STARTS_FUNCTION: string = $'^\s*\%({MODIFIERS.def}\)\=def\>!\=\s\@='
 
+# STARTS_ENUM {{{3
+
+const STARTS_ENUM: string = $'^\s*enum\>\s*'

This pattern should also account for export.


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/16293/review/2522195696@github.com>

Aliaksei Budavei

unread,
Dec 24, 2024, 3:29:31 PM12/24/24
to vim/vim, Subscribed

The proposed changes work for reformatting the whole enum
block and as long as the indent cache is valid. As before,
typing in enum values and keeping them aligned requires one
i_Ctrl-d stroke after entering the second value followed by
a comma.


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/16293/c2561390583@github.com>

Jim Zhou

unread,
Dec 24, 2024, 7:03:47 PM12/24/24
to vim/vim, Subscribed

The proposed changes work for reformatting the whole enum
block and as long as the indent cache is valid. As before,
typing in enum values and keeping them aligned requires one
i_Ctrl-d stroke after entering the second value followed by
a comma.

That's indeed a problem, I'll take some time finding a better solution.


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/16293/c2561497654@github.com>

Jim Zhou

unread,
Dec 25, 2024, 3:02:54 AM12/25/24
to vim/vim, Push

@JimZhouZZY pushed 1 commit.

  • f0549fe - Update test to a more complex one.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16293/before/0ce43aab4605b70c68692b4535d472e88b614dd1/after/f0549fe57d693864b2a93a94dce9cf53ca7329e5@github.com>

Jim Zhou

unread,
Dec 25, 2024, 3:06:18 AM12/25/24
to vim/vim, Push

@JimZhouZZY pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16293/before/f0549fe57d693864b2a93a94dce9cf53ca7329e5/after/96230deb388445cd810ede6e58357126c2778e9a@github.com>

Jim Zhou

unread,
Dec 25, 2024, 3:24:22 AM12/25/24
to vim/vim, Push

@JimZhouZZY pushed 1 commit.

  • c418cd3 Use buffer vriable instead of global variable

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16293/before/96230deb388445cd810ede6e58357126c2778e9a/after/c418cd32af20db836dc9bc4e14fd225cc4413b89@github.com>

Jim Zhou

unread,
Dec 25, 2024, 6:47:03 AM12/25/24
to vim/vim, Push

@JimZhouZZY pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16293/before/c418cd32af20db836dc9bc4e14fd225cc4413b89/after/0d4107ef749210c18940b8eacc749a7d2f6ff2b3@github.com>

Jim Zhou

unread,
Dec 25, 2024, 7:05:05 AM12/25/24
to vim/vim, Push

@JimZhouZZY pushed 1 commit.

  • 901c78c Merge branch 'master' into master

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16293/before/0d4107ef749210c18940b8eacc749a7d2f6ff2b3/after/901c78c0fd84437eb2b57c66d76c175220973dc9@github.com>

Jim Zhou

unread,
Dec 25, 2024, 7:27:47 AM12/25/24
to vim/vim, Subscribed

@JimZhouZZY commented on this pull request.


In runtime/autoload/dist/vimindent.vim:

> @@ -839,6 +849,25 @@ def CacheBracketBlock(line_A: dict<any>) # {{{2
     RegisterCacheInvalidation()
 enddef
 
+def CacheEnumBlock(line_A: dict<any>) # {{{2
+    if line_A.text !~ '^\s*enum\s'
+        return
+    endif
+
+    var pos: list<number> = getcurpos()
+    var startlnum: number = line_A.lnum + 1
+    var endlnum: number = search($'^\s*endenum$', 'nW') - 1

I am not very familiar with Vim’s regular expressions. Thank you for the guidance. I've corrected it.


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/16293/review/2522572247@github.com>

Jim Zhou

unread,
Dec 25, 2024, 7:31:19 AM12/25/24
to vim/vim, Push

@JimZhouZZY 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/16293/before/901c78c0fd84437eb2b57c66d76c175220973dc9/after/c0f25c1aa0642a1c367d700c98c30415fc33a02f@github.com>

Jim Zhou

unread,
Dec 25, 2024, 7:42:54 AM12/25/24
to vim/vim, Subscribed

I believe this is a simple solution to the issue. However, since it is limited to enum blocks and partially overlaps with the logic for indenting bracket blocks, further refactoring may be needed in the future to improve the code.


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/16293/c2561875301@github.com>

Aliaksei Budavei

unread,
Dec 25, 2024, 3:59:36 PM12/25/24
to vim/vim, Subscribed

@zzzyxwvut commented on this pull request.


In runtime/autoload/dist/vimindent.vim:

> +        var enum_pos = search('^\C\s*enum\>\s', 'bnW')
+        var endenum_pos = search('^\C\s*endenum\>\s', 'bnW')
⬇️ Suggested change
-        var enum_pos = search('^\C\s*enum\>\s', 'bnW')
-        var endenum_pos = search('^\C\s*endenum\>\s', 'bnW')
+        var enum_pos = search('^\C\s*\%(export\s\)\=\s*enum\s\+\S\+', 'bnW')
+        var endenum_pos = search('^\C\s*endenum\>', 'bnW')

The flag combination for search() can be tricky; the above
code seems to follow in PrevCodeLine()'s footsteps. If the
cursor is inside EnumBlock, shouldn't it seek forward for
endenum and backward for enum? Will it work when there is
more than one enum definition in the same file?


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/16293/review/2522660586@github.com>

Aliaksei Budavei

unread,
Dec 25, 2024, 4:00:55 PM12/25/24
to vim/vim, Subscribed

@zzzyxwvut commented on this pull request.


In runtime/autoload/dist/vimindent.vim:

> @@ -1078,6 +1052,24 @@ def ContinuesBelowBracketBlock( # {{{3
 enddef
 
 def IsInside(lnum: number, syntax: string): bool # {{{3
+    if syntax == 'EnumBlock'
+        var cur_pos = getpos('.')
+        cursor(lnum, 1)
+
+        var enum_pos = search('^\C\s*enum\>\s', 'bnW')
+        var endenum_pos = search('^\C\s*endenum\>\s', 'bnW')
+        

Trailing whitespace characters.


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/16293/review/2522660668@github.com>

Aliaksei Budavei

unread,
Dec 25, 2024, 4:01:53 PM12/25/24
to vim/vim, Subscribed

@zzzyxwvut commented on this pull request.


In runtime/indent/testdir/vim.in:

>  def new(this.value)
+return this.value
⬇️ Suggested change
-def new(this.value)
-return this.value
+def new(value: number)
+this.value = value

This is a constructor definition (:help E1365).


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/16293/review/2522660736@github.com>

Aliaksei Budavei

unread,
Dec 25, 2024, 4:02:05 PM12/25/24
to vim/vim, Subscribed

@zzzyxwvut commented on this pull request.


In runtime/indent/testdir/vim.ok:

>      def new(this.value)
+	return this.value
⬇️ Suggested change
-    def new(this.value)
-	return this.value
+    def new(value: number)
+	this.value = value

This is a constructor definition (:help E1365).


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/16293/review/2522660742@github.com>

Aliaksei Budavei

unread,
Dec 25, 2024, 5:02:55 PM12/25/24
to vim/vim, Subscribed

The latest patch version correctly aligns enum values when
they are typed and when they are formatted. Thank you.

It would be nice if some future patch tried a bit harder at
recovering indentation for value arguments split across two
or more lines when they are typed. For example:

vim9script

enum RGB
    RED(
        0xff0000,
        0),
    GREEN(
        0x008000,
        0),
    BLUE(
        0x0000ff,
        0)

    const value: number
    var other: any

    def new(value: number, other: any)
        this.value = value
        this.other = other
    enddef
endenum


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/16293/c2562008738@github.com>

h_east

unread,
Dec 25, 2024, 5:36:40 PM12/25/24
to vim/vim, Subscribed

@h-east commented on this pull request.


In runtime/indent/testdir/vim.in:

>  def new(this.value)
+return this.value

@zzzyxwvut def new(this.value) is a valid constructor syntax. However, neither return nor assignment is required.
See :h E1390.


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/16293/review/2522667615@github.com>

Jim Zhou

unread,
Dec 25, 2024, 11:40:35 PM12/25/24
to vim/vim, Push

@JimZhouZZY 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/16293/before/c0f25c1aa0642a1c367d700c98c30415fc33a02f/after/9a3c583898372bf4ac8a047f1d438857cfa7d91c@github.com>

Jim Zhou

unread,
Dec 25, 2024, 11:43:20 PM12/25/24
to vim/vim, Subscribed

@JimZhouZZY commented on this pull request.


In runtime/indent/testdir/vim.ok:

>      def new(this.value)
+	return this.value

Modified. Thank you for pointing that out.


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/16293/review/2522786870@github.com>

Jim Zhou

unread,
Dec 25, 2024, 11:44:29 PM12/25/24
to vim/vim, Push

@JimZhouZZY pushed 1 commit.

  • 70f8645 Update runtime/indent/testdir/vim.ok


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16293/before/9a3c583898372bf4ac8a047f1d438857cfa7d91c/after/70f8645cce50676559d03902d96dd87e5181c712@github.com>

Jim Zhou

unread,
Dec 25, 2024, 11:47:43 PM12/25/24
to vim/vim, Push

@JimZhouZZY pushed 1 commit.

  • eb0b5cc Remove trailing whitespace characters

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16293/before/70f8645cce50676559d03902d96dd87e5181c712/after/eb0b5cc4c568c4a51383b5b63c0e71a0fd179da6@github.com>

Jim Zhou

unread,
Dec 25, 2024, 11:50:11 PM12/25/24
to vim/vim, Subscribed

@JimZhouZZY commented on this pull request.


In runtime/autoload/dist/vimindent.vim:

> @@ -1078,6 +1052,24 @@ def ContinuesBelowBracketBlock( # {{{3
 enddef
 
 def IsInside(lnum: number, syntax: string): bool # {{{3
+    if syntax == 'EnumBlock'
+        var cur_pos = getpos('.')
+        cursor(lnum, 1)
+
+        var enum_pos = search('^\C\s*enum\>\s', 'bnW')
+        var endenum_pos = search('^\C\s*endenum\>\s', 'bnW')
+        

Removed for consistency.


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/16293/review/2522790792@github.com>

Jim Zhou

unread,
Dec 26, 2024, 12:10:30 AM12/26/24
to vim/vim, Subscribed

@JimZhouZZY commented on this pull request.


In runtime/autoload/dist/vimindent.vim:

> +        var enum_pos = search('^\C\s*enum\>\s', 'bnW')
+        var endenum_pos = search('^\C\s*endenum\>\s', 'bnW')

For the export enum case I think we should also map 'enum' with 'export' modifier. It is previously uncovered.

--- a/runtime/autoload/dist/vimindent.vim
+++ b/runtime/autoload/dist/vimindent.vim
@@ -172,6 +172,7 @@ const MODIFIERS: dict<string> = {
     def: ['export', 'static'],
     class: ['export', 'abstract', 'export abstract'],
     interface: ['export'],
+    enum: ['export'],
 }


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/16293/review/2522800822@github.com>

Jim Zhou

unread,
Dec 26, 2024, 12:38:33 AM12/26/24
to vim/vim, Subscribed

@JimZhouZZY commented on this pull request.


In runtime/autoload/dist/vimindent.vim:

> +        var enum_pos = search('^\C\s*enum\>\s', 'bnW')
+        var endenum_pos = search('^\C\s*endenum\>\s', 'bnW')

If the
cursor is inside EnumBlock, shouldn't it seek forward for
endenum and backward for enum?

No. This logic may fail. Consider a case

enum Color
    Red,
    Green,
    Blue
endenom                  #         <-- Missed

var foo: number = 1 #         <-- This line may fail

enum Subject           #         <-- Missed
    Math,
    Physics
endenum

In this case, If we seek for enum backward and endenum forward from the marked line, we might miss the endenum right above and the enum right below. As a result, the function could incorrectly conclude that the marked line is inside an EnumBlock.


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/16293/review/2522815245@github.com>

Jim Zhou

unread,
Dec 26, 2024, 12:41:49 AM12/26/24
to vim/vim, Push

@JimZhouZZY pushed 1 commit.

  • 8b01a81 Update combination for search()


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16293/before/eb0b5cc4c568c4a51383b5b63c0e71a0fd179da6/after/8b01a812a189692290471917a77a3e30809c2bd5@github.com>

Jim Zhou

unread,
Dec 26, 2024, 12:51:10 AM12/26/24
to vim/vim, Push

@JimZhouZZY pushed 1 commit.

  • 11b5e3b add modifier DYLD_LIBRARY_PATH=/opt/homebrew/opt/pyt...@3.13/Frameworks/Python.framework/Versions/3.13/lib:

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16293/before/8b01a812a189692290471917a77a3e30809c2bd5/after/11b5e3be410fd6b7b2f318ec3086a679c5528808@github.com>

Jim Zhou

unread,
Dec 26, 2024, 12:57:54 AM12/26/24
to vim/vim, Push

@JimZhouZZY pushed 1 commit.

  • e78dd1e add '\s' back to search endenum

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16293/before/11b5e3be410fd6b7b2f318ec3086a679c5528808/after/e78dd1ecaa60a28e2d2d29559742bb4eacdc6fac@github.com>

Jim Zhou

unread,
Dec 26, 2024, 1:15:53 AM12/26/24
to vim/vim, Subscribed

Updated vim.in and vim.out as @zzzyxwvut suggested.
Updated flag combination to search export enum (as @zzzyxwvut suggested) and MODIFIER to support export enum usage.


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/16293/c2562199832@github.com>

h_east

unread,
Dec 26, 2024, 2:35:42 AM12/26/24
to vim/vim, Subscribed

@h-east commented on this pull request.


In runtime/indent/testdir/vim.ok:

>      def new(this.value)
+	return this.value

@JimZhouZZY #16293 (comment)


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/16293/review/2522903574@github.com>

Jim Zhou

unread,
Dec 26, 2024, 2:55:05 AM12/26/24
to vim/vim, Push

@JimZhouZZY pushed 1 commit.

  • 0a1f940 Corect search and compare logic


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16293/before/e78dd1ecaa60a28e2d2d29559742bb4eacdc6fac/after/0a1f940df9a32877b2468c4f164269f4a7db3702@github.com>

Jim Zhou

unread,
Dec 26, 2024, 3:07:25 AM12/26/24
to vim/vim, Subscribed

@JimZhouZZY commented on this pull request.


In runtime/autoload/dist/vimindent.vim:

> +        var enum_pos = search('^\C\s*enum\>\s', 'bnW')
+        var endenum_pos = search('^\C\s*endenum\>\s', 'bnW')

I just noticed that I did make a mistake in the comparison expression.

(I thought the return value when searching backward was relative to the current position… Bruh…)

Thank you again for making me rethink.


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/16293/review/2522930767@github.com>

Christian Brabandt

unread,
Dec 26, 2024, 4:26:41 AM12/26/24
to vim/vim, Subscribed

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/16293/c2562360248@github.com>

Christian Brabandt

unread,
Dec 26, 2024, 4:39:15 AM12/26/24
to vim/vim, Subscribed

Closed #16293 via 6d2efd4.


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/16293/issue_event/15764607789@github.com>

Aliaksei Budavei

unread,
Dec 26, 2024, 12:27:40 PM12/26/24
to vim/vim, Subscribed

@zzzyxwvut commented on this pull request.


In runtime/indent/testdir/vim.in:

>  def new(this.value)
+return this.value

The suggested test had made use of that syntax. However,
with a newer commit, additional indentation was introduced
for testing with a return this.value statement; and return
with a value is malformed syntax for constructors. In order
to keep that indentation and use valid syntax, the above
suggestion was offered.

Otherwise, constructors equally support shorthand assignment
and/or regular parameters, as well as returns with no value.

For example,

vim9script

enum Test
    INSTANCE(1260, "twelve hundred and threescore", true)

    const number: number
    const string: string

    def new(this.number, string: string, _)
        if strlen(string) < 24
            this.string = string
        else
            return
        endif
    enddef
endenum


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/16293/review/2523367674@github.com>

Aliaksei Budavei

unread,
Dec 26, 2024, 5:45:14 PM12/26/24
to vim/vim, Subscribed

@zzzyxwvut commented on this pull request.


In runtime/autoload/dist/vimindent.vim:

> +        var enum_pos = search('^\C\s*enum\>\s', 'bnW')
+        var endenum_pos = search('^\C\s*endenum\>\s', 'bnW')

Fair enough. It escaped my notice that the cursor is only
moved once, hence the need to search in one direction.

There is still some room for improvement.

We can do better by avoiding the second lookup as soon as it
is known that there is no enum above. It is also worth the
effort to verify that the found enum and/or endenum line is
not the current line (remembering about NonCommentedMatch's
timeouts); otherwise, to reject this line for the related
indentation. See #16310.


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/16293/review/2523524358@github.com>

Reply all
Reply to author
Forward
0 new messages