aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl Heuer1994-03-09 00:23:30 +0000
committerKarl Heuer1994-03-09 00:23:30 +0000
commit138c44f6a33d6edc905fbd9c8427308335539d74 (patch)
tree1f3f1b09d9584e8b7524216cfec7d4b97a14dc5b
parente6d25e1474753fd78ad28c317504746476f90663 (diff)
downloademacs-138c44f6a33d6edc905fbd9c8427308335539d74.tar.gz
emacs-138c44f6a33d6edc905fbd9c8427308335539d74.zip
(find-buffer-visiting): New function to look for another buffer visiting the
same inode. (find-file-noselect): Use it instead of inline code.
-rw-r--r--lisp/files.el81
1 files changed, 41 insertions, 40 deletions
diff --git a/lisp/files.el b/lisp/files.el
index 831cb6d27d7..c89981f54bb 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -573,6 +573,38 @@ you may or may not want the visited file name to record the specific
573directory where the file was found. If you *do not* want that, add the logical 573directory where the file was found. If you *do not* want that, add the logical
574name to this list as a string.") 574name to this list as a string.")
575 575
576(defun find-buffer-visiting (filename)
577 "Return the buffer visiting file FILENAME (a string).
578This is like `get-file-buffer', except that it checks for any buffer
579visiting the same file, possibly under a different name.
580If there is no such live buffer, return nil."
581 (let ((buf (get-file-buffer filename))
582 (truename (abbreviate-file-name (file-truename filename))))
583 (or buf
584 (let ((list (buffer-list)) found)
585 (while (and (not found) list)
586 (save-excursion
587 (set-buffer (car list))
588 (if (and buffer-file-name
589 (string= buffer-file-truename truename))
590 (setq found (car list))))
591 (setq list (cdr list)))
592 found)
593 (let ((number (nthcdr 10 (file-attributes )))
594 (list (buffer-list)) found)
595 (while (and (not found) list)
596 (save-excursion
597 (set-buffer (car list))
598 (if (and (equal buffer-file-number number)
599 ;; Verify this buffer's file number
600 ;; still belongs to its file.
601 (file-exists-p buffer-file-name)
602 (equal (nthcdr 10 (file-attributes buffer-file-name))
603 number))
604 (setq found (car list))))
605 (setq list (cdr list)))
606 found))))
607
576(defun find-file-noselect (filename &optional nowarn) 608(defun find-file-noselect (filename &optional nowarn)
577 "Read file FILENAME into a buffer and return the buffer. 609 "Read file FILENAME into a buffer and return the buffer.
578If a buffer exists visiting FILENAME, return that one, but 610If a buffer exists visiting FILENAME, return that one, but
@@ -589,47 +621,16 @@ The buffer is not selected, just returned to the caller."
589 (truename (abbreviate-file-name (file-truename filename))) 621 (truename (abbreviate-file-name (file-truename filename)))
590 (number (nthcdr 10 (file-attributes truename))) 622 (number (nthcdr 10 (file-attributes truename)))
591 ;; Find any buffer for a file which has same truename. 623 ;; Find any buffer for a file which has same truename.
592 (same-truename 624 (other (and (not buf) (find-buffer-visiting filename)))
593 (or buf ; Shortcut
594 (let (found
595 (list (buffer-list)))
596 (while (and (not found) list)
597 (save-excursion
598 (set-buffer (car list))
599 (if (and buffer-file-name
600 (string= buffer-file-truename truename))
601 (setq found (car list))))
602 (setq list (cdr list)))
603 found)))
604 (same-number
605 (or buf ; Shortcut
606 (and number
607 (let (found
608 (list (buffer-list)))
609 (while (and (not found) list)
610 (save-excursion
611 (set-buffer (car list))
612 (if (and (equal buffer-file-number number)
613 ;; Verify this buffer's file number
614 ;; still belongs to its file.
615 (file-exists-p buffer-file-name)
616 (equal (nthcdr 10 (file-attributes buffer-file-name)) number))
617 (setq found (car list))))
618 (setq list (cdr list)))
619 found))))
620 error) 625 error)
621 ;; Let user know if there is a buffer with the same truename. 626 ;; Let user know if there is a buffer with the same truename.
622 (if (and (not buf) same-truename (not nowarn)) 627 (if other
623 (message "%s and %s are the same file (%s)" 628 (progn
624 filename (buffer-file-name same-truename) 629 (or nowarn (message "%s and %s are the same file"
625 truename) 630 filename (buffer-file-name other)))
626 (if (and (not buf) same-number (not nowarn)) 631 ;; Optionally also find that buffer.
627 (message "%s and %s are the same file" 632 (if (or find-file-existing-other-name find-file-visit-truename)
628 filename (buffer-file-name same-number)))) 633 (setq buf other))))
629
630 ;; Optionally also find that buffer.
631 (if (or find-file-existing-other-name find-file-visit-truename)
632 (setq buf (or same-truename same-number)))
633 (if buf 634 (if buf
634 (or nowarn 635 (or nowarn
635 (verify-visited-file-modtime buf) 636 (verify-visited-file-modtime buf)
@@ -669,7 +670,7 @@ The buffer is not selected, just returned to the caller."
669 t)))) 670 t))))
670 (setq hooks (cdr hooks)))))) 671 (setq hooks (cdr hooks))))))
671 ;; Find the file's truename, and maybe use that as visited name. 672 ;; Find the file's truename, and maybe use that as visited name.
672 (setq buffer-file-truename (abbreviate-file-name truename)) 673 (setq buffer-file-truename truename)
673 (setq buffer-file-number number) 674 (setq buffer-file-number number)
674 ;; On VMS, we may want to remember which directory in a search list 675 ;; On VMS, we may want to remember which directory in a search list
675 ;; the file was found in. 676 ;; the file was found in.