emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master d4fce73: Only insert XML declarations in nxml-mode


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master d4fce73: Only insert XML declarations in nxml-mode when the buffer is empty
Date: Sat, 27 Jul 2019 08:01:16 -0400 (EDT)

branch: master
commit d4fce7394345233026e6b427d90e0debe6c3e89e
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Only insert XML declarations in nxml-mode when the buffer is empty
    
    * lisp/nxml/nxml-mode.el (nxml-mode): Don't insert the XML
    declaration unless it's an empty buffer (bug#24978).  This avoids
    the problem of the declaration being inserted by mistake when
    opening XML files from archives and the like -- the file doesn't
    exist on the file system there, either, so it would typically lead
    to doubled XML declarations.
---
 lisp/nxml/nxml-mode.el | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el
index ad78d08..623a666 100644
--- a/lisp/nxml/nxml-mode.el
+++ b/lisp/nxml/nxml-mode.el
@@ -530,16 +530,13 @@ Many aspects this mode can be customized using
   (setq-local syntax-propertize-function #'nxml-syntax-propertize)
   (add-hook 'change-major-mode-hook #'nxml-cleanup nil t)
 
-  ;; Emacs 23 handles the encoding attribute on the xml declaration
-  ;; transparently to nxml-mode, so there is no longer a need for the below
-  ;; hook. The hook also had the drawback of overriding explicit user
-  ;; instruction to save as some encoding other than utf-8.
-  ;;(add-hook 'write-contents-hooks #'nxml-prepare-to-save)
   (when (not (and (buffer-file-name) (file-exists-p (buffer-file-name))))
     (when (and nxml-default-buffer-file-coding-system
               (not (local-variable-p 'buffer-file-coding-system)))
       (setq buffer-file-coding-system nxml-default-buffer-file-coding-system))
-    (when nxml-auto-insert-xml-declaration-flag
+    ;; When starting a new file, insert the XML declaraction.
+    (when (and nxml-auto-insert-xml-declaration-flag
+               (zerop (buffer-size)))
       (nxml-insert-xml-declaration)))
 
   (setq font-lock-defaults



reply via email to

[Prev in Thread] Current Thread [Next in Thread]