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

Don't force minlines in syntax/html.vim #14071

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Cheaterman
Copy link

No description provided.

@chrisbra
Copy link
Member

10 doesn't sound particular bad. So why do you want to change it?

@Cheaterman
Copy link
Author

Cheaterman commented Feb 21, 2024

Because it doesn't sync? I have to :syn sync fromstart all the time when editing HTML...

How is 10 "not particularly bad" when the average HTML file is hundreds of lines?

How is it OK to not respect g:vimsyn_minlines ?

@chrisbra
Copy link
Member

Because it doesn't sync? I have to :syn sync fromstart all the time when editing HTML...

Sounds more like you want a configuration variable that you can set for your specific use case.

How is 10 "not particularly bad" when the average HTML file is hundreds of lines?

I thought you wanted to disable it for performance reasons. Guess what: there is a reason, why a PR contains a big field where you can and should enter comments :)

Also, I fail to see, how minlines has any thing to do with hundreds of lines. It may still work to sync within 10 lines, right?

How is it OK to not respect g:vimsyn_minlines

Because that is for vim syntax files?

As mentioned, we probably want to make this variable configurable rather than remove it

@Cheaterman
Copy link
Author

So make it configurable using g:vimsyn_minlines? Since that's a vim syntax file?

@Cheaterman
Copy link
Author

Before:

before

After:

after

The only thing I did between the two is remove the offending line, then :e to re-edit my file.

@Cheaterman
Copy link
Author

If anything what I want to do locally is increase it, not decrease it. But the static 10 in the syntax file prevents that... so clearly it has to go, I don't even know why it's forced that way instead of relying on user settings?

@chrisbra
Copy link
Member

No, add a new variable, let's say: g:htmlsyn_minlines , mention it in the documentation at :h ft-html-syntax and refernce it then in the html syntax file, similar to how it is done in the vim syntax script

@Cheaterman
Copy link
Author

OK but then a follow-up question arises - why isn't there a way to globally set syntax sync minlines for all syntaxes? Related question, what makes you think 10 is a reasonable default (when it's clearly not, see my screenshots above)?

@chrisbra
Copy link
Member

OK but then a follow-up question arises - why isn't there a way to globally set syntax sync minlines for all syntaxes?

Is there such a global thing? Where?

Related question, what makes you think 10 is a reasonable default (when it's clearly not, see my screenshots above)?

Just because it failed for your html files, doesn't mean it fails for anybody else. I don't work a lot with html files but whenever I did, it worked for me. And I guess nobody has complained until now ?

@Cheaterman
Copy link
Author

Is there such a global thing? Where?

I'm literally asking why it doesn't exist.

Just because it failed for your html files, doesn't mean it fails for anybody else. I don't work a lot with html files but whenever I did, it worked for me. And I guess nobody has complained until now ?

That's the part that genuinely surprises me - clearly when writing SFCs you're gonna have a relatively large script block and a relatively large style block, both of which are gonna be incorrectly synced 90% of the time, which is why (after frustratingly and frantically using :syn sync fromstart for years) I made this PR.

I'm working on the g:htmlsyn_minlines right now, but still I feel like it would be a good idea for users to have a global way to deal with syntax sync minlines, don't you think? Since the main issue with sync minlines is performance, scaling it up depends largely on how fast one's machine is, not really per-language

@Cheaterman
Copy link
Author

It looks to me like if I do exactly what vim.syntax is doing, it will be functionally equivalent to removing the line for most users (having g:htmlsyn_minlines unset). Is this what we want?

@chrisbra
Copy link
Member

I'm literally asking why it doesn't exist.

Why should it? It clearly depends on the syntax you are using.

That's the part that genuinely surprises me - clearly when writing SFCs you're gonna have a relatively large script block and a relatively large style block, both of which are gonna be incorrectly synced 90% of the time, which is why (after frustratingly and frantically using :syn sync fromstart for years) I made this PR.

And thanks for that.

I'm working on the g:htmlsyn_minlines right now, but still I feel like it would be a good idea for users to have a global way to deal with syntax sync minlines, don't you think? Since the main issue with sync minlines is performance, scaling it up depends largely on how fast one's machine is, not really per-language

Ideally it should really be the responsibility of each syntax script maintainer to find reasonable good defaults, so that not each user has to fiddle with a global variable that does not always work for all kinds of languages. But it seems it doesn't always work well enough.

It looks to me like if I do exactly what vim.syntax is doing, it will be functionally equivalent to removing the line for most users (having g:htmlsyn_minlines unset). Is this what we want?

@dkearns what's your preference?

@Cheaterman
Copy link
Author

Cheaterman commented Feb 21, 2024

There's an extra issue for the latter point (documenting it in ft-html-syntax) - it looks to me like this documentation isn't representative of what we observe when editing HTML files (eg the part about <> and </> being colored differently), so perhaps this entire documentation page is out of date?

EDIT: As I mentioned earlier, I'm personally unsure that we can expect per-language "sane defaults", since what's sane is largely going to depend on user machine performance ; if anything, there could be a global "multiplier" to adjust all the per-language defaults, but having a global absolute line count as minlines sounds simpler to me (and more sensible).

@Cheaterman
Copy link
Author

I'm guessing a better source of inspiration for a default that can be overriden is c.vim ; I'd probably also use its documentation as a base for html.vim's future g:htmlsyn_minlines option, I think that's OK? :-)

@dkearns
Copy link
Contributor

dkearns commented Feb 22, 2024

Removing the syn-sync line doesn't make sense as it, in principal, removes syncing for that file. It appears to work because the HTML syntax file then uses the sync settings of the included XML syntax file. You can run :syn sync to query the current settings.

The best course of action is probably just to bump the default HTML syn-minlines value to something like 250. 10 was chosen as the default value in 1998. Most elements aren't matched as syn-regions by the syntax file so the overall length of the file doesn't matter, it's primarily the length of comments, style, and script elements.

You can override this value on a per-fileytpe basis by adding the command to something like ~/.vim/after/syntax/html.vim. Alternatively you can override it for all filetypes with a FileType autocommand executed after :syntax enable|on.

Adding a config option is fine but it should be named html_minlines. The de facto standard is to use a {filetype}_ prefix for the filetype-specific config variables. The Vim syntax file is an unfortunate exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants