"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))))
(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