Function: compilation-get-file-structure

compilation-get-file-structure is a byte-compiled function defined in compile.el.gz.

Signature

(compilation-get-file-structure FILE &optional FMT)

Documentation

Retrieve FILE's file-structure or create a new one.

FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME). In the former case, FILENAME may be relative or absolute.

The file-structure looks like this:
  ((FILENAME [TRUE-DIRNAME]) FMT ...)

TRUE-DIRNAME is the file-truename of DIRNAME, if given.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/compile.el.gz
(defun compilation-get-file-structure (file &optional fmt)
  "Retrieve FILE's file-structure or create a new one.
FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
In the former case, FILENAME may be relative or absolute.

The file-structure looks like this:
  ((FILENAME [TRUE-DIRNAME]) FMT ...)

TRUE-DIRNAME is the `file-truename' of DIRNAME, if given."
  (or (gethash file compilation-locs)
      ;; File was not previously encountered, at least not in the form passed.
      ;; Let's normalize it and look again.
      (let ((filename (car file))
	    ;; Get the specified directory from FILE.
	    (spec-directory
             (if (cdr file)
		 (file-truename (concat comint-file-name-prefix (cdr file))))))

	;; Check for a comint-file-name-prefix and prepend it if appropriate.
	;; (This is very useful for compilation-minor-mode in an rlogin-mode
	;; buffer.)
	(if (file-name-absolute-p filename)
	    (setq filename (concat comint-file-name-prefix filename)))

	;; If compilation-parse-errors-filename-function is
	;; defined, use it to process the filename.  The result might be a
	;; buffer.
	(unless (memq compilation-parse-errors-filename-function
                      '(nil identity))
          (save-match-data
	    (setq filename
		  (funcall compilation-parse-errors-filename-function
			   filename))))

	;; Some compilers (e.g. Sun's java compiler, reportedly) produce bogus
	;; file names like "./bar//foo.c" for file "bar/foo.c";
	;; expand-file-name will collapse these into "/foo.c" and fail to find
	;; the appropriate file.  So we look for doubled slashes in the file
	;; name and fix them.
	(if (stringp filename)
            (setq filename (command-line-normalize-file-name filename)))

	;; Store it for the possibly unnormalized name
	(puthash file
		 ;; Retrieve or create file-structure for normalized name
		 ;; The gethash used to not use spec-directory, but
		 ;; this leads to errors when files in different
		 ;; directories have the same name:
		 ;; https://lists.gnu.org/r/emacs-devel/2007-08/msg00463.html
		 (or (gethash (cons filename spec-directory) compilation-locs)
		     (puthash (cons filename spec-directory)
			      (compilation--make-file-struct
                               (list filename spec-directory) fmt)
			      compilation-locs))
		 compilation-locs))))