diff options
| author | Ivan Sokolov | 2021-07-19 18:54:18 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2021-07-19 18:54:23 +0200 |
| commit | f7f2024b86bdcf028ce942e59d1cfdba89747d0b (patch) | |
| tree | 3f86faedc8bc954c3645fd8b6d9c1d0a53a0583f | |
| parent | 0c48469ac11ea0120d050b79072a6dcb1798d2e0 (diff) | |
| download | emacs-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/NEWS | 8 | ||||
| -rw-r--r-- | lisp/ansi-color.el | 32 |
2 files changed, 40 insertions, 0 deletions
| @@ -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'. | ||
| 1606 | This function is meant to be used in 'compilation-filter-hook'. | ||
| 1607 | |||
| 1608 | --- | ||
| 1609 | *** New user option 'ansi-color-for-compilation-mode'. | ||
| 1610 | This 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. |
| 1605 | The variable 'compilation-error-case-fold-search' can be set for | 1613 | The variable 'compilation-error-case-fold-search' can be set for |
| 1606 | case-insensitive matching of messages when the old behavior is | 1614 | case-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. | ||
| 187 | If nil, do nothing. | ||
| 188 | |||
| 189 | If the symbol `filter', then filter all ANSI graphical control | ||
| 190 | sequences. | ||
| 191 | |||
| 192 | If anything else (such as t), then translate ANSI graphical | ||
| 193 | control sequences into text properties. | ||
| 194 | |||
| 195 | In order for this to have any effect, `ansi-color-compilation-filter' | ||
| 196 | must 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. |
| 186 | This function should accept three arguments: BEG, END, and FACE, | 205 | This 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. | ||
| 253 | This function depends on the `ansi-color-for-compilation-mode' | ||
| 254 | variable, 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 | ||