GNU bug report logs - #8252
Please add a function to get files in *grep*

Previous Next

Package: emacs;

Reported by: Lennart Borgman <lennart.borgman <at> gmail.com>

Date: Mon, 14 Mar 2011 21:47:01 UTC

Severity: wishlist

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 8252 in the body.
You can then email your comments to 8252 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8252; Package emacs. (Mon, 14 Mar 2011 21:47:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Lennart Borgman <lennart.borgman <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 14 Mar 2011 21:47:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Lennart Borgman <lennart.borgman <at> gmail.com>
To: Emacs Bugs <bug-gnu-emacs <at> gnu.org>
Subject: Please add a function to get files in *grep*
Date: Mon, 14 Mar 2011 22:46:05 +0100
For example something like this (which I just added to
ourcomments-util.el in nXhtml) works now:

(defun grep-grepped-file (pt)
  "Return grepped file at PT in a `grep-mode' buffer.
The returned file name is relative."
  (let* ((msg (get-text-property (point) 'compilation-message))
         (loc (when msg (compilation--message->loc msg)))
         (file (when loc (caar (compilation--loc->file-struct loc)))))
    file))




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8252; Package emacs. (Tue, 15 Mar 2011 02:17:01 GMT) Full text and rfc822 format available.

Message #8 received at 8252 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Lennart Borgman <lennart.borgman <at> gmail.com>
Cc: 8252 <at> debbugs.gnu.org
Subject: Re: bug#8252: Please add a function to get files in *grep*
Date: Mon, 14 Mar 2011 22:16:46 -0400
Could you motivate your request?


        Stefan




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8252; Package emacs. (Tue, 15 Mar 2011 09:33:02 GMT) Full text and rfc822 format available.

Message #11 received at 8252 <at> debbugs.gnu.org (full text, mbox):

From: Lennart Borgman <lennart.borgman <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 8252 <at> debbugs.gnu.org
Subject: Re: bug#8252: Please add a function to get files in *grep*
Date: Tue, 15 Mar 2011 10:31:40 +0100
On Tue, Mar 15, 2011 at 3:16 AM, Stefan Monnier
<monnier <at> iro.umontreal.ca> wrote:
> Could you motivate your request?

There can be a lot of uses for it. In my case I am using it for this:

(defun grep-get-buffer-files ()
  "Return list of files in a `grep-mode' buffer."
  (or (and (compilation-buffer-p (current-buffer))
           (derived-mode-p 'grep-mode))
      (error "Not in a grep buffer"))
  (let ((here (point))
        files)
    (font-lock-fontify-buffer)
    (goto-char (point-min))
    (while (not (eobp))
      (let ((file (grep-grepped-file (point))))
        (when file (add-to-list 'files file)))
      (forward-line))
    (goto-char here)
    ;;(message "files=%s" files)
    files))


(defun grep-query-replace(from to &optional delimited)
  "Do `query-replace-regexp' of FROM with TO, on all files in *grep*.
Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
If you exit (\\[keyboard-quit], RET or q), you can resume the query replace
with the command \\[tags-loop-continue].

Must be called from a `grep-mode' buffer."
  (interactive
   (let ((common
          ;; Use the regexps that have been used in grep
          (let ((query-replace-from-history-variable 'grep-regexp-history)
                (query-replace-defaults (or grep-query-replace-defaults
                                            query-replace-defaults)))
            (unless (derived-mode-p 'grep-mode) (error "This command
must be used in a grep output buffer"))
            (query-replace-read-args
             "Query replace regexp in grepped files" t t))))
     (setq grep-query-replace-defaults (cons (nth 0 common)
                                             (nth 1 common)))
     (list (nth 0 common) (nth 1 common) (nth 2 common))))
  (unless (derived-mode-p 'grep-mode) (error "This command must be
used in a grep output buffer"))
  (dolist (file (grep-get-buffer-files))
    (let ((buffer (get-file-buffer file)))
      (if (and buffer (with-current-buffer buffer
			buffer-read-only))
	  (error "File `%s' is visited read-only" file))))
  (tags-query-replace from to delimited
		      '(grep-get-buffer-files)))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#8252; Package emacs. (Sat, 17 Jul 2021 14:56:02 GMT) Full text and rfc822 format available.

Message #14 received at 8252 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Lennart Borgman <lennart.borgman <at> gmail.com>
Cc: 8252 <at> debbugs.gnu.org
Subject: Re: bug#8252: Please add a function to get files in *grep*
Date: Sat, 17 Jul 2021 16:54:56 +0200
Lennart Borgman <lennart.borgman <at> gmail.com> writes:

> For example something like this (which I just added to
> ourcomments-util.el in nXhtml) works now:
>
> (defun grep-grepped-file (pt)
>   "Return grepped file at PT in a `grep-mode' buffer.
> The returned file name is relative."
>   (let* ((msg (get-text-property (point) 'compilation-message))
>          (loc (when msg (compilation--message->loc msg)))
>          (file (when loc (caar (compilation--loc->file-struct loc)))))
>     file))

I think that sounds generally useful -- writing things on top of grep
mode is quite popular, and it isn't obvious how to get at the file name
(which is what people generally want).  So I've added your function to
Emacs 28 (with some minor tweaks) under the name `grep-file-at-point'.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug marked as fixed in version 28.1, send any further explanations to 8252 <at> debbugs.gnu.org and Lennart Borgman <lennart.borgman <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sat, 17 Jul 2021 14:56:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 15 Aug 2021 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 248 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.