From 9ee418b7b95e20fa4d8ae585f33e9b5d9316bc99 Mon Sep 17 00:00:00 2001 From: Lennart Borgman Date: Sat, 17 Jul 2021 16:53:36 +0200 Subject: [PATCH] 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 4bfb5b4d165..88d8fbe4b89 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1153,6 +1153,11 @@ any directory names on the 'find' command lines end in a slash. 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' +buffers. + ** Help +++ diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index 462ea51e2ce..370bdd55163 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)))) + ;;;###autoload (defalias 'rzgrep 'zrgrep) -- 2.39.2