Subject: Re: bug#25360: File mode specification errors during building

From: Noam Postavsky <[email-masked]>
Date: Thu, 19 Jan 2017 12:06:07 -0500

On Thu, Jan 19, 2017 at 11:05 AM, Eli Zaretskii <[email-masked]> wrote:
>> From: [email-masked] (Phillip Lord)
>> Cc: Glenn Morris <[email-masked]>,  [email-masked],  Eli Zaretskii <[email-masked]>
>> Date: Thu, 19 Jan 2017 10:45:51 +0000
>>
>> > I believe it does respect "coding:" in general (at least it looks like
>> > there are some comments to that effect in Finsert_file_contents), but
>> > indeed it doesn't matter in this case because we're let-binding
>> > `coding-system-for-read' which overrides that.
>>
>> I have checked this now with a full bootstrap and it appears not to
>> work, unfortunately -- the .el files that are generated are broken (this
>> isn't obvious until they fail to byte-compile -- you have let the build
>> complete).
>
> Every file is broken, or just some of them?  If the latter, can you
> name some of them, or try to figure out what they have in common?

The problem is that (with-temp-buffer) changes the current buffer,
which the converter function expected to be set to the output file
(sorry for not checking this properly before). Attached is a
non-broken version of my previous patch.
diff --git i/lisp/international/titdic-cnv.el w/lisp/international/titdic-cnv.elindex 6f65d49..130bc74 100644
--- i/lisp/international/titdic-cnv.el
+++ w/lisp/international/titdic-cnv.el
@@ -1167,11 +1167,14 @@ miscdic-convert
 		    (if (eq coding 'iso-2022-cn-ext) "Chinese-CNS"
 		      "Chinese-GB"))
 		  "\" \"" title "\" t\n")
-	  (let* ((coding-system-for-read
-		  (coding-system-change-eol-conversion coding 'unix))
-		 (dicbuf (find-file-noselect filename)))
-	    (funcall converter dicbuf name title)
-	    (kill-buffer dicbuf))
+          (let ((coding-system-for-read
+                 (coding-system-change-eol-conversion coding 'unix))
+                (dstbuf (current-buffer)))
+            (with-temp-buffer
+              (insert-file-contents filename)
+              (let ((dicbuf (current-buffer)))
+                (with-current-buffer dstbuf
+                  (funcall converter dicbuf name title)))))
 	  (insert ";; Local Variables:\n"
 		  ";; version-control: never\n"
 		  ";; no-update-autoloads: t\n"