Subject: project-search fails with file-missing error

From: Dmitry Gutov <[email-masked]>
Date: Tue, 1 Dec 2020 05:15:50 +0200

I have a few broken symlinks in the current project, and when doing a 
search, it stops at the first one it sees, with a backtrace like

(file-missing "Opening input file" "No such file or directory" 
"etc/etc/etc")
   insert-file-contents("etc/etc/etc" nil)
   (if (not (and new novisit)) (set-buffer (find-file-noselect next)) 
(set-buffer (get-buffer-create " *next-file*")) 
(kill-all-local-variables) (erase-buffer) (setq new next) 
(insert-file-contents new nil))
   (let* ((buffer (get-file-buffer next)) (new (not buffer))) (and 
buffer fileloop-revert-buffers (not (verify-visited-file-modtime 
buffer)) (if (eq fileloop-revert-buffers 'silent) (and (not 
(buffer-modified-p buffer)) (let ((revertible nil)) (let 
((--dolist-tail-- revert-without-query)) (while --dolist-tail-- (let ... 
... ...))) revertible)) (y-or-n-p (format (if (buffer-modified-p buffer) 
"File %s changed on disk.  Discard your edits? " "File %s changed on 
disk.  Reread from disk? ") next))) (save-current-buffer (set-buffer 
buffer) (revert-buffer t t))) (if (not (and new novisit)) (set-buffer 
(find-file-noselect next)) (set-buffer (get-buffer-create " 
*next-file*")) (kill-all-local-variables) (erase-buffer) (setq new next) 
(insert-file-contents new nil)) new)
   (let ((next (condition-case nil (iter-next fileloop--iterator) 
(iter-end-of-sequence nil)))) (if next nil (and novisit (get-buffer " 
*next-file*") (kill-buffer " *next-file*")) (user-error "All files 
processed")) (let* ((buffer (get-file-buffer next)) (new (not buffer))) 
(and buffer fileloop-revert-buffers (not (verify-visited-file-modtime 
buffer)) (if (eq fileloop-revert-buffers 'silent) (and (not 
(buffer-modified-p buffer)) (let ((revertible nil)) (let (...) (while 
--dolist-tail-- ...)) revertible)) (y-or-n-p (format (if 
(buffer-modified-p buffer) "File %s changed on disk.  Discard your 
edits? " "File %s changed on disk.  Reread from disk? ") next))) 
(save-current-buffer (set-buffer buffer) (revert-buffer t t))) (if (not 
(and new novisit)) (set-buffer (find-file-noselect next)) (set-buffer 
(get-buffer-create " *next-file*")) (kill-all-local-variables) 
(erase-buffer) (setq new next) (insert-file-contents new nil)) new))
   fileloop-next-file(t)

Not such what's the best solution, but either all commands which use 
fileloop should pre-filter the list with file-exists-p, or 
fileloop-next-file should skip over nonexistent files. This seems to work:

diff --git a/lisp/fileloop.el b/lisp/fileloop.el
index b778eca8e9..289df6d593 100644
--- a/lisp/fileloop.el
+++ b/lisp/fileloop.el
@@ -120,7 +120,10 @@ fileloop-next-file
          (kill-all-local-variables)
          (erase-buffer)
          (setq new next)
-        (insert-file-contents new nil))
+        (condition-case nil
+            (insert-file-contents new nil)
+          (file-missing
+           (fileloop-next-file novisit))))
        new)))

  (defun fileloop-continue ()