unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#24978: 25.1; Bad interaction between nxml-auto-insert-xml-declaration-flag and archive-extract
@ 2016-11-21 13:41 Heinz Rommerskirchen
  2019-07-27 12:02 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Heinz Rommerskirchen @ 2016-11-21 13:41 UTC (permalink / raw)
  To: 24978

If the variable nxml-auto-insert-xml-declaration-flag is set, an XML
declaration is inserted into non-empty XML files inside a zip archive.

To reproduce this bug create the valid XML file foo.xml containing
=== start foo.xml ===
<?xml version="1.0" encoding="utf-8"?>
<content>y</content>
=== end foo.xml ===
and pack it into a zip-archive:
$ zip -m bar.zip foo.xml
Now start "emacs -Q", evaluate
"(setq nxml-auto-insert-xml-declaration-flag 't)" in the *scratch*
buffer, visit bar.zip with C-x C-f, and press Enter on the entry
"foo.xml". foo.xml will be opened and an additional XML declaration is
inserted into the buffer rendering the file invalid and marking the
buffer as modified.

The following simple patch solved the problem for me.

=== start patch ====
--- nxml-mode-from-25.1.el	2016-11-20 19:45:43.339427354 +0100
+++ nxml-mode.el	2016-11-20 19:48:26.009625534 +0100
@@ -566,7 +566,8 @@
    ;; 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 (not (and (buffer-file-name) (file-exists-p (buffer-file-name))))
+             (not archive-superior-buffer))
      (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))
=== end patch ===

-- 
Dr. Heinrich Rommerskirchen
Prof.-Schmid-Str. 41
82140 Olching
Allemagne

Tel. +49 8142 28787

Email heinz@h-rommerskirchen.de





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

* bug#24978: 25.1; Bad interaction between nxml-auto-insert-xml-declaration-flag and archive-extract
  2016-11-21 13:41 bug#24978: 25.1; Bad interaction between nxml-auto-insert-xml-declaration-flag and archive-extract Heinz Rommerskirchen
@ 2019-07-27 12:02 ` Lars Ingebrigtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2019-07-27 12:02 UTC (permalink / raw)
  To: Heinz Rommerskirchen; +Cc: 24978

Heinz Rommerskirchen <heinz@h-rommerskirchen.de> writes:

> If the variable nxml-auto-insert-xml-declaration-flag is set, an XML
> declaration is inserted into non-empty XML files inside a zip archive.
>
> To reproduce this bug create the valid XML file foo.xml containing
> === start foo.xml ===
> <?xml version="1.0" encoding="utf-8"?>
> <content>y</content>
> === end foo.xml ===
> and pack it into a zip-archive:
> $ zip -m bar.zip foo.xml
> Now start "emacs -Q", evaluate
> "(setq nxml-auto-insert-xml-declaration-flag 't)" in the *scratch*
> buffer, visit bar.zip with C-x C-f, and press Enter on the entry
> "foo.xml". foo.xml will be opened and an additional XML declaration is
> inserted into the buffer rendering the file invalid and marking the
> buffer as modified.

(I'm going through older Emacs bug reports that have received no
response.)

I was able to reproduce the bug in Emacs 27, too.

> The following simple patch solved the problem for me.

[...]

> -  (when (not (and (buffer-file-name) (file-exists-p (buffer-file-name))))
> +  (when (and (not (and (buffer-file-name) (file-exists-p (buffer-file-name))))
> +             (not archive-superior-buffer))

Thanks for the patch, but I think the problem is a bit more general.
The intention seems to be to insert the declaration whenever you're
starting a new file, so I think a more general solution is to just check
whether the buffer is empty before inserting the declaration.  I've now
done this change on the Emacs trunk.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

end of thread, other threads:[~2019-07-27 12:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-21 13:41 bug#24978: 25.1; Bad interaction between nxml-auto-insert-xml-declaration-flag and archive-extract Heinz Rommerskirchen
2019-07-27 12:02 ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).