GNU bug report logs - #13549
24.3.50; FR: Improve grep output (show function names, when possible)

Previous Next

Package: emacs;

Reported by: Jambunathan K <kjambunathan <at> gmail.com>

Date: Fri, 25 Jan 2013 14:59:02 UTC

Severity: wishlist

Found in version 24.3.50

Done: Juri Linkov <juri <at> jurta.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 13549 in the body.
You can then email your comments to 13549 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 bug-gnu-emacs <at> gnu.org:
bug#13549; Package emacs. (Fri, 25 Jan 2013 14:59:05 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jambunathan K <kjambunathan <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 25 Jan 2013 14:59:05 GMT) Full text and rfc822 format available.

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

From: Jambunathan K <kjambunathan <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3.50; FR: Improve grep output (show function names, when possible)
Date: Fri, 25 Jan 2013 20:27:29 +0530
[Message part 1 (text/plain, inline)]
FR: Improve grep output (show function names, when possible)


Please see the attached screen shot.

Window on top displays cscope control buffer.

Window down below shows output from rgrep.  Note that the grep output
has been enhanced to *also* display the function name.

Compare cscope's typography with grep's.  (Hint: cscope's is much
better).  I have modified compilation faces as below for quick visual
comparison.

(custom-set-faces
 '(compilation-info ((t (:inherit cscope-file-face))))
 '(compilation-line-number ((t (:inherit cscope-line-number-face)))))

----------------------------------------------------------------

I used the following local modification to compile.el to sneak in the
function names.  

The modification is in `compilation-parse-errors' which seems to be a
font-lock handler.  I call `which-function' within this context.  Is it
justified?

(WARNING: Quick and Dirty work)
(Bzr version: revno: 111597)

[compile.el.diff (text/x-diff, inline)]
=== modified file 'lisp/progmodes/compile.el'
--- lisp/progmodes/compile.el	2013-01-14 01:09:38 +0000
+++ lisp/progmodes/compile.el	2013-01-25 14:25:11 +0000
@@ -1320,6 +1320,24 @@ to `compilation-error-regexp-alist' if R
                              file line end-line col end-col (or type 2) fmt))
 
             (when (integerp file)
+	      (when (integerp line)
+		(let* ((file-name (match-string file))
+		       (line-no (match-string line))
+		       (which-fn
+			(save-match-data
+			  (when line-no
+			    (with-current-buffer
+				(find-file-noselect file-name)
+			      (forward-line (1- line))
+			      (which-function))))))
+		  (overlay-put
+		   (make-overlay (match-end file) (match-end file)
+				 (current-buffer) t t)
+		   'after-string
+		   (format " <%s>"
+			   (propertize (or which-fn "global")
+				       'face 'cscope-function-face)))))
+
               (compilation--put-prop
                file 'font-lock-face
                (if (consp type)

[Message part 3 (text/plain, inline)]
----------------------------------------------------------------

In GNU Emacs 24.3.50.7 (i686-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2013-01-25 on debian-6.05
Bzr revision: 111597 michael.albinus <at> gmx.de-20130124095002-l3domdlb4dqep93i
Windowing system distributor `The X.Org Foundation', version 11.0.10707000
System Description:	Debian GNU/Linux 6.0.5 (squeeze)

----------------------------------------------------------------

[grep-proof-of-concept-cf-cscope.png (image/png, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13549; Package emacs. (Fri, 25 Jan 2013 15:06:01 GMT) Full text and rfc822 format available.

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

From: Jambunathan K <kjambunathan <at> gmail.com>
To: 13549 <at> debbugs.gnu.org
Subject: Re: bug#13549: 24.3.50;
	FR: Improve grep output (show function names, when possible)
Date: Fri, 25 Jan 2013 20:35:08 +0530
Jambunathan K <kjambunathan <at> gmail.com> writes:

> FR: Improve grep output (show function names, when possible)

> The modification is in `compilation-parse-errors' which seems to be a
> font-lock handler.  I call `which-function' within this context.  Is it
> justified?

I am not sure how semantic displays symbol searches.  Semantic could be
much more intelligent than `which-function'.
-- 




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13549; Package emacs. (Fri, 25 Jan 2013 17:33:02 GMT) Full text and rfc822 format available.

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

From: Glenn Morris <rgm <at> gnu.org>
To: Jambunathan K <kjambunathan <at> gmail.com>
Cc: 13549 <at> debbugs.gnu.org
Subject: Re: bug#13549: 24.3.50;
	FR: Improve grep output (show function names, when possible)
Date: Fri, 25 Jan 2013 12:32:41 -0500
If you want to indicate a feature request, the documented method is to
put

Severity: wishlist

as the first line of the body. Not FR or (Wish) or whatever
random string in the subject.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13549; Package emacs. (Sat, 26 Jan 2013 11:11:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Jambunathan K <kjambunathan <at> gmail.com>
Cc: 13549 <at> debbugs.gnu.org
Subject: Re: bug#13549: 24.3.50;
	FR: Improve grep output (show function names, when possible)
Date: Fri, 25 Jan 2013 13:55:08 -0500
> I used the following local modification to compile.el to sneak in the
> function names.
> The modification is in `compilation-parse-errors' which seems to be a
> font-lock handler.

It's not quite a font-lock handler: it's a function that can get called
to parse errors when needed.  It is triggered by font-lock, indeed, but
also by next-error (e.g. tho often font-lock will have done the work of
parsing already).

> I call `which-function' within this context.  Is it justified?

I'm not sure what you mean by "justified", but I see no particular
reason why it shouldn't work.

Your suggestion is interesting, and clearly since it is specific to
`grep' it should be moved to grep.el (maybe as a font-lock-keyword?).

It would need to be an option, since for some uses it doesn't make much
sense (especially considering the performance impact it can have, and
the amount of screen real-estate it requires).


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13549; Package emacs. (Sun, 03 Feb 2013 13:51:02 GMT) Full text and rfc822 format available.

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

From: Jambunathan K <kjambunathan <at> gmail.com>
To: 13549 <at> debbugs.gnu.org
Subject: Re: bug#13549: 24.3.50;
	FR: Improve grep output (show function names, when possible)
Date: Sun, 03 Feb 2013 19:19:05 +0530
[Message part 1 (text/plain, inline)]
Jambunathan K <kjambunathan <at> gmail.com> writes:

> I used the following local modification to compile.el to sneak in the
> function names.  
>
> The modification is in `compilation-parse-errors' which seems to be a
> font-lock handler.  I call `which-function' within this context.  Is it
> justified?
>
> (WARNING: Quick and Dirty work)
> (Bzr version: revno: 111597)

I attached the wrong diff (but the right screenshot).  I am attaching
the "right" diff, more for archival purposes.

Here is the diff that needs to be used.  Earlier diff was "totally
broken" in that it missed:

    1. `string-to-number' on line numbers.
    2. Goto beginning of buffer, before `forward-line'.

The changes still need a `save-excursion', though.  For experimental
code, it shouldn't matter much.

[Message part 2 (text/plain, inline)]
=== modified file 'lisp/progmodes/compile.el'
--- lisp/progmodes/compile.el	2013-02-02 08:41:02 +0000
+++ lisp/progmodes/compile.el	2013-02-03 13:35:20 +0000
@@ -1318,6 +1318,24 @@ to `compilation-error-regexp-alist' if R
                              file line end-line col end-col (or type 2) fmt))
 
             (when (integerp file)
+	      (when (integerp line)
+		(let* ((file-name (match-string file))
+		       (line-no (string-to-number (match-string line)))
+		       (which-fn
+			(save-match-data
+			  (with-current-buffer
+			      (find-file-noselect file-name)
+			    (goto-char (point-min))
+			    (forward-line (1- line-no))
+			    (which-function)))))
+		  (overlay-put
+		   (make-overlay (match-end file) (match-end file)
+				 (current-buffer) t t)
+		   'after-string
+		   (format "(%s)"
+			   (propertize (or which-fn "global")
+				       'face 'cscope-function-face)))))
+
               (compilation--put-prop
                file 'font-lock-face
                (if (consp type)

[Message part 3 (text/plain, inline)]

-- 

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13549; Package emacs. (Wed, 22 May 2013 21:07:02 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> jurta.org>
To: Jambunathan K <kjambunathan <at> gmail.com>
Cc: 13549 <at> debbugs.gnu.org
Subject: Re: bug#13549: 24.3.50;
	FR: Improve grep output (show function names, when possible)
Date: Wed, 22 May 2013 23:44:24 +0300
> FR: Improve grep output (show function names, when possible)

I think external commands (like `cscope' etc.) should output function names
much more efficiently than using `find-file-noselect' and `which-function'
to post-process their output.

There was a suggestion to implement this in `grep' with the
`-p --show-c-function' command line argument as mentioned in:

http://stackoverflow.com/questions/6133989/what-grep-command-will-include-the-current-function-name-in-its-output

There are other grep-like commands that already can output function names,
e.g. `git-grep'.  If you add to ~./.gitconfig the following lines:

[diff "el"]
        xfuncname = "^(\\(.*)$"

and to a project-specific file .gitattributes:

*.el   diff=el

then the following command will output function names:

git grep -inH -p -e "org-element-map"
lisp/org/org.el=20969=(defun org-fill-paragraph (&optional justify)
lisp/org/org.el:21047:		      (org-element-map

Since line numbers of function names are enclosed with `=' in its output,
they could be highlighted like `-' separators with this patch:

=== modified file 'lisp/progmodes/grep.el'
--- lisp/progmodes/grep.el	2013-05-18 16:32:43 +0000
+++ lisp/progmodes/grep.el	2013-05-22 20:36:00 +0000
@@ -410,7 +410,7 @@ (defvar grep-mode-font-lock-keywords
       (0 '(face nil compilation-message nil help-echo nil mouse-face nil) t)
       (1 grep-error-face)
       (2 grep-error-face nil t))
-     ("^.+?-[0-9]+-.*\n" (0 grep-context-face)))
+     ("^.+?[-=][0-9]+[-=].*\n" (0 grep-context-face)))
    "Additional things to highlight in grep output.
 This gets tacked on the end of the generated expressions.")
 

=== modified file 'etc/grep.txt'
--- etc/grep.txt	2013-01-03 00:36:36 +0000
+++ etc/grep.txt	2013-05-22 20:36:33 +0000
@@ -72,6 +72,14 @@
 agrep -n "INFO tree" ../info/*
 ../info/dir: 6: File: dir	Node: Top	This is the top of the INFO tree
 
+* git-grep
+  with `[diff "el"] xfuncname = "^(\\(.*)$"' in .gitconfig
+  and `*.el diff=el' in .gitattributes
+
+git grep -inH -p -e "org-element-map"
+lisp/org/org.el=20969=(defun org-fill-paragraph (&optional justify)
+lisp/org/org.el:21047:		      (org-element-map
+
 * unknown greps
 





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13549; Package emacs. (Wed, 22 May 2013 22:05:01 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Juri Linkov <juri <at> jurta.org>
Cc: Jambunathan K <kjambunathan <at> gmail.com>, 13549 <at> debbugs.gnu.org
Subject: Re: bug#13549: 24.3.50;
	FR: Improve grep output (show function names, when possible)
Date: Wed, 22 May 2013 18:03:36 -0400
> -     ("^.+?-[0-9]+-.*\n" (0 grep-context-face)))
> +     ("^.+?[-=][0-9]+[-=].*\n" (0 grep-context-face)))

Sounds good, tho a little comment above that line would be welcome (it
could talk about both the =..= and the -..- cases).


        Stefan




Reply sent to Juri Linkov <juri <at> jurta.org>:
You have taken responsibility. (Fri, 24 May 2013 20:58:02 GMT) Full text and rfc822 format available.

Notification sent to Jambunathan K <kjambunathan <at> gmail.com>:
bug acknowledged by developer. (Fri, 24 May 2013 20:58:02 GMT) Full text and rfc822 format available.

Message #28 received at 13549-done <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 13549-done <at> debbugs.gnu.org, Jambunathan K <kjambunathan <at> gmail.com>
Subject: Re: bug#13549: 24.3.50;
	FR: Improve grep output (show function names, when possible)
Date: Fri, 24 May 2013 23:55:15 +0300
>> -     ("^.+?-[0-9]+-.*\n" (0 grep-context-face)))
>> +     ("^.+?[-=][0-9]+[-=].*\n" (0 grep-context-face)))
>
> Sounds good, tho a little comment above that line would be welcome (it
> could talk about both the =..= and the -..- cases).

Done, with more comments.

As for the function names in the output of grep, let's hope that
the developers of GNU grep will apply the patch implemented in

http://lists.gnu.org/archive/html/bug-grep/2005-01/msg00027.html

that adds the command line option `-p' and `--show-function-line'
with formatting similar to the output of git-grep
that is now supported in Emacs.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13549; Package emacs. (Sat, 25 May 2013 13:10:02 GMT) Full text and rfc822 format available.

Message #31 received at 13549-done <at> debbugs.gnu.org (full text, mbox):

From: Jambunathan K <kjambunathan <at> gmail.com>
To: Juri Linkov <juri <at> jurta.org>
Cc: 13549-done <at> debbugs.gnu.org, Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Subject: Re: bug#13549: 24.3.50;
	FR: Improve grep output (show function names, when possible)
Date: Sat, 25 May 2013 18:38:31 +0530
In terms of UI, git grep solution is inferior compared to
(which-function) proposal.  Both of these are in turn is much inferior
to current state of the art i.e., semantic-symref.

Semantic not only interfaces with grep, cscope backends but has the
necessary infrastructure to re-write the results in to a unified
interface.  More importantly it displays function context.

I am OK with this bug remaining closed.  

I have now moved the proposal for displaying function context to
http://debbugs.gnu.org/cgi/bugreport.cgi?bug=14468.

Juri Linkov <juri <at> jurta.org> writes:

>>> -     ("^.+?-[0-9]+-.*\n" (0 grep-context-face)))
>>> +     ("^.+?[-=][0-9]+[-=].*\n" (0 grep-context-face)))
>>
>> Sounds good, tho a little comment above that line would be welcome (it
>> could talk about both the =..= and the -..- cases).
>
> Done, with more comments.
>
> As for the function names in the output of grep, let's hope that
> the developers of GNU grep will apply the patch implemented in
>
> http://lists.gnu.org/archive/html/bug-grep/2005-01/msg00027.html
>
> that adds the command line option `-p' and `--show-function-line'
> with formatting similar to the output of git-grep
> that is now supported in Emacs.




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

This bug report was last modified 10 years and 320 days ago.

Previous Next


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