Re: Augmenting filetype detection for supplemental types

2023-02-26 Thread Rob Foehl

On Sun, 26 Feb 2023, Bram Moolenaar wrote:


One way would be to not change 'filetype' directly but set a timer with
a very short timeout to do it later.  This can already be done now, you
can try it out.  Obvious disadvantage is that all the
indent/syntax/ftplugin files will be sourced twice.


Yeah, this works:

autocmd FileType foo if ... | call timer_start(0, {_ -> execute('set 
filetype=foo.bar', '')}) | endif

...assuming one can live with the double inclusion, which had tripped me 
up the first time I'd tried this.  Also attempted were various hacks 
in {,after/}ftplugin/foo/, with mixed results.


(Aside: a time of 0 isn't explicitly documented, but seems to work as 
expected, i.e. meaning something like "next tick"...)



A specific way to handle this would be to add a FileTypePre event, which
would be triggered first and allow for changing 'filetype'.  Hmm,
perhaps we would also need this for the Syntax event?
This would be a very specific solution, do we really need it?


That'd be cleaner...  Whether it's really needed, I'm not sure.  I'm 
pretty far down the rabbit hole of trying to mix syntaxes in particular -- 
see other thread on extend causing trouble -- but not far enough to have a 
solid grasp on whether there's a better way, or what that would be.


I've found a lot of existing workarounds -- the @htmlPreproc cluster, the 
near-copy of HTML in PHP, the dynamic inclusions in Markdown/RST/others -- 
and having hacked up another, none seem all that satisfying.


-Rob

--
--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/efc5d122-bf33-762f-369b-f3b4e55d312f%40loonybin.net.


Re: Syntax keepend/oneline vs. extend

2023-02-26 Thread Rob Foehl

On Sat, 11 Feb 2023, Rob Foehl wrote:

(Context: including portions of one syntax in another, where the former's use 
of extend doesn't anticipate the latter.  I haven't found any obviously right 
way to do this in either the help or the runtime files that ship with Vim, 
only workarounds for specific cases.)


Toying with this a bit more, I managed to work around the issues with 
extend by mechanically collecting :syn list output and replacing the 
offending bits of the existing syntax, which is... ugly.


The seeming inability to do this otherwise had me wondering why this 
problem wasn't more commonplace, and how often extend is actually used in 
the syntax files shipped with Vim (as of 9.0.1307):


 99 syntax/perl.vim
 23 syntax/plsql.vim
 22 syntax/php.vim
 18 syntax/rpl.vim
 14 syntax/fortran.vim
 11 syntax/raku.vim
 10 syntax/c.vim
  8 syntax/rhelp.vim
  7 syntax/baan.vim syntax/rib.vim syntax/tt2.vim
  6 syntax/cs.vim
  4 syntax/ada.vim syntax/pike.vim syntax/xml.vim
  3 syntax/obse.vim syntax/typescriptreact.vim
  2 [12 files]
  1 [14 files]
  0 [636 files]

Oh.  Of course the one I'm trying to embed is the outlier...  Jokes about 
only Perl being able to parse Perl aside, am I wrong to presume that at 
least a few of those 99 instances might be gratuitous?


Among the dozen or so that I've tripped over thus far, I can't tell what 
any of them were actually intended to accomplish.  For example:


syn match  perlComment  "#.*" contains=perlTodo,@Spell extend

Huh?  EOL is also end-of-comment, so what's that supposed to do?

-Rob

--
--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/bb8db435-c23a-4e55-4820-76a1d1547a25%40loonybin.net.


Re: Augmenting filetype detection for supplemental types

2023-02-26 Thread Bram Moolenaar


> Attempting to set multiple filetypes based on something like
> 
> autocmd FileType foo if ... | set filetype=foo.bar | endif
> 
> seems to have an ordering problem with the FileType autocmd that sets 
> 'syntax' -- the "foo.bar" filetype is set, requisite files for "bar" are 
> loaded, and then the autocmd waiting on the original expansion of  
> to "foo" runs and effectively resets the syntax.
> 
> Is there a way to tack on a supplemental filetype without running into 
> this problem?  The obvious approach of setting the whole string at once 
> works, but that requires duplicating everything that could otherwise 
> determine the initial filetype...

It's hard to think of an elegant way to deal with this.  Once the
FileType event is triggered, it would normally find all matching
autocommands and execute them.  Changing the value halfway makes it
unpredictable, easily leading to weird errors.

One way would be to not change 'filetype' directly but set a timer with
a very short timeout to do it later.  This can already be done now, you
can try it out.  Obvious disadvantage is that all the
indent/syntax/ftplugin files will be sourced twice.

A specific way to handle this would be to add a FileTypePre event, which
would be triggered first and allow for changing 'filetype'.  Hmm,
perhaps we would also need this for the Syntax event?
This would be a very specific solution, do we really need it?

-- 
hundred-and-one symptoms of being an internet addict:
182. You may not know what is happening in the world, but you know
 every bit of net-gossip there is.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///  \\\
\\\sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/20230226144757.A0DCA1C0B1F%40moolenaar.net.