-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
add optional lua function folding #16151
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
Conversation
might require @ElPiloto 's approval for copyright and @dkearn 's for the Lua ftplugin; code was extracted from [0] [0]: https://github.com/ElPiloto/Lua-Omni-Vim-Completion/blob/7044c7010d4e6f59da60704a4a8e2118af7e973b/ftplugin/lua_omni.lua#L661
Thanks. I'm not opposed to it in principle but I wonder how many people, even those working with Lua, build Vim with the Lua interface? It should probably be ported to one of the Vim scripts in the future, if not now. The syntax file looks like a few |
Yes, I agree. I was just delighted to have found a starting point here, but wondered as well if Vimscript would not be the better tool for this job. Here it is |
👍 but looks like approval no longer needed from me. |
I am wondering if a foldexpression is really a recommended approach compared with proper syntax folding? I think the fold-expression may cause signifcant lag when used with large files, no? Wouldn't syntax folding be the prefered way here? |
@chrisbra I suppose so too, I am not sure which is faster. For me this works very well, but I'm also using fastfold to avoid unnecessary recomputes (as the more direct approach failed. I am fine with any |
This said, generally speaking, aren't |
Well, I found it still to be slow on bigger lua files indeed and now made it only recompute on changes |
okay thanks. Let me include this now then. |
Actually I have to take this back. Does the following patch make sense? diff --git a/runtime/ftplugin/lua.vim b/runtime/ftplugin/lua.vim
index 8a1e86db6..15497841f 100644
--- a/runtime/ftplugin/lua.vim
+++ b/runtime/ftplugin/lua.vim
@@ -5,7 +5,7 @@
" Contributor: Dorai Sitaram <ds26@gte.com>
" C.D. MacEachern <craig.daniel.maceachern@gmail.com>
" Tyler Miller <tmillr@proton.me>
-" Last Change: 2024 Jan 14
+" Last Change: 2024 Dec 03
if exists("b:did_ftplugin")
finish
@@ -55,11 +55,13 @@ if has("folding") && get(g:, "lua_folding", 0)
let b:undo_ftplugin ..= "|setl foldexpr< foldmethod< | unlet b:lua_lasttick b:lua_foldlists"
endif
-let &cpo = s:cpo_save
-unlet s:cpo_save
" The rest of the file needs to be :sourced only once per Vim session
-if exists('s:loaded_lua') || &cp | finish | endif
+if exists('s:loaded_lua') || &cp
+ let &cpo = s:cpo_save
+ unlet s:cpo_save
+ finish
+endif
let s:loaded_lua = 1
" From https://github.com/ElPiloto/Lua-Omni-Vim-Completion/blob/7044c7010d4e6f59da60704a4a8e2118af7e973b/ftplugin/lua_omni.lua#L715C1-L738C4
@@ -106,4 +108,7 @@ function! LuaFold(lnum) abort
return len(lua_foldlists[a:lnum-1])
endfunction
+let &cpo = s:cpo_save
+unlet s:cpo_save
+
" vim: nowrap sw=2 sts=2 ts=8 noet: The reasoning is, we are still using line-continuation lines after the test for |
Then it makes perfect sense; I never thought this |
okay, I'll squash this in |
Oh, I did this |
Since there were some other details |
But feel free to refine further |
okay, thanks. I'll merge it now. |
closes: vim/vim#16151 vim/vim@fdfcce5 Co-authored-by: Enno <Konfekt@users.noreply.github.com>
might require @ElPiloto 's and @rkowal 's approval for copyright and @dkearn 's for the Lua ftplugin; code was extracted from 0