Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make indentexpr evaluate from older vim scripts #14936

Closed
wants to merge 1 commit into from

Conversation

smemsh
Copy link

@smemsh smemsh commented Jun 7, 2024

Older scripts have a problem with recent changes to indentexpr for vim9, they will see it as undefined variable E121. Patch avoids the error in vim8 script as mentioned by @monkoose in #14111 (comment)

Fixes #14111

@chrisbra
Copy link
Member

chrisbra commented Jun 9, 2024

Hm, I suppose if we make this change, we also don't need the import statement anymore. @yegappan @dkearns what is your opinion on this?

)

Needed for 'indentexpr' to evaluate correctly outside vim9 context, ie
with older scripts.  Whereto, it will be an undefined variable,
demonstrate with ':echo vimindent.Expr()' -> E121: Undefined variable:
vimindent
@smemsh smemsh force-pushed the indentexpr-oldscripts-fix branch from 929e0f2 to a693fa0 Compare June 10, 2024 04:53
@smemsh
Copy link
Author

smemsh commented Jun 10, 2024

ok, removed the import line.

@vim-ml
Copy link

vim-ml commented Jun 10, 2024 via email

@chrisbra
Copy link
Member

so you want those changes because? Is this just because you need to manually call the &indentexpr?

@dkearns
Copy link
Contributor

dkearns commented Jun 10, 2024

There should probably be a builtin function to evaluate the 'indentexpr' for a given line, like cindent() and lispindent().

@smemsh
Copy link
Author

smemsh commented Jun 10, 2024

so you want those changes because? Is this just because you need to manually call the &indentexpr

the changes are so the plugin doesn't break with E121, it's the vim-stabs mentioned in the issue, which had been working ok until I upgraded a vim8 to 9.1. I could carry a patch to vim-stabs, or I could carry a patch in vim but if it benefits anyone else and seems like better not to break vim8 scripts, then why should the patch not go in?

these reference exist:

 $ grep -sr indentexpr plugin
plugin/stabs.vim:       if &expandtab || !(&autoindent || &indentexpr || &cindent)
plugin/stabs.vim:               if &indentexpr != ''
plugin/stabs.vim:                       sandbox exe 'let inda='.&indentexpr
plugin/stabs.vim:       let checkalign = ( &expandtab || !(&autoindent || &indentexpr || &cindent))

don't know how to do anything more complicated with the patch, just cherry-picked the fix mentioned in the linked issue, because it fixed my problem. hope that it can be fixed one way or another, so older scripts don't get undefined error.

@jessepav
Copy link
Contributor

so you want those changes because? Is this just because you need to manually call the &indentexpr?

To chime in with my use case:

I've been running with a patch in my tree that exposes all vim9script indentexprs at the global scope, because I have a mapping that toggles between the standard indentexpr and a custom, minimal indentation mode, and it needs to stash away the buffer's current indentexpr so it can restore it later.

@chrisbra
Copy link
Member

Hm, it seems like those autoloaded functions are automatically translated into autoloadable form, in this case like dist#vimindent#Expr(). One also cannot use function() to refer to those autoloaded vim9 functions, may be we should make this work instead, so that you can save and restore it using function()?

@smemsh
Copy link
Author

smemsh commented Jul 12, 2024

@chrisbra is this patch useful in the meantime to fix vim8 users, before a more complete change can be made, or should the PR be closed?

@chrisbra
Copy link
Member

I have another idea how to fix this, probably doesn't matter, but I wanted to keep the import and didn't want to have to use the autoloaded name. Let's see how this works for you.

@chrisbra chrisbra closed this in cb79288 Jul 12, 2024
@smemsh
Copy link
Author

smemsh commented Jul 13, 2024

Let's see how this works for you

solves my issue afaict; thanks.

@smemsh smemsh deleted the indentexpr-oldscripts-fix branch August 31, 2024 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vimindent variable is not defined
5 participants