From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Robert Pluim Newsgroups: gmane.emacs.bugs Subject: bug#59888: [PATCH] Add 'grep-use-headings' Date: Sun, 26 Feb 2023 14:17:17 +0100 Message-ID: <87cz5w7ehu.fsf@gmail.com> References: <87v8mndrla.fsf@gmail.com> <87ilime025.fsf@gmail.com> <86359pm55x.fsf@mail.linkov.net> <87o7scdb45.fsf_-_@gmail.com> <837cz0z7wj.fsf@gnu.org> <87k0301h16.fsf@gmail.com> <831qp8z5gp.fsf@gnu.org> <87sfhn3tui.fsf@gmail.com> <83wn6zui9n.fsf@gnu.org> <87ilii41p9.fsf@gmail.com> <867cytgk0k.fsf@mail.linkov.net> <871qme5ej3.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39080"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , stefankangas@gmail.com, 59888@debbugs.gnu.org, Juri Linkov To: Augusto Stoffel Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 26 14:18:24 2023 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 1pWGv2-000A1R-KC for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 26 Feb 2023 14:18:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pWGun-00061B-3X; Sun, 26 Feb 2023 08:18:09 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pWGul-00060Y-ES for bug-gnu-emacs@gnu.org; Sun, 26 Feb 2023 08:18:07 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pWGug-0007Zx-DV for bug-gnu-emacs@gnu.org; Sun, 26 Feb 2023 08:18:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pWGug-0007TX-3a for bug-gnu-emacs@gnu.org; Sun, 26 Feb 2023 08:18:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Robert Pluim Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 26 Feb 2023 13:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59888 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 59888-submit@debbugs.gnu.org id=B59888.167741744728682 (code B ref 59888); Sun, 26 Feb 2023 13:18:02 +0000 Original-Received: (at 59888) by debbugs.gnu.org; 26 Feb 2023 13:17:27 +0000 Original-Received: from localhost ([127.0.0.1]:42577 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pWGu7-0007SY-Cc for submit@debbugs.gnu.org; Sun, 26 Feb 2023 08:17:27 -0500 Original-Received: from mail-wm1-f49.google.com ([209.85.128.49]:36506) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pWGu5-0007SJ-BU for 59888@debbugs.gnu.org; Sun, 26 Feb 2023 08:17:26 -0500 Original-Received: by mail-wm1-f49.google.com with SMTP id j19-20020a05600c191300b003eb3e1eb0caso736003wmq.1 for <59888@debbugs.gnu.org>; Sun, 26 Feb 2023 05:17:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=KnVezPHq+GdOoLqjyao/nGLEqem7qYUbuTLbilK7DwM=; b=AxoVmld9yNE0aUxi7e0QmG5J1gm7l9Um0197OlhPWZXuM9hHPGYcHe2mWSOzvdFlz8 g14rhOmtyhvZumWT9a/1u28t9g0+4v/r09gNqSCCAjgAlgpLf3/QuQ5jtQeoGEGUZ/3u dY0I+PjBRZX/ouYki5PkkieE2AD1Q5arQzqOpFtXjfpY6Fs2gFcHczqdTSYDVOgUnVdV uNX9n2tBrcrRJig9WKzC7F/MgJriUeLgK+dQc3ulzm4VLuCWr2EfGB4wZ75bOvECzfIW ImQ2AmL5KiEwTFmey+A70xC2BKRZA9w6JHUtBjrCNZ1eyHKGrLsCxgatqjScqKRoMpCu 0jRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KnVezPHq+GdOoLqjyao/nGLEqem7qYUbuTLbilK7DwM=; b=XFjqYJ1WHMOQuePi3kEBns/veDBbFuT68VwnAAqoSmxI16jMgeqLUnEnfNlAz12F2w pf1+MyVNitwCu/h6gaV+M9s0Ccx/Q+H3cwFDyKSE+BiNRwTTV8zplsTtNhdCpgDTRlZw g+Y+KH8c55b5KoQEwgx2ggzjBL4QQXBPGO73C18awEIjor4+wxTSW/9c1H/Z9QkzljWw 3pOR+UcUgMhvbcLKaj/P+/1h/nHShgNLsZAaFYFCmKBJqtmaPilD8Kufa56dNu/748dl NSL23i67+kwlZYmytt6Jpn9S1FLHXO2iBXB48hLeWeIUdVNOHdEU6snkMHWkgOApvljn 1J3w== X-Gm-Message-State: AO0yUKVDNQDrE7HLuWiyiyBtWA6L+GfepPIDhoANx5WNrh12JVOEwVQf ULjMppjbdv6hsAFGGrTHPLAUT5KBXBc= X-Google-Smtp-Source: AK7set9jAdRCd7u7ADguMd/95fkWUQA2DoMp2/2y4yhfox1X5UcJshXO/nXP04fpzbIcLtbdqv7eLw== X-Received: by 2002:a05:600c:34cb:b0:3eb:a4e:a2b2 with SMTP id d11-20020a05600c34cb00b003eb0a4ea2b2mr6998750wmq.4.1677417438830; Sun, 26 Feb 2023 05:17:18 -0800 (PST) Original-Received: from rltb ([82.66.8.55]) by smtp.gmail.com with ESMTPSA id l4-20020a05600c4f0400b003df7b40f99fsm10092954wmq.11.2023.02.26.05.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Feb 2023 05:17:18 -0800 (PST) In-Reply-To: <871qme5ej3.fsf@gmail.com> (Augusto Stoffel's message of "Sat, 25 Feb 2023 09:34:56 +0100") 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:256796 Archived-At: >>>>> On Sat, 25 Feb 2023 09:34:56 +0100, Augusto Stoffel said: Augusto> I've been using the grep-use-headings locally for a long time = and it Augusto> works well. Should the the patches be installed? Augusto> From 77ea46f6dc50a8f463bd2f51ce9d0585de0bb55c Mon Sep 17 00:00= :00 2001 Augusto> From: Augusto Stoffel Augusto> Date: Wed, 7 Dec 2022 18:44:07 +0100 Augusto> Subject: [PATCH 2/2] New user option 'grep-use-headings' Augusto> * lisp/progmodes/grep.el (grep-heading-regexp): New user optio= n. Augusto> (grep-heading): New face. Augusto> (grep--heading-format, grep--heading-state, grep--heading-filt= er): Augusto> Filter function for grep processes and supporting variables. Augusto> (grep-use-headings): New user option. Augusto> (grep-mode): Use the above, if applicable. Augusto> --- Augusto> etc/NEWS | 8 ++++ Augusto> lisp/progmodes/grep.el | 69 ++++++++++++++++++++++= +++++++++ Augusto> test/lisp/progmodes/grep-tests.el | 14 +++++++ Augusto> 3 files changed, 91 insertions(+) Augusto> diff --git a/etc/NEWS b/etc/NEWS Augusto> index 4b0e4e6bd46..ca2e8011510 100644 Augusto> --- a/etc/NEWS Augusto> +++ b/etc/NEWS Augusto> @@ -95,6 +95,14 @@ If you want to get back the old behavior, s= et the user option to the value Augusto> (setopt gdb-locals-table-row-config Augusto> `((type . 0) (name . 0) (value . ,gdb-locals-valu= e-limit))) =20 Augusto> +** Compile Augusto> + Augusto> +*** New user option 'grep-use-headings'. Augusto> +When non-nil, the output of Grep is split into sections, one = for each Augusto> +file, instead of having file names prefixed to each line. It= is Augusto> +equivalent to the --heading option of some tools such as 'git= grep' Augusto> +and 'rg'. Augusto> + You also add a face and a user option for the regexp, they should be mentioned in NEWS (and the manual, if relevant) =20 Augusto> +(defvar grep--heading-format Augusto> + (eval-when-compile Augusto> + (let ((title (propertize "%s" Augusto> + 'font-lock-face 'grep-heading Augusto> + 'outline-level 1))) Augusto> + (propertize (concat title "\n") 'compilation-annotation= t))) Augusto> + "Format string of grep headings. Augusto> +This is passed to `format' with one argument, the text of the Augusto> +first capture group of `grep-heading-regexp'.") Augusto> + Augusto> +(defvar-local grep--heading-state nil Augusto> + "Variable to keep track of the `grep--heading-filter' state= .") Augusto> + Augusto> +(defun grep--heading-filter () Augusto> + "Filter function to add headings to output of a grep proces= s." Augusto> + (unless grep--heading-state Augusto> + (setq grep--heading-state (cons (point-min-marker) nil))) Augusto> + (save-excursion Augusto> + (let ((limit (car grep--heading-state))) Augusto> + ;; Move point to the old limit and update limit marker. Augusto> + (move-marker limit (prog1 (pos-bol) (goto-char limit))) Augusto> + (while (re-search-forward grep-heading-regexp limit t) Augusto> + (unless (get-text-property (point) 'compilation-annot= ation) Augusto> + (let ((heading (match-string-no-properties 1)) Augusto> + (start (match-beginning 2)) Augusto> + (end (match-end 2))) Augusto> + (when start Augusto> + (put-text-property start end 'invisible t)) Augusto> + (when (and heading (not (equal heading (cdr grep-= -heading-state)))) Augusto> + (save-excursion Augusto> + (forward-line 0) That=CA=BCs the same as (goto-char (pos-bol)) because of a wrinkle in the implementation of `forward-line'. It might even be faster, but I=CA=BCve not measured it :-) Robert --=20