diff options
Diffstat (limited to 'lisp/international/mule.el')
-rw-r--r-- | lisp/international/mule.el | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lisp/international/mule.el b/lisp/international/mule.el index a5e7477e758..0267b154409 100644 --- a/lisp/international/mule.el +++ b/lisp/international/mule.el @@ -2545,7 +2545,17 @@ This function is intended to be added to `auto-coding-functions'." (let* ((match (match-string 2)) (sym (intern (downcase match)))) (if (coding-system-p sym) - sym + ;; If the encoding tag is UTF-8 and the buffer's + ;; encoding is one of the variants of UTF-8, use the + ;; buffer's encoding. This allows, e.g., saving an + ;; HTML file as UTF-8 with BOM when the tag says UTF-8. + (let ((sym-type (coding-system-type sym)) + (bfcs-type + (coding-system-type buffer-file-coding-system))) + (if (and (coding-system-equal 'utf-8 sym-type) + (coding-system-equal 'utf-8 bfcs-type)) + buffer-file-coding-system + sym)) (message "Warning: unknown coding system \"%s\"" match) nil))))) |