Friday, May 26, 2017

Re: Bug in ftdetect?

On Do, 25 Mai 2017, Bram Moolenaar wrote:

> Christian Brabandt wrote:
>
> > On Mi, 24 Mai 2017, fREW Schmidt wrote:
> >
> > > Yes. "If I replace the contents of /usr/share/vim/vim80/syntax/vb.vim with `let
> > > b:current_syntax = "vb"` everything is fast and, as I would hope, the support
> > > files are not loaded N times per buffer but instead exactly once." 
> >
> > Well, I see the problem, although I cannot reproduce it.
> >
> > The markdown syntax script sources the html syntax script and that one
> > does include a couple of other syntax scripts, like css.vim,
> > javascript.vim and also vb.vim. However from my testing vb.vim is not
> > guilty alone. If I uncomment vb.vim, the overall loading time only
> > shrinks by 0.2 seconds or so (it needs here a total of around 7
> > seconds). So you would need to disable all other to be included syntax
> > scripts as well (for a test, you could set main_syntax='java').
>
> I haven't read the whole thread, but I suspect that the trick is to set
> b:current_syntax (to anything), which will cause further syntax scripts to bail
> out. Anyway, this is all working around the actual problem.

Not for html, which explicitly resets b:current_syntax to be able to
include several other syntax scripts and even provides the main_syntax
global variable to make this work with other syntax scripts.

>
> > However, I think you might have found a bug here. Your ftdetect script
> > does this:
> >
> > autocmd BufNew,BufNewFile,BufRead *.md :set filetype=markdown
> >
> > The :args command does fill the argument list, calls ex_next() which
> > calls eventually alist_set() and then iterates over the argument list
> > and calls adlist_add(). This will finally call buflist_add() which in
> > turn calls buflist_new(), which triggers the BufNew autocommand, which
> > then triggers the FileType and finally the Syntax autocommands. So in
> > the end, we are iterating over the whole list of arguments and call
> > autocommands, for buffers that are not even going to be displayed next.
> >
> > So I wonder, if we can't do a little bit better, similar to how vimgrep
> > sets the eventignore option to prevent at least the expensive FileType
> > autocommand:
>
> I'm quite sure this will make other things fail. Just don't use
> BufNew for detecting the filetype, that is the cause of the problem.
> The file type should only be detected when the buffer is loaded.
> Doing it earlier indeed causes the overhead experienced.

Indeed, however, that doesn't mean, we shouldn't try to avoid this
problem. Vimgrep does the same.

Best,
Christian
--
Am Ende ist alles ein Witz.
-- Charlie Chaplin

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment