Skip to content

Conversation

Konfekt
Copy link
Contributor

@Konfekt Konfekt commented Dec 2, 2024

might require @ElPiloto 's and @rkowal 's approval for copyright and @dkearn 's for the Lua ftplugin; code was extracted from 0

@dkearns
Copy link
Contributor

dkearns commented Dec 2, 2024

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 fold options added to the :syn-regions would also achieve much the same.

@Konfekt
Copy link
Contributor Author

Konfekt commented Dec 3, 2024

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

@ElPiloto
Copy link

ElPiloto commented Dec 3, 2024

👍 but looks like approval no longer needed from me.

@chrisbra
Copy link
Member

chrisbra commented Dec 3, 2024

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?

@Konfekt
Copy link
Contributor Author

Konfekt commented Dec 3, 2024

@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 &foldmethod and invite further implementations, but at least we've something working on every Vim.

@Konfekt
Copy link
Contributor Author

Konfekt commented Dec 3, 2024

This said, generally speaking, aren't &syntax and &foldexpr always two viable solutions? When is one clearly better than the other? For example, Dr Chip's built-in Tex folding uses syntax, whereas the popular vimtex switched to &foldexpr

@Konfekt
Copy link
Contributor Author

Konfekt commented Dec 3, 2024

Well, I found it still to be slow on bigger lua files indeed and now made it only recompute on changes

@chrisbra
Copy link
Member

chrisbra commented Dec 3, 2024

okay thanks. Let me include this now then.

@chrisbra
Copy link
Member

chrisbra commented Dec 3, 2024

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 s:loaded_lua, so resetting &cpo might be a bit too early.

@Konfekt
Copy link
Contributor Author

Konfekt commented Dec 3, 2024

Then it makes perfect sense; I never thought this &cpo dance through

@chrisbra
Copy link
Member

chrisbra commented Dec 3, 2024

okay, I'll squash this in

@Konfekt
Copy link
Contributor Author

Konfekt commented Dec 3, 2024

Oh, I did this

@Konfekt
Copy link
Contributor Author

Konfekt commented Dec 3, 2024

Since there were some other details

@Konfekt
Copy link
Contributor Author

Konfekt commented Dec 3, 2024

But feel free to refine further

@chrisbra
Copy link
Member

chrisbra commented Dec 3, 2024

okay, thanks. I'll merge it now.

@chrisbra chrisbra closed this in fdfcce5 Dec 3, 2024
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.

4 participants