I wrote a simple function for workaround. Hope it helps.
(defun sgml-xml-auto-coding-function-utf (size)
(let* ((selected-coding (sgml-xml-auto-coding-function size))
(selected (symbol-name selected-coding))
(current-coding buffer-file-coding-system)
(current (symbol-name current-coding))
)
(if (and (string-match "^utf-" selected)
(string-match "^utf-.+\\(-with-signature.*\\)" current))
(if (string= selected (substring current 0 (length selected)))
current-coding
;; current=utf-cc-xxxx; selected=utf-ss; new -> utf-ss-xxxx
(let ((sig (match-string 1 current))
new)
(string-match "^utf-\\(.+\\)" selected)
(setq new (match-string 1 selected))
(setq new (intern (concat "utf-" new sig)))
(if (coding-system-p new)
new
selected-coding
)))
selected-coding))
)
Hi,
I am using Emacs 23.2.1. I think sgml-xml-auto-coding-function() should respect the *-with-signature-* coding.
Consider the scenario below:
1. xml file with the signature \376\377 at beginning of the file and the first line is
<?xml version="1.0" encoding="utf-16be"?>
2. edit this file and save it. sgml-xml-auto-coding-function will use the utf-16be to save the file.
3. open the file again, get messed.
In this case sgml-xml-auto-coding-function() shouldn't change the coding and if it really need to change the coding, it should append the *-with-signature-* to the selected coding.
sgml-html-meta-auto-coding-function() should have same problem.