Use Vim 9 script function for indentexpr?

13 views
Skip to first unread message

Lifepillar

unread,
Aug 10, 2022, 4:25:09 PM8/10/22
to vim...@googlegroups.com
The following silly indent works as expected (of course):

function! FooIndent()
return indent(v:lnum - 1) + 2
endfunction

setlocal indentexpr=FooIndent()

However, a Vim 9 script function does not seem to be called:

vim9script

def BarIndent()
echomsg "BarIndent called"
return indent(v:lnum - 1) + 4
enddef

setlocal indentexpr=BarIndent()

Am I doing anything wrong?

Life.


Lifepillar

unread,
Aug 11, 2022, 4:37:05 AM8/11/22
to vim...@googlegroups.com
On 2022-08-10, Lifepillar <lifep...@lifepillar.me> wrote:
> However, a Vim 9 script function does not seem to be called:
>
> vim9script
>
> def BarIndent()
> echomsg "BarIndent called"
> return indent(v:lnum - 1) + 4
> enddef
>
> setlocal indentexpr=BarIndent()
>
> Am I doing anything wrong?

Obviously, I do: the correct signature for BarIndent() is:

def BarIndent(): number

Life.

Reply all
Reply to author
Forward
0 new messages