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

Re: Proposing new "filetype"

Expand Messages
  • Bram Moolenaar
    ... Seems that the pattern
    Message 1 of 3 , Feb 4, 2003
    • 0 Attachment
      Dan Sharp replied to Benji Fisher:

      > > I think it would be better to use the existing mechanism than to
      > >override it. Remember, $VIMRUNTIME/scripts.vim can be used to check the
      > >first few lines. Do XHTML files have the extension .html ? If so, then
      > >instead of deciding, in filetype.vim, that this file is HTML, it should be
      > >left to scripts.vim, where the first few lines can be checked for the XML
      > >header <?xml ... ?>. If this is found, we can look for the DTD and assign
      > >a filetype of XHTML if appropriate.
      > Checking for the XML header in a .html file would probably be easiest, but
      > according to the XHTML 1.0 spec it is not required, so may not always be
      > available. The DOCTYPE definition is required, so scripts.vim could check
      > for one of (or just XHTML inside of) the following three definitions to
      > determine if a file is xhtml instead of plain html.
      > <!DOCTYPE html
      > PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      > <!DOCTYPE html
      > PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      > <!DOCTYPE html
      > PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
      > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

      Seems that the pattern "\<DTD\s\+XHTML\s" would already be specific enough.

      Try this in $VIMRUNTIME/filetype.vim:

      " HTML (.shtml for server side)
      au BufNewFile,BufRead *.html,*.htm,*.shtml call <SID>FTCheck_html()

      " Distinguish between HTML and XHTML
      fun! <SID>FTCheck_html()
      let n = 1
      while n < 10 && n < line("$")
      if getline(n) =~ '\<DTD\s\+XHTML\s'
      setf xhtml
      let n = n + 1
      setf html

      It's easy to add an "xhtml" filetype and use either the html or xml
      scripts to start with. Then improve the xhtml specific things.

      Someone who would like to take up the xhtml syntax and/or indent file?

      hundred-and-one symptoms of being an internet addict:
      121. You ask for e-mail adresses instead of telephone numbers.

      /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
      /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
      \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
      \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///
    Your message has been successfully submitted and would be delivered to recipients shortly.