emacs-diffs
[Top][All Lists]
Advanced

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

master 7edf3d2902: Make find-file-noselect not pick buffers with broken


From: Lars Ingebrigtsen
Subject: master 7edf3d2902: Make find-file-noselect not pick buffers with broken symlinks
Date: Mon, 6 Jun 2022 09:51:11 -0400 (EDT)

branch: master
commit 7edf3d29029a884bbc30babe2bc105ac27aa61da
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Make find-file-noselect not pick buffers with broken symlinks
    
    * lisp/files.el (find-buffer-visiting): Improve doc string.
    (find-file-noselect): Don't pick buffers with broken symlinks,
    because that's too confusing (bug#41414).
---
 lisp/files.el | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index 07ab2b45a5..d876a76119 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -2102,8 +2102,11 @@ started Emacs, set `abbreviated-home-dir' to nil so it 
will be recalculated)."
   "Return the buffer visiting file FILENAME (a string).
 This is like `get-file-buffer', except that it checks for any buffer
 visiting the same file, possibly under a different name.
+
 If PREDICATE is non-nil, only buffers satisfying it are eligible,
-and others are ignored.
+and others are ignored.  PREDICATE is called with the buffer as
+the only argument, but not with the buffer as the current buffer.
+
 If there is no such live buffer, return nil."
   (let ((predicate (or predicate #'identity))
         (truename (abbreviate-file-name (file-truename filename))))
@@ -2324,7 +2327,16 @@ the various files."
             (attributes (file-attributes truename))
             (number (nthcdr 10 attributes))
             ;; Find any buffer for a file that has same truename.
-            (other (and (not buf) (find-buffer-visiting filename))))
+            (other (and (not buf)
+                         (find-buffer-visiting
+                          filename
+                          ;; We want to filter out buffers that we've
+                          ;; visited via symlinks and the like, where
+                          ;; the symlink no longer exists.
+                          (lambda (buffer)
+                            (let ((file (buffer-local-value
+                                         'buffer-file-name buffer)))
+                              (and file (file-exists-p file))))))))
        ;; Let user know if there is a buffer with the same truename.
        (if other
            (progn



reply via email to

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