[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug in mule.el/sgml-xml-auto-coding-function
From: |
Kevin Rodgers |
Subject: |
Re: Bug in mule.el/sgml-xml-auto-coding-function |
Date: |
Thu, 28 Apr 2005 12:29:18 -0600 |
User-agent: |
Mozilla Thunderbird 0.9 (X11/20041105) |
Jirka Kosek wrote:
> function sgml-xml-auto-coding-function tries to detect encoding of XML
> file.
What version of Emacs are you using? That function isn't distributed
with 21.3.
> XML specification allows encoding name to be surrounded by quotes
> or apostrophes. Current code expect only quotes so it won't detect
> encoding if specified as:
>
> <?xml version="1.0" encoding='windows-1250'?>
>
> The following function has corrected RE in order to deal with both
> delimiters.
>
> (defun sgml-xml-auto-coding-function (size)
> "Determine whether the buffer is XML, and if so, its encoding.
> This function is intended to be added to `auto-coding-functions'."
> (setq size (+ (point) size))
> (when (re-search-forward "\\`[[:space:]\n]*<\\?xml" size t)
> (let ((end (save-excursion
> ;; This is a hack.
> (re-search-forward "[\"']\\s-*\\?>" size t))))
> (when end
> (if (re-search-forward "encoding=[\"']\\(.+?\\)[\"']" end t)
> (let* ((match (match-string 1))
> (sym (intern (downcase match))))
> (if (coding-system-p sym)
> sym
> (message "Warning: unknown coding system \"%s\"" match)
> nil))
> 'utf-8)))))
The delimiters must match:
(if (re-search-forward "encoding=\\([\"']\\)\\(.+?\\)\\1" end t)
(let* ((match (match-string 2))
--
Kevin Rodgers