emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master b699c380286 1/2: Introduce 'compilation-annotation' text property


From: Juri Linkov
Subject: master b699c380286 1/2: Introduce 'compilation-annotation' text property
Date: Mon, 27 Feb 2023 14:15:49 -0500 (EST)

branch: master
commit b699c380286151c97ffae65010d733a092d2db14
Author: Augusto Stoffel <arstoffel@gmail.com>
Commit: Juri Linkov <juri@linkov.net>

    Introduce 'compilation-annotation' text property
    
    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 | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index ccf64fb670b..6d151db8a83 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]