From e44b6e8d161dadbccdbeb9c72ed6d531dbf9cc40 Mon Sep 17 00:00:00 2001 From: Ulrich Müller Date: Wed, 30 Nov 2022 19:49:42 +0100 Subject: Filter SGR control sequences in compilation output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ebuild-mode.el (ebuild-compilation-mode): New mode for compilation buffers, filters SGR control sequences. (ebuild-log-buffer-mode): Default to it. (ebuild-mode-run-pkgdev, ebuild-mode-run-pkgcheck): Call compile with ebuild-log-buffer-mode. (ebuild-mode-process-environment): Don't set NOCOLOR if ansi-color is available. Signed-off-by: Ulrich Müller --- ChangeLog | 10 ++++++++++ ebuild-mode.el | 24 ++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5d5edf6..040b537 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2022-11-30 Ulrich Müller + + * ebuild-mode.el (ebuild-compilation-mode): New mode for + compilation buffers, filters SGR control sequences. + (ebuild-log-buffer-mode): Default to it. + (ebuild-mode-run-pkgdev, ebuild-mode-run-pkgcheck): Call compile + with ebuild-log-buffer-mode. + (ebuild-mode-process-environment): Don't set NOCOLOR if ansi-color + is available. + 2022-11-28 Ulrich Müller * ebuild-mode.el (ebuild-mode-ebuild-history) diff --git a/ebuild-mode.el b/ebuild-mode.el index 6bd2c80..dcc2e9a 100644 --- a/ebuild-mode.el +++ b/ebuild-mode.el @@ -121,7 +121,9 @@ If nil, use two spaces." :group 'ebuild) (defcustom ebuild-mode-process-environment - '("NOCOLOR=true") + (if (or (featurep 'xemacs) + (not (fboundp 'ansi-color-compilation-filter))) + '("NOCOLOR=true")) "List of additional environment variables for subprocesses. Each element should be a string of the form NAME=VALUE. This will be prepended to `process-environment' when calling a subprocess." @@ -407,7 +409,7 @@ of the elements." (defvar ebuild-mode-pkgdev-history nil) (defvar ebuild-mode-pkgcheck-history nil) -(defvar ebuild-log-buffer-mode nil +(defvar ebuild-log-buffer-mode 'ebuild-compilation-mode "Major mode for the log buffer of `ebuild-run-command'. If nil, `compilation-mode' will be used.") @@ -430,6 +432,16 @@ If nil, `compilation-mode' will be used.") (compile shell-command) (compile shell-command ebuild-log-buffer-mode)))) +(define-derived-mode ebuild-compilation-mode compilation-mode "Compilation" + "Like `compilation-mode' but with color support. +Translates ANSI graphical control sequences into text properties +(if the Emacs version supports it). +Variable `ansi-color-for-compilation-mode' must be non-nil for +this to have any effect." + (if (fboundp 'ansi-color-compilation-filter) + (add-hook 'compilation-filter-hook + 'ansi-color-compilation-filter nil t))) + (defun ebuild-mode-get-completion-function (mode) "Get completion function for completion mode MODE." (cond ((null mode) 'try-completion) @@ -494,7 +506,9 @@ Like `compile', but with autocompletion for pkgdev." (let ((process-environment (append ebuild-mode-process-environment process-environment)) (compilation-buffer-name-function (lambda (mode) "*pkgdev*"))) - (compile command))) + (if (featurep 'xemacs) + (compile command) + (compile command ebuild-log-buffer-mode)))) (defun ebuild-mode-run-pkgcheck (command) "Run pkgcheck COMMAND with output to a compilation buffer. @@ -507,7 +521,9 @@ Like `compile', but with autocompletion for pkgcheck." (let ((process-environment (append ebuild-mode-process-environment process-environment)) (compilation-buffer-name-function (lambda (mode) "*pkgcheck*"))) - (compile command))) + (if (featurep 'xemacs) + (compile command) + (compile command ebuild-log-buffer-mode)))) ;;; Modify package keywords. -- cgit v1.2.3-65-gdbad