From: Lennart Borgman Date: Sat, 17 Jul 2021 14:53:36 +0000 (+0200) Subject: Add new function 'grep-file-at-point' X-Git-Tag: emacs-28.0.90~1830 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=9ee418b7b95e20fa4d8ae585f33e9b5d9316bc99;p=emacs.git 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). --- 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)