]> git.eshelyaron.com Git - emacs.git/commitdiff
Introduce 'compilation-annotation' text property
authorAugusto Stoffel <arstoffel@gmail.com>
Thu, 8 Dec 2022 20:05:10 +0000 (21:05 +0100)
committerJuri Linkov <juri@linkov.net>
Mon, 27 Feb 2023 19:14:41 +0000 (21:14 +0200)
It is meant to mark parts of compilation buffers which do not
correspond to process output (bug#59888).

* lisp/progmodes/compile.el (compilation-insert-annotation): New
function.
(compilation-start, compilation-handle-exit): Use it.
(compilation--ensure-parse) Rely on 'compilation-annotation' property
instead of 'compilation-header-end'.

lisp/progmodes/compile.el

index ccf64fb670b86307e908d8ad1321cfc664501b89..6d151db8a8372ded3b6dd3f087f92d5f70cfe309 100644 (file)
@@ -1706,7 +1706,7 @@ to `compilation-error-regexp-alist' if RULES is nil."
             (set-marker (make-marker)
                         (save-excursion
                           (goto-char (point-min))
-                          (text-property-search-forward 'compilation-header-end)
+                          (text-property-search-forward 'compilation-annotation)
                           ;; If we have no end marker, this will be
                           ;; `point-min' still.
                           (point)))))
@@ -1854,6 +1854,14 @@ If nil, don't hide anything."
   ;; buffers when it changes from nil to non-nil or vice-versa.
   (unless compilation-in-progress (force-mode-line-update t)))
 
+(defun compilation-insert-annotation (&rest args)
+  "Insert ARGS at point, adding the `compilation-annotation' text property.
+This property is used to distinguish output of the compilation
+process from additional information inserted by Emacs."
+  (let ((start (point)))
+    (apply #'insert args)
+    (put-text-property start (point) 'compilation-annotation t)))
+
 ;;;###autoload
 (defun compilation-start (command &optional mode name-function highlight-regexp
                                   continue)
@@ -1975,17 +1983,16 @@ Returns the compilation buffer created."
             (setq-local compilation-auto-jump-to-next t))
         (when (zerop (buffer-size))
          ;; Output a mode setter, for saving and later reloading this buffer.
-         (insert "-*- mode: " name-of-mode
-                 "; default-directory: "
-                  (prin1-to-string (abbreviate-file-name default-directory))
-                 " -*-\n"))
-        (insert (format "%s started at %s\n\n"
-                       mode-name
-                       (substring (current-time-string) 0 19))
-               command "\n")
-        ;; Mark the end of the header so that we don't interpret
-        ;; anything in it as an error.
-        (put-text-property (1- (point)) (point) 'compilation-header-end t)
+         (compilation-insert-annotation
+           "-*- mode: " name-of-mode
+           "; default-directory: "
+           (prin1-to-string (abbreviate-file-name default-directory))
+          " -*-\n"))
+        (compilation-insert-annotation
+         (format "%s started at %s\n\n"
+                 mode-name
+                (substring (current-time-string) 0 19))
+        command "\n")
        (setq thisdir default-directory))
       (set-buffer-modified-p nil))
     ;; Pop up the compilation buffer.
@@ -2467,13 +2474,13 @@ commands of Compilation major mode are available.  See
        (cur-buffer (current-buffer)))
     ;; Record where we put the message, so we can ignore it later on.
     (goto-char omax)
-    (insert ?\n mode-name " " (car status))
+    (compilation-insert-annotation ?\n mode-name " " (car status))
     (if (and (numberp compilation-window-height)
             (zerop compilation-window-height))
        (message "%s" (cdr status)))
     (if (bolp)
        (forward-char -1))
-    (insert " at " (substring (current-time-string) 0 19))
+    (compilation-insert-annotation " at " (substring (current-time-string) 0 19))
     (goto-char (point-max))
     ;; Prevent that message from being recognized as a compilation error.
     (add-text-properties omax (point)