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

Re: Using fenc in modeline

Expand Messages
  • A. J. Mechelynck
    Bram Moolenaar wrote: [...] ... Since you re doing it for XML, you might add a todo item of equal priority to check, in HTML files, the first few lines (it s
    Message 1 of 2 , Apr 4, 2005
      Bram Moolenaar wrote:
      [...]
      > There is an idea in the todo list to allow specifying the encoding in
      > one of the first lines in the file:
      >
      > 8 Add an item in 'fileencodings' to check the first lines of a file for
      > the encoding. See Python PEP: http://www.python.org/peps/pep-0263.html.
      > To avoid getting a wrong encoding only accept something Emacs-like:
      > "-*- coding: enc-na_me.foo -*-" and "-*- coding= enc-na_me.foo -*-"
      > Match with "-\*-\s*coding[:=]\s*\([::word::-_.]\+\)\s*-\*-" and use first
      > item.
      > 8 Add an item in 'fileencodings' to check the first line of an XML file for
      > the encoding. <?xml version="1.0" encoding="UTF-8"?> Or "charset=UTF-8"?
      >
      > This is a typical problem of having so many standards to chose from...
      >
      Since you're doing it for XML, you might add a todo item of equal
      priority to check, in HTML files, the first few lines (it's usually not
      the first one) for a tag of the format:

      <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8" />

      which must come before the </HEAD> closing tag. I think it is
      case-insensitive but I'm not 100% sure. I suppose that if both items you
      quoted become possible it should be a small matter to add this kind of
      detection in the appropriate vim script (ftplugin/html.vim maybe?).
      Maybe through a new autocommand event triggered after a "preliminary
      read" (call it ModeLine, EncodingDetect, whatever)? Or maybe define a
      buffer-local boolean allowing BufReadPost autocommands to trigger a
      re-read with some options changed? ('fileencoding' being the prime
      example but not necessarily the only one)

      I'm just running ideas up the flagpole here. Any salutes?

      Best regards,
      Tony.
    • Bram Moolenaar
      ... When doing it for XML then we should do the same for HTML. And PHP, and... ... I don t know what would be the best way to implement this. Perhaps an
      Message 2 of 2 , Apr 5, 2005
        Tony Mechelynck wrote:

        > Bram Moolenaar wrote:
        > [...]
        > > There is an idea in the todo list to allow specifying the encoding in
        > > one of the first lines in the file:
        > >
        > > 8 Add an item in 'fileencodings' to check the first lines of a file for
        > > the encoding. See Python PEP: http://www.python.org/peps/pep-0263.html.
        > > To avoid getting a wrong encoding only accept something Emacs-like:
        > > "-*- coding: enc-na_me.foo -*-" and "-*- coding= enc-na_me.foo -*-"
        > > Match with "-\*-\s*coding[:=]\s*\([::word::-_.]\+\)\s*-\*-" and use first
        > > item.
        > > 8 Add an item in 'fileencodings' to check the first line of an XML file for
        > > the encoding. <?xml version="1.0" encoding="UTF-8"?> Or "charset=UTF-8"?
        > >
        > > This is a typical problem of having so many standards to chose from...
        > >
        > Since you're doing it for XML, you might add a todo item of equal
        > priority to check, in HTML files, the first few lines (it's usually not
        > the first one) for a tag of the format:
        >
        > <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8" />
        >
        > which must come before the </HEAD> closing tag. I think it is
        > case-insensitive but I'm not 100% sure.

        When doing it for XML then we should do the same for HTML. And PHP,
        and...

        > I suppose that if both items you
        > quoted become possible it should be a small matter to add this kind of
        > detection in the appropriate vim script (ftplugin/html.vim maybe?).
        > Maybe through a new autocommand event triggered after a "preliminary
        > read" (call it ModeLine, EncodingDetect, whatever)? Or maybe define a
        > buffer-local boolean allowing BufReadPost autocommands to trigger a
        > re-read with some options changed? ('fileencoding' being the prime
        > example but not necessarily the only one)
        >
        > I'm just running ideas up the flagpole here. Any salutes?

        I don't know what would be the best way to implement this. Perhaps an
        option 'encdetectexpr', so that you can define your own. Although it
        probably needs to be a list to which you can add more items. Or replace
        the one used for XML... It's this "figure out how to do it" that is the
        main reason it's still in the todo list.

        --
        Keyboard not found. Think ENTER to continue.

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
        \\\ Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html ///
      Your message has been successfully submitted and would be delivered to recipients shortly.