aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Sokolov2021-07-19 18:54:18 +0200
committerLars Ingebrigtsen2021-07-19 18:54:23 +0200
commitf7f2024b86bdcf028ce942e59d1cfdba89747d0b (patch)
tree3f86faedc8bc954c3645fd8b6d9c1d0a53a0583f
parent0c48469ac11ea0120d050b79072a6dcb1798d2e0 (diff)
downloademacs-f7f2024b86bdcf028ce942e59d1cfdba89747d0b.tar.gz
emacs-f7f2024b86bdcf028ce942e59d1cfdba89747d0b.zip
Add function for filtering ANSI sequences when compiling
* lisp/ansi-color.el (ansi-color-for-compilation-mode): New user option (bug#49609). (ansi-color-compilation-filter): New function.
-rw-r--r--etc/NEWS8
-rw-r--r--lisp/ansi-color.el32
2 files changed, 40 insertions, 0 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 0c90683c767..7bf42330b9d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1601,6 +1601,14 @@ Defaults to 'libravatar', with 'unicornify' and 'gravatar' as options.
1601 1601
1602** Compilation mode 1602** Compilation mode
1603 1603
1604---
1605*** New function 'ansi-color-compilation-filter'.
1606This function is meant to be used in 'compilation-filter-hook'.
1607
1608---
1609*** New user option 'ansi-color-for-compilation-mode'.
1610This controls what 'ansi-color-compilation-filter' does.
1611
1604*** Regexp matching of messages is now case-sensitive by default. 1612*** Regexp matching of messages is now case-sensitive by default.
1605The variable 'compilation-error-case-fold-search' can be set for 1613The variable 'compilation-error-case-fold-search' can be set for
1606case-insensitive matching of messages when the old behavior is 1614case-insensitive matching of messages when the old behavior is
diff --git a/lisp/ansi-color.el b/lisp/ansi-color.el
index 44dc0351d45..79dc821ea19 100644
--- a/lisp/ansi-color.el
+++ b/lisp/ansi-color.el
@@ -75,6 +75,7 @@
75;;; Code: 75;;; Code:
76 76
77(defvar comint-last-output-start) 77(defvar comint-last-output-start)
78(defvar compilation-filter-start)
78 79
79;; Customization 80;; Customization
80 81
@@ -181,6 +182,24 @@ in shell buffers. You set this variable by calling one of:
181 :group 'ansi-colors 182 :group 'ansi-colors
182 :version "23.2") 183 :version "23.2")
183 184
185(defcustom ansi-color-for-compilation-mode t
186 "Determines what to do with compilation output.
187If nil, do nothing.
188
189If the symbol `filter', then filter all ANSI graphical control
190sequences.
191
192If anything else (such as t), then translate ANSI graphical
193control sequences into text properties.
194
195In order for this to have any effect, `ansi-color-compilation-filter'
196must be in `compilation-filter-hook'."
197 :type '(choice (const :tag "Do nothing" nil)
198 (const :tag "Filter" filter)
199 (other :tag "Translate" t))
200 :group 'ansi-colors
201 :version "28.1")
202
184(defvar ansi-color-apply-face-function #'ansi-color-apply-overlay-face 203(defvar ansi-color-apply-face-function #'ansi-color-apply-overlay-face
185 "Function for applying an Ansi Color face to text in a buffer. 204 "Function for applying an Ansi Color face to text in a buffer.
186This function should accept three arguments: BEG, END, and FACE, 205This function should accept three arguments: BEG, END, and FACE,
@@ -228,6 +247,19 @@ This is a good function to put in `comint-output-filter-functions'."
228 (t 247 (t
229 (ansi-color-apply-on-region start-marker end-marker))))) 248 (ansi-color-apply-on-region start-marker end-marker)))))
230 249
250;;;###autoload
251(defun ansi-color-compilation-filter ()
252 "Maybe translate SGR control sequences into text properties.
253This function depends on the `ansi-color-for-compilation-mode'
254variable, and is meant to be used in `compilation-filter-hook'."
255 (let ((inhibit-read-only t))
256 (pcase ansi-color-for-compilation-mode
257 ('nil nil)
258 ('filter
259 (ansi-color-filter-region compilation-filter-start (point)))
260 (_
261 (ansi-color-apply-on-region compilation-filter-start (point))))))
262
231(define-obsolete-function-alias 'ansi-color-unfontify-region 263(define-obsolete-function-alias 'ansi-color-unfontify-region
232 'font-lock-default-unfontify-region "24.1") 264 'font-lock-default-unfontify-region "24.1")
233 265