From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ivan Sokolov Newsgroups: gmane.emacs.bugs Subject: bug#49609: [PATCH] Add option for handling SGR control sequences in compilation-mode Date: Sat, 17 Jul 2021 22:48:43 +0300 Message-ID: <877dhooh5w.fsf@ya.ru> References: <87a6mkohob.fsf@ya.ru> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18667"; mail-complaints-to="usenet@ciao.gmane.io" To: 49609@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 17 21:49:11 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m4qJD-0004gD-MV for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 17 Jul 2021 21:49:11 +0200 Original-Received: from localhost ([::1]:53202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m4qJB-0006LT-MZ for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 17 Jul 2021 15:49:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40376) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m4qJ4-0006K6-CR for bug-gnu-emacs@gnu.org; Sat, 17 Jul 2021 15:49:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:43099) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m4qJ4-0002Oy-3V for bug-gnu-emacs@gnu.org; Sat, 17 Jul 2021 15:49:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m4qJ3-000682-UJ for bug-gnu-emacs@gnu.org; Sat, 17 Jul 2021 15:49:01 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <87a6mkohob.fsf@ya.ru> Resent-From: Ivan Sokolov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 17 Jul 2021 19:49:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49609 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 49609-submit@debbugs.gnu.org id=B49609.162655133723547 (code B ref 49609); Sat, 17 Jul 2021 19:49:01 +0000 Original-Received: (at 49609) by debbugs.gnu.org; 17 Jul 2021 19:48:57 +0000 Original-Received: from localhost ([127.0.0.1]:54645 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m4qIy-00067j-Nl for submit@debbugs.gnu.org; Sat, 17 Jul 2021 15:48:56 -0400 Original-Received: from forward101j.mail.yandex.net ([5.45.198.241]:57478) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m4qIu-00067S-Ds for 49609@debbugs.gnu.org; Sat, 17 Jul 2021 15:48:55 -0400 Original-Received: from sas1-e6291564df6f.qloud-c.yandex.net (sas1-e6291564df6f.qloud-c.yandex.net [IPv6:2a02:6b8:c08:1f2f:0:640:e629:1564]) by forward101j.mail.yandex.net (Yandex) with ESMTP id B14971BE06B3 for <49609@debbugs.gnu.org>; Sat, 17 Jul 2021 22:48:45 +0300 (MSK) Original-Received: from sas2-e7f6fb703652.qloud-c.yandex.net (sas2-e7f6fb703652.qloud-c.yandex.net [2a02:6b8:c14:4fa6:0:640:e7f6:fb70]) by sas1-e6291564df6f.qloud-c.yandex.net (mxback/Yandex) with ESMTP id LIAgOOnQDw-mjHi9fCB; Sat, 17 Jul 2021 22:48:45 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ya.ru; s=mail; t=1626551325; bh=JJJ4qrI0gw1CJnW0zIBlefV99/VnT0DibqegnaILIrA=; h=Message-ID:Date:Subject:To:From; b=qj6md7D9qEAvVB6eFB3Yuhpr2cfBpOSB/wgbUBltsxZsIPRXt2iAtlnEcn4dYZQp4 vVDc6OFUJnxJhffQNqIGJGMEC/QTb2wzmpP23mHFclh1VYhpGYZdBKBLGyFA9x32HM C1KdhLeg3zWFBjwjpWAtEre5XRabC74Hi+I8ai2k= Authentication-Results: sas1-e6291564df6f.qloud-c.yandex.net; dkim=pass header.i=@ya.ru Original-Received: by sas2-e7f6fb703652.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id gzQSinJRVw-mj247bFl; Sat, 17 Jul 2021 22:48:45 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:210146 Archived-At: --=-=-= Content-Type: text/plain I don't have much to say about the patch -- it's a well known solution, I don't know why we don't have it yet. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Add-option-for-handling-SGR-control-sequences-in-com.patch >From e41f7bfa24c0fac575ebd7513ea5c527aa4c38ac Mon Sep 17 00:00:00 2001 From: Ivan Sokolov Date: Sat, 17 Jul 2021 21:56:37 +0300 Subject: [PATCH] Add option for handling SGR control sequences in compilation-mode --- lisp/ansi-color.el | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lisp/ansi-color.el b/lisp/ansi-color.el index 44dc0351d4..013f2a8c5d 100644 --- a/lisp/ansi-color.el +++ b/lisp/ansi-color.el @@ -75,6 +75,7 @@ ;;; Code: (defvar comint-last-output-start) +(defvar compilation-filter-start) ;; Customization @@ -181,6 +182,21 @@ ansi-color-for-comint-mode :group 'ansi-colors :version "23.2") +(defcustom ansi-color-for-compilation-mode t + "Determines what to do with compilation output. +If nil, do nothing. +If the symbol `filter', then filter all SGR control sequences. +If anything else (such as t), then translate SGR control sequences +into text properties. + +In order for this to have any effect, `ansi-color-compilation-filter' +must be in `compilation-filter-hook'." + :type '(choice (const :tag "Do nothing" nil) + (const :tag "Filter" filter) + (other :tag "Translate" t)) + :group 'ansi-colors + :version "28.1") + (defvar ansi-color-apply-face-function #'ansi-color-apply-overlay-face "Function for applying an Ansi Color face to text in a buffer. This function should accept three arguments: BEG, END, and FACE, @@ -228,6 +244,22 @@ ansi-color-process-output (t (ansi-color-apply-on-region start-marker end-marker))))) +;;;###autoload +(defun ansi-color-compilation-filter () + "Maybe translate SGR control sequences into text properties. +Depending on variable `ansi-color-for-compilation-mode' the +compilation output is either nor processed, SGR control sequences +are filtered using `ansi-color-filter-region', or SGR control +sequences are translated into text properties using +`ansi-color-apply-on-region'." + (let ((inhibit-read-only t)) + (pcase ansi-color-for-compilation-mode + ('nil nil) + ('filter + (ansi-color-filter-region compilation-filter-start (point))) + (_ + (ansi-color-apply-on-region compilation-filter-start (point)))))) + (define-obsolete-function-alias 'ansi-color-unfontify-region 'font-lock-default-unfontify-region "24.1") -- 2.32.0 --=-=-=--