Subject: Re: bug#18141: 24.4.50; saving .gz file breaks file coding

From: Eli Zaretskii <[email-masked]>
Date: Wed, 06 Aug 2014 21:10:39 +0300

> From: Stefan Monnier <[email-masked]>
> Cc: Glenn Morris <[email-masked]>,  [email-masked],  Vincent Lefevre <[email-masked]>,  [email-masked]
> Date: Wed, 06 Aug 2014 13:48:27 -0400
> 
> > -	      (let ((coding-system-for-write writecoding)
> > -		    (coding-system-require-warning nil))
> > +	      (let ((coding-system-for-write
> > +		     (if filename-is-magic coding-system-for-write writecoding))
> > +		    (coding-system-require-warning
> > +		     (if filename-is-magic coding-system-require-warning)))
> >  		(write-region nil nil
> >  			      buffer-file-name nil t buffer-file-truename)
> >  		(setq success t))
> 
> I can vaguely guess why that avoids the problem

The problem is the binding of coding-system-for-write based on
incorrect interpretation of buffer-file-name.  Why that causes the bug
was explained in the text you elided.  The code avoids the binding,
and thus fixes its adverse effects.

> but I'm having a hard time seeing why the above is "right".

Do you see why the binding is "wrong"?

> IOW it seems like an ugly workaround which may itself come with
> unintended consequences.

I agree that reverting the original change, which introduced this
binding, is a better solution.  Again, the text you elided said
precisely that.  I wonder why you didn't comment on that at all.

As for unintended consequences, I don't see how can any come out of
that, since this just restores the code that was working for years.

Of course, if you have a better suggestion that would be safe enough
for the release branch, I'm all ears.