help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: wrong type error in local variables


From: Stefan Monnier
Subject: Re: wrong type error in local variables
Date: Thu, 02 Jul 2020 13:42:41 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

>> `find-file` should not be called from Elisp.
>> Use `find-file-noselect` instead.
> Oups, if so I have 15 changes to make.
> Why doesn't the byte compiler say this?

Because noone has added the annotation for it yet (tho there are
various comments in the code that say so).

FWIW, I just tried adding it (see patch below), and I see that we have
many cases in Emacs's own Lisp code where we call `find-file`
from Elisp.  I suspect that many of them would benefit from being
changed, but the need to go and update all those cases might be a
reason why it hasn't been done yet :-(


        Stefan


diff --git a/lisp/files.el b/lisp/files.el
index 742fd78df1d..a29d02bf591 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1688,6 +1688,7 @@ find-file
 
 To visit a file without any kind of conversion and without
 automatically choosing a major mode, use \\[find-file-literally]."
+  (declare (interactive-only find-file-noselect))
   (interactive
    (find-file-read-args "Find file: "
                         (confirm-nonexistent-file-or-buffer)))
@@ -1761,15 +1762,16 @@ find-file-other-frame
       (switch-to-buffer-other-frame value))))
 
 (defun find-file-existing (filename)
-   "Edit the existing file FILENAME.
+  "Edit the existing file FILENAME.
 Like \\[find-file], but allow only a file that exists, and do not allow
 file names with wildcards."
-   (interactive (nbutlast (find-file-read-args "Find existing file: " t)))
-   (if (and (not (called-interactively-p 'interactive))
-           (not (file-exists-p filename)))
-       (error "%s does not exist" filename)
-     (find-file filename)
-     (current-buffer)))
+  (interactive (nbutlast (find-file-read-args "Find existing file: " t)))
+  (if (not (or (called-interactively-p 'interactive)
+               (file-exists-p filename)))
+      (error "%s does not exist" filename)
+    (with-suppressed-warnings ((interactive-only find-file))
+      (find-file filename))
+    (current-buffer)))
 
 (defun find-file--read-only (fun filename wildcards)
   (unless (or (and wildcards find-file-wildcards




reply via email to

[Prev in Thread] Current Thread [Next in Thread]