ffi-magic -- Fix #'magic:find-file-noselect unbound 'coding'
authorSteve Youngs <steve@sxemacs.org>
Thu, 8 Apr 2021 01:02:14 +0000 (11:02 +1000)
committerSteve Youngs <steve@sxemacs.org>
Thu, 8 Apr 2021 01:02:14 +0000 (11:02 +1000)
If you tried to open a file from a buffer where the coding system had
been set via file-local variable ("Local variables:" section or
cookie) it would result in a void variable error.  This change fixes
that.

* lisp/ffi/ffi-magic.el (magic:find-file-noselect): let-bind
'coding' inside the #'with-current-buffer instead of outside.

Signed-off-by: Steve Youngs <steve@sxemacs.org>
lisp/ffi/ffi-magic.el

index bb6ab16..b2bafa1 100644 (file)
@@ -590,16 +590,16 @@ set by something else prior.  For example, if the user had called
 (defun magic:find-file-noselect (file)
   (let* ((codesys (intern (magic:file file :mime-encoding)))
         (coding-system-for-read codesys)
-        (buf (create-file-buffer file))
-        (coding nil))
+        (buf (create-file-buffer file)))
     (with-current-buffer buf
-      (insert-file-contents file t)
-      (hack-local-variables)
-      (when (and coding (not (eq coding codesys)))
-       (let ((coding-system-for-read coding))
-         (set-buffer-file-coding-system coding)
-         (insert-file-contents file t nil nil t)))
-      (after-find-file nil t))
+      (let ((coding nil))
+       (insert-file-contents file t)
+       (hack-local-variables)
+       (when (and coding (not (eq coding codesys)))
+         (let ((coding-system-for-read coding))
+           (set-buffer-file-coding-system coding)
+           (insert-file-contents file t nil nil t)))
+       (after-find-file nil t)))
     buf))
 
 ;;;###autoload