[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 9ee418b: Add new function 'grep-file-at-point'

From: Lars Ingebrigtsen
Subject: master 9ee418b: Add new function 'grep-file-at-point'
Date: Sat, 17 Jul 2021 10:53:44 -0400 (EDT)

branch: master
commit 9ee418b7b95e20fa4d8ae585f33e9b5d9316bc99
Author: Lennart Borgman <lennart.borgman@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add new function 'grep-file-at-point'
    * lisp/progmodes/grep.el (grep-file-at-point): New function to
    return the file name at point (bug#8252).
 etc/NEWS               | 5 +++++
 lisp/progmodes/grep.el | 7 +++++++
 2 files changed, 12 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 4bfb5b4..88d8fbe 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1153,6 +1153,11 @@ any directory names on the 'find' command lines end in a 
 This change is for better compatibility with old versions of non-GNU
 'find', such as the one used on macOS.
+*** New utility function 'grep-file-at-point'.
+This returns the name of the file at point (if any) in 'grep-mode'
 ** Help
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index 462ea51..370bdd5 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -1345,6 +1345,13 @@ command before it's run."
         (grep-highlight-matches 'always))
     (rgrep regexp files dir confirm)))
+(defun grep-file-at-point (point)
+  "Return the name of the file at POINT a `grep-mode' buffer.
+The returned file name is relative."
+  (when-let ((msg (get-text-property (point) 'compilation-message))
+             (loc (compilation--message->loc msg)))
+    (caar (compilation--loc->file-struct loc))))
 (defalias 'rzgrep 'zrgrep)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]