From: Robert Pluim <rpluim@gmail.com>
To: Augusto Stoffel <arstoffel@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>,
stefankangas@gmail.com, 59888@debbugs.gnu.org,
Juri Linkov <juri@linkov.net>
Subject: bug#59888: [PATCH] Add 'grep-use-headings'
Date: Sun, 26 Feb 2023 14:17:17 +0100 [thread overview]
Message-ID: <87cz5w7ehu.fsf@gmail.com> (raw)
In-Reply-To: <871qme5ej3.fsf@gmail.com> (Augusto Stoffel's message of "Sat, 25 Feb 2023 09:34:56 +0100")
>>>>> On Sat, 25 Feb 2023 09:34:56 +0100, Augusto Stoffel <arstoffel@gmail.com> 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 <arstoffel@gmail.com>
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 option.
Augusto> (grep-heading): New face.
Augusto> (grep--heading-format, grep--heading-state, grep--heading-filter):
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, set the user option to the value
Augusto> (setopt gdb-locals-table-row-config
Augusto> `((type . 0) (name . 0) (value . ,gdb-locals-value-limit)))
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)
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 process."
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-annotation)
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ʼs the same as (goto-char (pos-bol)) because of a wrinkle in the
implementation of `forward-line'. It might even be faster, but Iʼve
not measured it :-)
Robert
--
next prev parent reply other threads:[~2023-02-26 13:17 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-07 17:57 bug#59888: [PATCH] Add 'grep-heading-mode' Augusto Stoffel
2022-12-07 18:14 ` Eli Zaretskii
2022-12-08 8:59 ` Augusto Stoffel
2022-12-08 10:57 ` Eli Zaretskii
2022-12-08 0:19 ` Stefan Kangas
2022-12-08 9:06 ` Augusto Stoffel
2022-12-09 7:23 ` Juri Linkov
2022-12-09 11:58 ` Augusto Stoffel
2022-12-09 12:18 ` bug#59888: [PATCH] Add 'grep-use-headings' Augusto Stoffel
2022-12-09 19:36 ` Eli Zaretskii
2022-12-09 20:03 ` Augusto Stoffel
2022-12-09 20:29 ` Eli Zaretskii
2022-12-10 20:08 ` Augusto Stoffel
2022-12-10 20:16 ` Eli Zaretskii
2022-12-11 11:30 ` Augusto Stoffel
2022-12-15 8:05 ` Juri Linkov
2023-02-25 8:34 ` Augusto Stoffel
2023-02-25 18:00 ` Juri Linkov
2023-02-26 13:17 ` Robert Pluim [this message]
2023-02-26 15:07 ` Augusto Stoffel
2023-02-27 6:24 ` Robert Pluim
2023-02-27 11:26 ` Augusto Stoffel
2023-02-27 16:51 ` Robert Pluim
2023-02-27 18:53 ` Juri Linkov
2023-02-27 19:06 ` Augusto Stoffel
2023-02-27 19:15 ` Juri Linkov
2023-02-28 17:24 ` Juri Linkov
2023-02-28 18:17 ` Augusto Stoffel
2023-03-01 17:52 ` Juri Linkov
2022-12-09 20:40 ` Gregory Heytings
2022-12-10 17:24 ` Juri Linkov
2022-12-08 9:57 ` bug#59888: [PATCH] Add 'grep-heading-mode' Mattias Engdegård
2022-12-08 10:28 ` Augusto Stoffel
2022-12-08 10:48 ` Mattias Engdegård
2023-02-27 14:18 ` Mattias Engdegård
2022-12-09 7:28 ` Juri Linkov
2022-12-09 11:58 ` Augusto Stoffel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87cz5w7ehu.fsf@gmail.com \
--to=rpluim@gmail.com \
--cc=59888@debbugs.gnu.org \
--cc=arstoffel@gmail.com \
--cc=eliz@gnu.org \
--cc=juri@linkov.net \
--cc=stefankangas@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).