all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Bug in mule.el/sgml-xml-auto-coding-function
@ 2005-04-28 11:48 Jirka Kosek
  2005-04-28 18:29 ` Kevin Rodgers
  0 siblings, 1 reply; 2+ messages in thread
From: Jirka Kosek @ 2005-04-28 11:48 UTC (permalink / raw)



[-- Attachment #1.1: Type: text/plain, Size: 1548 bytes --]

Hi,

function sgml-xml-auto-coding-function tries to detect encoding of XML 
file. 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)))))


TIA,

				Jirka

-- 
------------------------------------------------------------------
   Jirka Kosek     e-mail: jirka@kosek.cz     http://www.kosek.cz
------------------------------------------------------------------
   Profesionální školení a poradenství v oblasti technologií XML.
      Podívejte se na náš nově spuštěný web http://DocBook.cz
        Podrobný přehled školení http://xmlguru.cz/skoleni/
------------------------------------------------------------------


[-- Attachment #1.2: S/MIME Cryptographic Signature --]
[-- Type: application/x-pkcs7-signature, Size: 3158 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

_______________________________________________
Bug-gnu-emacs mailing list
Bug-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnu-emacs

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Bug in mule.el/sgml-xml-auto-coding-function
  2005-04-28 11:48 Bug in mule.el/sgml-xml-auto-coding-function Jirka Kosek
@ 2005-04-28 18:29 ` Kevin Rodgers
  0 siblings, 0 replies; 2+ messages in thread
From: Kevin Rodgers @ 2005-04-28 18:29 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-04-28 18:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-28 11:48 Bug in mule.el/sgml-xml-auto-coding-function Jirka Kosek
2005-04-28 18:29 ` Kevin Rodgers

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.