Function: compilation-find-file-1

compilation-find-file-1 is a byte-compiled function defined in compile.el.gz.

Signature

(compilation-find-file-1 MARKER FILENAME DIRECTORY &optional FORMATS)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/compile.el.gz
(defun compilation-find-file-1 (marker filename directory &optional formats)
  (or formats (setq formats '("%s")))
  (let ((dirs compilation-search-path)
        (spec-dir (if directory
                      (expand-file-name directory)
                    default-directory))
        buffer thisdir fmts name)
    (if (and filename
             (file-name-absolute-p filename))
        ;; The file name is absolute.  Use its explicit directory as
        ;; the first in the search path, and strip it from FILENAME.
        (setq filename (abbreviate-file-name (expand-file-name filename))
              dirs (cons (file-name-directory filename) dirs)
              filename (file-name-nondirectory filename)))
    ;; Now search the path.
    (while (and dirs (null buffer))
      (setq thisdir (or (car dirs) spec-dir)
            fmts formats)
      ;; For each directory, try each format string.
      (while (and fmts (null buffer))
        (setq name (file-truename
                    (file-name-concat thisdir (format (car fmts) filename)))
              buffer (and (file-exists-p name)
                          (find-file-noselect name))
              fmts (cdr fmts)))
      (setq dirs (cdr dirs)))
    ;; If we haven't found it, this might be a parallel build.
    ;; Search the directories further up the buffer.
    (when (and (null buffer)
               compilation-search-all-directories)
      (with-current-buffer (marker-buffer marker)
        (save-excursion
          (goto-char (marker-position marker))
          (when-let ((prev (compilation--previous-directory (point))))
            (goto-char prev))
          (setq dirs (cdr (or (get-text-property
                               (1- (point)) 'compilation-directory)
                              (get-text-property
                               (point) 'compilation-directory))))))
      (while (and dirs (null buffer))
        (setq thisdir (car dirs)
              fmts formats)
        (while (and fmts (null buffer))
          (setq name (file-truename
                      (file-name-concat thisdir (format (car fmts) filename)))
                buffer (and (file-exists-p name)
                            (find-file-noselect name))
                fmts (cdr fmts)))
        (setq dirs (cdr dirs))))
    (list buffer spec-dir)))