From: Lars Ingebrigtsen Date: Mon, 6 Jun 2022 13:49:36 +0000 (+0200) Subject: Make find-file-noselect not pick buffers with broken symlinks X-Git-Tag: emacs-29.0.90~1910^2~191 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=7edf3d29029a884bbc30babe2bc105ac27aa61da;p=emacs.git 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). --- diff --git a/lisp/files.el b/lisp/files.el index 07ab2b45a51..d876a76119c 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