Wednesday, December 5, 2012

Re: filetype detection within files

On 05/12/12 18:23, Marc Weber wrote:
> I know about &ft.
>
> Talking about
>
> == a .html file ==
>
> <script type="javaoscript">
> CURSOR_HERE
> </script>
>
> ==
>
> Now I want a function which returnns "js" if cursor is in such a
> javascript section. That would be useful for both: commenting plugins
> and snippet plugins.
>
> Same for any kind of "nested" languages such as php, haml, jsp etc.
>
> Marc Weber
>

Ah, that doesn't look so easy.

Maybe by examining the syntax group at the cursor position and checking
the part of the group name before the first uppercase letter? You would
of course need to have syntax highlighting enabled (and compiled-in).

See
:help synID()
:help synIDattr()
:help synIDtrans()

There are however places (such as in "ordinary" HTML text) where no
syntax group is defined, defaulting to the Normal highlight.

Also, in the value of a style= attribute within an HTML tag, the syntax
group is htmlString (highlight linked to Constant), not anything
CSS-related.


Best regards,
Tony.
--
"Beware of the man who works hard to learn something, learns it, and
finds himself no wiser than before," Bokonon tells us. "He is full of
murderous resentment of people who are ignorant without having come by
their ignorance the hard way."
-- Kurt Vonnegut, "Cat's Cradle"

--
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

No comments: