Function: compilation-internal-error-properties

compilation-internal-error-properties is a byte-compiled function defined in compile.el.gz.

Signature

(compilation-internal-error-properties FILE LINE END-LINE COL END-COL TYPE FMTS RULE)

Documentation

Get the meta-info that will be added as text-properties.

LINE, END-LINE, COL, END-COL are integers or nil. TYPE can be 0, 1, or 2, meaning error, warning, or just info. FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME) or (BUFFER) or nil. FMTS is a list of format specs for transforming the file name. RULE is the name (symbol) of the rule used or nil if anonymous.
 (See compilation-error-regexp-alist.)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/compile.el.gz
(defun compilation-internal-error-properties (file line end-line col end-col
                                              type fmts rule)
  "Get the meta-info that will be added as text-properties.
LINE, END-LINE, COL, END-COL are integers or nil.
TYPE can be 0, 1, or 2, meaning error, warning, or just info.
FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME) or (BUFFER) or
nil.
FMTS is a list of format specs for transforming the file name.
RULE is the name (symbol) of the rule used or nil if anonymous.
 (See `compilation-error-regexp-alist'.)"
  (unless file (setq file '("*unknown*")))
  (let* ((file-struct (compilation-get-file-structure file fmts))
	 ;; Get first already existing marker (if any has one, all have one).
	 ;; Do this first, as the compilation-assq's may create new nodes.
	 (marker-line	; a line structure
          (cadr (compilation--file-struct->loc-tree file-struct)))
	 (marker
          (if marker-line (compilation--loc->marker (cadr marker-line))))
	 (screen-columns compilation-error-screen-columns)
	 (first-column compilation-first-column)
	 end-marker loc end-loc)
    (if (not (and marker (marker-buffer marker)))
	(setq marker nil)		; no valid marker for this file
      (unless line (setq line 1))       ; normalize no linenumber to line 1
      (catch 'marker			; find nearest loc, at least one exists
	(dolist (x (cddr (compilation--file-struct->loc-tree
                          file-struct)))	; Loop over remaining lines.
	  (if (> (car x) line)		; Still bigger.
	      (setq marker-line x)
	    (if (> (- (or (car marker-line) 1) line)
		   (- line (car x)))	; Current line is nearer.
		(setq marker-line x))
	    (throw 'marker t))))
      (setq marker (compilation--loc->marker (cadr marker-line))
	    marker-line (or (car marker-line) 1))
      (with-current-buffer (marker-buffer marker)
        (let ((screen-columns
               ;; Obey the compilation-error-screen-columns of the target
               ;; buffer if its major mode set it buffer-locally.
               (if (local-variable-p 'compilation-error-screen-columns)
                   compilation-error-screen-columns screen-columns))
	      (compilation-first-column
               (if (local-variable-p 'compilation-first-column)
                   compilation-first-column first-column)))
          (save-excursion
	  (save-restriction
	    (widen)
	    (goto-char (marker-position marker))
	    ;; Set end-marker if appropriate and go to line.
	    (if (not (or end-col end-line))
		(compilation-beginning-of-line (- line marker-line -1))
	      (compilation-beginning-of-line (- (or end-line line)
                                                marker-line -1))
	      (if (or (null end-col) (< end-col 0))
		  (end-of-line)
		(compilation-move-to-column end-col screen-columns))
	      (setq end-marker (point-marker))
	      (when end-line
                (compilation-beginning-of-line (- line end-line -1))))
	    (if col
		(compilation-move-to-column col screen-columns)
	      (forward-to-indentation 0))
	    (setq marker (point-marker)))))))

    (setq loc (compilation-assq line (compilation--file-struct->loc-tree
                                      file-struct)))
    (setq end-loc
          (if end-line
              (compilation-assq
               end-col (compilation-assq
                        end-line (compilation--file-struct->loc-tree
                                  file-struct)))
            (if end-col			; use same line element
                (compilation-assq end-col loc))))
    (setq loc (compilation-assq col loc))
    ;; If they are new, make the loc(s) reference the file they point to.
    ;; FIXME-omake: there's a problem with timestamps here: the markers
    ;; relative to which we computed the current `marker' have a timestamp
    ;; almost guaranteed to be different from compilation-buffer-modtime, so if
    ;; we use their timestamp, we'll never use `loc' since the timestamp won't
    ;; match compilation-buffer-modtime, and if we use
    ;; compilation-buffer-modtime then we have different timestamps for
    ;; locations that were computed together, which doesn't make sense either.
    ;; I think this points to a fundamental problem in our approach to the
    ;; "omake -P" problem.  --Stef
    (or (cdr loc)
        (setcdr loc (compilation--make-cdrloc line file-struct marker)))
    (if end-loc
	(or (cdr end-loc)
	    (setcdr end-loc
                    (compilation--make-cdrloc (or end-line line) file-struct
                                              end-marker))))

    ;; Must start with face
    `(font-lock-face ,compilation-message-face
      compilation-message ,(compilation--make-message loc type end-loc rule)
      help-echo ,(if col
                     "mouse-2: visit this file, line and column"
                   (if line
                       "mouse-2: visit this file and line"
                     "mouse-2: visit this file"))
      keymap compilation-button-map
      mouse-face highlight)))