From ed71839c33f9dad1de4bdf6911dafbe4a571136b Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 16 May 2022 15:30:50 +0200 Subject: [PATCH] Add new user option compilation-hidden-output * doc/emacs/building.texi (Compilation Mode): Document it. * lisp/progmodes/compile.el (compilation-hidden-output): New user option. (compilation-filter): Use it. (compilation--hide-output): New function. --- doc/emacs/building.texi | 13 ++++++++++++ etc/NEWS | 5 +++++ lisp/progmodes/compile.el | 43 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/doc/emacs/building.texi b/doc/emacs/building.texi index 8f972de568a..b79fa0a755c 100644 --- a/doc/emacs/building.texi +++ b/doc/emacs/building.texi @@ -289,6 +289,19 @@ window so that the current error message is @var{n} lines from the top, whether or not there is a fringe; the default value, @code{nil}, gives the behavior described above. +@vindex compilation-hidden-output + Compilation output can sometimes be very verbose, and much of it isn't +of particular interest to a user. The +@code{compilation-hidden-output} user option should either be a regexp +or a list of regexps, and output that matches will be made invisible. +For instance, to hide the verbose output from recursive makefiles, you +can say something like: + +@lisp +(setq compilation-hidden-output + '("^make[^\n]+\n")) +@end lisp + @vindex compilation-error-regexp-alist @vindex grep-regexp-alist To parse messages from the compiler, Compilation mode uses the diff --git a/etc/NEWS b/etc/NEWS index b5b23952867..630288d4316 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -898,6 +898,11 @@ which is a change in behaviour from previous Emacs versions. ** Compile ++++ +*** New user option 'compilation-hidden-output'. +This can be used to make specific parts of compilation output +invisible. + +++ *** The 'compilation-auto-jump-to-first-error' has been extended. It can now have the additional values 'if-location-known' (which will diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el index 5545b4cd4ad..fdcd4a22c07 100644 --- a/lisp/progmodes/compile.el +++ b/lisp/progmodes/compile.el @@ -82,6 +82,25 @@ after `call-process' inserts the grep output into the buffer.") "Position of the start of the text inserted by `compilation-filter'. This is bound before running `compilation-filter-hook'.") +(defcustom compilation-hidden-output nil + "Regexp to match output from the compilation that should be hidden. +This can also be a list of regexps. + +The text matched by this variable will be made invisible, which +means that it'll still be present in the buffer, so that +navigation commands (for instance, `next-error') can still make +use of the hidden text to determine the current directory and the +like. + +For instance, to hide the verbose output from recursive +makefiles, you can say something like: + + (setq compilation-hidden-output + \\='(\"^make[^\n]+\n\"))" + :type '(choice regexp + (repeat regexp)) + :version "29.1") + (defvar compilation-first-column 1 "This is how compilers number the first column, usually 1 or 0. If this is buffer-local in the destination buffer, Emacs obeys @@ -2441,8 +2460,8 @@ commands of Compilation major mode are available. See (defun compilation-filter (proc string) "Process filter for compilation buffers. -Just inserts the text, -handles carriage motion (see `comint-inhibit-carriage-motion'), +Just inserts the text, handles carriage motion (see +`comint-inhibit-carriage-motion'), `compilation-hidden-output', and runs `compilation-filter-hook'." (when (buffer-live-p (process-buffer proc)) (with-current-buffer (process-buffer proc) @@ -2467,6 +2486,8 @@ and runs `compilation-filter-hook'." (dolist (line (string-lines string nil t)) (compilation--insert-abbreviated-line line compilation-max-output-line-length))) + (when compilation-hidden-output + (compilation--hide-output compilation-filter-start)) (unless comint-inhibit-carriage-motion (comint-carriage-motion (process-mark proc) (point))) (set-marker (process-mark proc) (point)) @@ -2479,6 +2500,24 @@ and runs `compilation-filter-hook'." (set-marker min nil) (set-marker max nil)))))) +(defun compilation--hide-output (start) + (save-excursion + (goto-char start) + (beginning-of-line) + ;; Apply the match to each line, but wait until we have a complete + ;; line. + (let ((start (point))) + (while (search-forward "\n" nil t) + (save-restriction + (narrow-to-region start (point)) + (dolist (regexp (ensure-list compilation-hidden-output)) + (goto-char start) + (while (re-search-forward regexp nil t) + (add-text-properties (match-beginning 0) (match-end 0) + '( invisible t + rear-nonsticky t)))) + (goto-char (point-max))))))) + (defun compilation--insert-abbreviated-line (string width) (if (and (> (current-column) 0) (get-text-property (1- (point)) 'button)) -- 2.39.2