Folding will be copied if it's reproducible. If you're using marker
, indent
, syntax
or expr
folding methods, it should be reproducible automatically.
If you're using manual
, well, it means your template expander plugin will need to interpret some information and use it to fold manually.
I never though about it, but I guess it should be possible to register such a behaviour in my fork of mu-template. In it I can register post-expansion hooks -- that I mainly use to add missing import/include statements. If in that hooks we create manual folds. It should work. The tricky part would be the extraction of the final line numbers to call :l1,l2fold
.
Something like the following will work in simple cases -- if you start to mix this with other hooks (to automate the inclusion of headers for instance), it'll quite likely require more wiring.
MuT: let s:fold_start = s:Line()
for (auto&& <+e+> : <+container+>) {
<+code+>
}
MuT: let s:fold_end = s:Line() - 1
VimL: call s:AddPostExpandCallback('execute(s:fold_start.",".s:fold_end."fold")')
Regarding the syntax used here.
<+
and +>
delimit placeholders. Mu-template will try to evaluate it's content, otherwise they are inserted as placeholders
- lines starting with
:VimL
are interpreted as Vim commands (that get interpreted with the :execute
command)
- lines starting with
:MuT
are interpreted by mu-template engine, I use them to conditionally decide what to do, in this is case to define a variable that'll get automatically undefined at the end of the expansion.
- all the
s:
functions are helper functions already implemented in mu-template that we can use to define more complex template/snippets: s:Line()
returns the line number where the current line in the template line will be actually inserted/expanded ; s:AddPostExpandCallback()
registers a hook that'll get executed after the expansion has been completed.
- otherwise, the text we type is directly inserted when the template file is expanded.