diff options
| author | Lars Ingebrigtsen | 2019-07-27 14:01:10 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-07-27 14:01:10 +0200 |
| commit | d4fce7394345233026e6b427d90e0debe6c3e89e (patch) | |
| tree | c8bc1f0f13f3da2983237ae814c098d078d73b60 | |
| parent | 60511bd89dbc9cd5a3ee2bb615a118cb379fb956 (diff) | |
| download | emacs-d4fce7394345233026e6b427d90e0debe6c3e89e.tar.gz emacs-d4fce7394345233026e6b427d90e0debe6c3e89e.zip | |
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.
| -rw-r--r-- | lisp/nxml/nxml-mode.el | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/lisp/nxml/nxml-mode.el b/lisp/nxml/nxml-mode.el index ad78d086c74..623a6666627 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 | |||
| 530 | (setq-local syntax-propertize-function #'nxml-syntax-propertize) | 530 | (setq-local syntax-propertize-function #'nxml-syntax-propertize) |
| 531 | (add-hook 'change-major-mode-hook #'nxml-cleanup nil t) | 531 | (add-hook 'change-major-mode-hook #'nxml-cleanup nil t) |
| 532 | 532 | ||
| 533 | ;; Emacs 23 handles the encoding attribute on the xml declaration | ||
| 534 | ;; transparently to nxml-mode, so there is no longer a need for the below | ||
| 535 | ;; hook. The hook also had the drawback of overriding explicit user | ||
| 536 | ;; instruction to save as some encoding other than utf-8. | ||
| 537 | ;;(add-hook 'write-contents-hooks #'nxml-prepare-to-save) | ||
| 538 | (when (not (and (buffer-file-name) (file-exists-p (buffer-file-name)))) | 533 | (when (not (and (buffer-file-name) (file-exists-p (buffer-file-name)))) |
| 539 | (when (and nxml-default-buffer-file-coding-system | 534 | (when (and nxml-default-buffer-file-coding-system |
| 540 | (not (local-variable-p 'buffer-file-coding-system))) | 535 | (not (local-variable-p 'buffer-file-coding-system))) |
| 541 | (setq buffer-file-coding-system nxml-default-buffer-file-coding-system)) | 536 | (setq buffer-file-coding-system nxml-default-buffer-file-coding-system)) |
| 542 | (when nxml-auto-insert-xml-declaration-flag | 537 | ;; When starting a new file, insert the XML declaraction. |
| 538 | (when (and nxml-auto-insert-xml-declaration-flag | ||
| 539 | (zerop (buffer-size))) | ||
| 543 | (nxml-insert-xml-declaration))) | 540 | (nxml-insert-xml-declaration))) |
| 544 | 541 | ||
| 545 | (setq font-lock-defaults | 542 | (setq font-lock-defaults |