- (if find-file-run-dired
- (dired-noselect (if find-file-visit-truename
- (abbreviate-file-name (file-truename filename))
- filename))
- (error "%s is a directory" filename))
- (let* ((buf (get-file-buffer filename))
- (truename (abbreviate-file-name (file-truename filename)))
- (number (nthcdr 10 (file-attributes truename)))
- ;; Find any buffer for a file which has same truename.
- (other (and (not buf) (find-buffer-visiting filename)))
- error)
- ;; Let user know if there is a buffer with the same truename.
- (if other
- (progn
- (or nowarn
- (string-equal filename (buffer-file-name other))
- (message "%s and %s are the same file"
- filename (buffer-file-name other)))
- ;; Optionally also find that buffer.
- (if (or find-file-existing-other-name find-file-visit-truename)
- (setq buf other))))
- (if buf
- (or nowarn
- (verify-visited-file-modtime buf)
- (cond ((not (file-exists-p filename))
- (error "File %s no longer exists!" filename))
- ;; Certain files should be reverted automatically
- ;; if they have changed on disk and not in the buffer.
- ((and (not (buffer-modified-p buf))
- (let ((tail revert-without-query)
- (found nil))
- (while tail
- (if (string-match (car tail) filename)
- (setq found t))
- (setq tail (cdr tail)))
- found))
- (with-current-buffer buf
- (message "Reverting file %s..." filename)
- (revert-buffer t t)
- (message "Reverting file %s...done" filename)))
- ((yes-or-no-p
- (if (string= (file-name-nondirectory filename)
- (buffer-name buf))
- (format
- (if (buffer-modified-p buf)
- "File %s changed on disk. Discard your edits? "
- "File %s changed on disk. Reread from disk? ")
- (file-name-nondirectory filename))
- (format
- (if (buffer-modified-p buf)
- "File %s changed on disk. Discard your edits in %s? "
- "File %s changed on disk. Reread from disk into %s? ")
- (file-name-nondirectory filename)
- (buffer-name buf))))
- (with-current-buffer buf
- (revert-buffer t t)))
- ((not (eq rawfile (not (null find-file-literally))))
- (if rawfile
- (message "File is already visited, and not literally")
- (message "File is already visited, and visited literally")))))
- (save-excursion
-;;; The truename stuff makes this obsolete.
-;;; (let* ((link-name (car (file-attributes filename)))
-;;; (linked-buf (and (stringp link-name)
-;;; (get-file-buffer link-name))))
-;;; (if (bufferp linked-buf)
-;;; (message "Symbolic link to file in buffer %s"
-;;; (buffer-name linked-buf))))
+ (or (and find-file-run-dired
+ (run-hook-with-args-until-success
+ 'find-directory-functions
+ (if find-file-visit-truename
+ (abbreviate-file-name (file-truename filename))
+ filename)))
+ (error "%s is a directory" filename))
+ (if (and wildcards
+ find-file-wildcards
+ (not (string-match "\\`/:" filename))
+ (string-match "[[*?]" filename))
+ (let ((files (condition-case nil
+ (file-expand-wildcards filename t)
+ (error (list filename))))
+ (find-file-wildcards nil))
+ (if (null files)
+ (find-file-noselect filename)
+ (car (mapcar #'find-file-noselect files))))
+ (let* ((buf (get-file-buffer filename))
+ (truename (abbreviate-file-name (file-truename filename)))
+ (number (nthcdr 10 (file-attributes truename)))
+ ;; Find any buffer for a file which has same truename.
+ (other (and (not buf) (find-buffer-visiting filename))))
+ ;; Let user know if there is a buffer with the same truename.
+ (if other
+ (progn
+ (or nowarn
+ (string-equal filename (buffer-file-name other))
+ (message "%s and %s are the same file"
+ filename (buffer-file-name other)))
+ ;; Optionally also find that buffer.
+ (if (or find-file-existing-other-name find-file-visit-truename)
+ (setq buf other))))
+ (if buf
+ ;; We are using an existing buffer.
+ (progn
+ (or nowarn
+ (verify-visited-file-modtime buf)
+ (cond ((not (file-exists-p filename))
+ (error "File %s no longer exists!" filename))
+ ;; Certain files should be reverted automatically
+ ;; if they have changed on disk and not in the buffer.
+ ((and (not (buffer-modified-p buf))
+ (let ((tail revert-without-query)
+ (found nil))
+ (while tail
+ (if (string-match (car tail) filename)
+ (setq found t))
+ (setq tail (cdr tail)))
+ found))
+ (with-current-buffer buf
+ (message "Reverting file %s..." filename)
+ (revert-buffer t t)
+ (message "Reverting file %s...done" filename)))
+ ((yes-or-no-p
+ (if (string= (file-name-nondirectory filename)
+ (buffer-name buf))
+ (format
+ (if (buffer-modified-p buf)
+ "File %s changed on disk. Discard your edits? "
+ "File %s changed on disk. Reread from disk? ")
+ (file-name-nondirectory filename))
+ (format
+ (if (buffer-modified-p buf)
+ "File %s changed on disk. Discard your edits in %s? "
+ "File %s changed on disk. Reread from disk into %s? ")
+ (file-name-nondirectory filename)
+ (buffer-name buf))))
+ (with-current-buffer buf
+ (revert-buffer t t)))))
+ (with-current-buffer buf
+ (when (not (eq (not (null rawfile))
+ (not (null find-file-literally))))
+ (if (buffer-modified-p)
+ (if (y-or-n-p (if rawfile
+ "Save file and revisit literally? "
+ "Save file and revisit non-literally? "))
+ (progn
+ (save-buffer)
+ (find-file-noselect-1 buf filename nowarn
+ rawfile truename number))
+ (if (y-or-n-p (if rawfile
+ "Discard your edits and revisit file literally? "
+ "Discard your edits and revisit file non-literally? "))
+ (find-file-noselect-1 buf filename nowarn
+ rawfile truename number)
+ (error (if rawfile "File already visited non-literally"
+ "File already visited literally"))))
+ (if (y-or-n-p (if rawfile
+ "Revisit file literally? "
+ "Revisit file non-literally? "))
+ (find-file-noselect-1 buf filename nowarn
+ rawfile truename number)
+ (error (if rawfile "File already visited non-literally"
+ "File already visited literally"))))))
+ ;; Return the buffer we are using.
+ buf)
+ ;; Create a new buffer.