emacs-diffs
[Top][All Lists]
Advanced

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

master 58398dea25 3/3: Truncate output from grep


From: Lars Ingebrigtsen
Subject: master 58398dea25 3/3: Truncate output from grep
Date: Sat, 30 Apr 2022 06:57:28 -0400 (EDT)

branch: master
commit 58398dea254dcfdab58d5439061a513b48cfe895
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Truncate output from grep
    
    * doc/emacs/building.texi (Compilation): Document it.
    * lisp/progmodes/compile.el (compilation-max-output-line-length):
    New user option (bug#44983).
    (compilation-filter): Use it.
    (compilation--insert-abbreviated-line): New function.
---
 doc/emacs/building.texi   |  8 ++++++++
 etc/NEWS                  |  8 ++++++++
 lisp/progmodes/compile.el | 48 +++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/doc/emacs/building.texi b/doc/emacs/building.texi
index 5b68b1ef9f..5bf4c8c739 100644
--- a/doc/emacs/building.texi
+++ b/doc/emacs/building.texi
@@ -138,6 +138,14 @@ of environment variable settings; each element should be a 
string of
 the form @code{"@var{envvarname}=@var{value}"}.  These environment
 variable settings override the usual ones.
 
+@vindex compilation-max-output-line-length
+  Displaying extremely long lines in compilation output can slow Emacs
+down.  Lines that are longer than
+@code{compilation-max-output-line-length} will have the portion that's
+exceeds that limit hidden behind a button that can be clicked on to
+reveal the hidden portion.  Set this variable to @code{nil} to never
+hide anything.
+
 @node Compilation Mode
 @section Compilation Mode
 
diff --git a/etc/NEWS b/etc/NEWS
index 30882ed2fe..1c943bfd64 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -672,6 +672,14 @@ script that was used in ancient South Asia.  A new input 
method,
 
 * Changes in Specialized Modes and Packages in Emacs 29.1
 
+** Compile
+
++++
+*** New user option 'compilation-max-output-line-length'.
+Lines longer than this will have the ends hidden, with a button to
+reveal the hidden text.  This speeds up operations like grepping on
+files that have few newlines.
+
 ** Flymake
 
 +++
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index e75a44b653..a621779f8c 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -1752,6 +1752,13 @@ If nil, ask to kill it."
   :type 'boolean
   :version "24.3")
 
+(defcustom compilation-max-output-line-length 400
+  "Output lines that are longer than this value will be hidden.
+If nil, don't hide anything."
+  :type '(choice (const :tag "Hide nothing" nil)
+                 number)
+  :version "29.1")
+
 (defun compilation--update-in-progress-mode-line ()
   ;; `compilation-in-progress' affects the mode-line of all
   ;; buffers when it changes from nil to non-nil or vice-versa.
@@ -2426,13 +2433,16 @@ and runs `compilation-filter-hook'."
               ;; We used to use `insert-before-markers', so that windows with
               ;; point at `process-mark' scroll along with the output, but we
               ;; now use window-point-insertion-type instead.
-              (insert string)
+              (if (not compilation-max-output-line-length)
+                  (insert string)
+                (dolist (line (string-lines string nil t))
+                  (compilation--insert-abbreviated-line
+                   line compilation-max-output-line-length)))
               (unless comint-inhibit-carriage-motion
                 (comint-carriage-motion (process-mark proc) (point)))
               (set-marker (process-mark proc) (point))
               ;; Update the number of errors in compilation-mode-line-errors
               (compilation--ensure-parse (point))
-              ;; (setq-local compilation-buffer-modtime (current-time))
               (run-hooks 'compilation-filter-hook))
          (goto-char pos)
           (narrow-to-region min max)
@@ -2440,6 +2450,40 @@ and runs `compilation-filter-hook'."
          (set-marker min nil)
          (set-marker max nil))))))
 
+(defun compilation--insert-abbreviated-line (string width)
+  (if (and (> (current-column) 0)
+           (get-text-property (1- (point)) 'button))
+      ;; We already have an abbreviation; just add the string to it.
+      (let ((beg (point)))
+        (insert string)
+        (add-text-properties
+         beg
+         ;; Don't make the final newline invisible.
+         (if (= (aref string (1- (length string))) ?\n)
+             (1- (point))
+           (point))
+         (text-properties-at (1- beg))))
+    (insert string)
+    ;; If we exceeded the limit, hide the last portion of the line.
+    (when (> (current-column) width)
+      (let ((start (save-excursion
+                     (move-to-column width)
+                     (point))))
+        (buttonize-region
+         start (point)
+         (lambda (start)
+           (let ((inhibit-read-only t))
+             (remove-text-properties start (save-excursion
+                                             (goto-char start)
+                                             (line-end-position))
+                                     (text-properties-at start)))))
+        (put-text-property
+         start (if (= (aref string (1- (length string))) ?\n)
+                   ;; Don't hide the final newline.
+                   (1- (point))
+                 (point))
+         'display (if (char-displayable-p ?…) "[…]" "[...]"))))))
+
 (defsubst compilation-buffer-internal-p ()
   "Test if inside a compilation buffer."
   (local-variable-p 'compilation-locs))



reply via email to

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