Loading ...
Sorry, an error occurred while loading the content.
 

Re: filetype detection within files

Expand Messages
  • Marc Weber
    I know about &ft. Talking about == a .html file == CURSOR_HERE == Now I want a function which returnns js if cursor is
    Message 1 of 5 , Dec 5, 2012
      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

      --
      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
    • Tony Mechelynck
      ... 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
      Message 2 of 5 , Dec 5, 2012
        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
      • Charles Campbell
        ... If I understand correctly, you want to know the currently active effective filetype when a syntax group has been included in. For example, from html: syn
        Message 3 of 5 , Dec 6, 2012
          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.

          If I understand correctly, you want to know the currently active
          effective filetype when a syntax group has been "included" in.

          For example, from html:

          syn include @htmlJavaScript syntax/javascript.vim
          syn region javaScript start=+<script[^>]*>+ keepend
          end=+</script>+me=s-1
          contains=@htmlJavaScript,htmlCssStyleComment,htmlScriptTag,@htmlPreproc

          which interprets the <script type="javascript">... snippet above.

          In your example, the following vimL...

          let idlist = synstack(line("."),col("."))
          for id in idlist
          echo synIDattr(id,"name")
          endfor

          will show "javaScript". Any syntax inclusion must be in a region. You
          could manually extract a list of such names and set up a dictionary
          mapping them to the filetypes you want (ie. converting javaScript ->
          javascript (js is just one of several suffices that map to a filetype of
          javascript). Alternatively, you could have something crawl through the
          syntax files and build such a list, but I'd think that'd be
          unnecessarily time consuming (as the syntax-include region names are
          likely to be fairly static).

          Regards,
          C Campbell





          --
          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
        Your message has been successfully submitted and would be delivered to recipients shortly.