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

Verbatim is copied once for every variant #72

Open
romainl opened this issue Mar 15, 2023 · 3 comments
Open

Verbatim is copied once for every variant #72

romainl opened this issue Mar 15, 2023 · 3 comments

Comments

@romainl
Copy link

romainl commented Mar 15, 2023

Hello, in romainl/vim-malotru, I have a short "verbatim" block that forcibly sets &fillchars.

Today I was trying to make that block less intrusive, which involved making a backup of the existing &fillchars value, when I noticed that the block was copied for every variant (explicit or, in my case, implicit):

It means that the code in the block is executed at least 2 times: a first time because it is at root of the file and a second time as part of the contextually relevant variant. It wasn't such an issue when the block only had one :set line because it was imperceptible but, now that I am defining variables and adding conditionals and such, it makes things more complicated than they should be.

For reference, this is the first iteration of the new code:

verbatim
let g:malotru_save_fillchars = &fillchars
echom g:malotru_save_fillchars
set fillchars+=vert:│
augroup malotru
autocmd!
autocmd ColorSchemePre * let &fillchars = get(g:, 'malotru_save_fillchars', &fillchars)
augroup END
endverbatim

where I save the current &fillchars before changing it to the desired value. Because the code is executed twice, g:malotru_save_fillchars is defined a second time with the customized &fillchars, which makes resetting impossible.

Now, I could add more checks but a) that means more fragility and complexity, and b) the current behavior is quite unintuitive.

@lifepillar
Copy link
Owner

Does it work for you if you move the verbatim block towards the top of the file, before the first Variant and Background directive, in what the help file calls the “global section” (see :help colortemplate-structure?

@lifepillar
Copy link
Owner

lifepillar commented Mar 18, 2023

You've put the block in the scope of Variant: gui 256 16: that is why it appears in every variant. Either put it at the top, as suggested above, or add Variant: gui before it to limit the scope to the GUI variant (whose statements are executed unconditionally). I agree that this is not particularly intuitive, though.

For Colortemplate v3 I plan to allow only one optional verbatim section that always appears at the beginning of a color scheme. That, combined with “discriminators”, which is a new feature, covers all the cases I can think of.

Unless there is a specific reason why you would want to execute arbitrary statements after the highlight groups have been defined.

@romainl
Copy link
Author

romainl commented Mar 18, 2023

Thank you, I will experiment with that and report back.

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

No branches or pull requests

2 participants