Function: dired-goto-file

dired-goto-file is an interactive and byte-compiled function defined in dired.el.gz.

Signature

(dired-goto-file FILE)

Documentation

Go to line describing file FILE in this Dired buffer.

View in manual

Probably introduced at or before Emacs version 22.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/dired.el.gz
(defun dired-goto-file (file)
  "Go to line describing file FILE in this Dired buffer."
  ;; Return value of point on success, else nil.
  ;; FILE must be an absolute file name.
  ;; Loses if FILE contains control chars like "\007" for which ls
  ;; either inserts "?" or "\\007" into the buffer, so we won't find
  ;; it in the buffer.
  (interactive
   (prog1				; let push-mark display its message
       (list (expand-file-name
	      (read-file-name "Goto file: "
			      (dired-current-directory))))
     (push-mark)))
  (unless (file-name-absolute-p file)
    (error "File name `%s' is not absolute" file))
  (setq file (directory-file-name file)) ; does no harm if not a directory
  (let* ((case-fold-search nil)
	 (dir (file-name-directory file))
	 (found (or
		 ;; First, look for a listing under the absolute name.
		 (save-excursion
		   (goto-char (point-min))
		   (dired-goto-file-1 file file (point-max)))
                 ;; Next, look for it as a relative name with leading
                 ;; subdirectories.  (This happens in Dired buffers
                 ;; created by find-dired, for example.)
                 (save-excursion
                   (goto-char (point-min))
                   (dired-goto-file-1 (file-relative-name file
                                                          default-directory)
                                      file (point-max)))
		 ;; Otherwise, look for it as a relative name, a base
		 ;; name only.  The hair is to get the result of
		 ;; `dired-goto-subdir' without calling it if we don't
		 ;; have any subdirs.
		 (save-excursion
		   (when (if (string= dir (expand-file-name default-directory))
			     (goto-char (point-min))
			   (and (cdr dired-subdir-alist)
				(dired-goto-subdir dir)))
		     (dired-goto-file-1 (file-name-nondirectory file)
					file
					(dired-subdir-max)))))))
    ;; Return buffer position, if found.
    (if found
	(goto-char found))))