unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#13549: 24.3.50; FR: Improve grep output (show function names, when possible)
@ 2013-01-25 14:57 Jambunathan K
  2013-01-25 15:05 ` Jambunathan K
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Jambunathan K @ 2013-01-25 14:57 UTC (permalink / raw)
  To: 13549

[-- Attachment #1: Type: text/plain, Size: 939 bytes --]


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)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: compile.el.diff --]
[-- Type: text/x-diff, Size: 983 bytes --]

=== 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)


[-- Attachment #3: Type: text/plain, Size: 441 bytes --]


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

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@gmx.de-20130124095002-l3domdlb4dqep93i
Windowing system distributor `The X.Org Foundation', version 11.0.10707000
System Description:	Debian GNU/Linux 6.0.5 (squeeze)

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


[-- Attachment #4: grep-proof-of-concept-cf-cscope.png --]
[-- Type: image/png, Size: 62190 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#13549: 24.3.50; FR: Improve grep output (show function names, when possible)
  2013-01-25 14:57 bug#13549: 24.3.50; FR: Improve grep output (show function names, when possible) Jambunathan K
@ 2013-01-25 15:05 ` Jambunathan K
  2013-01-25 17:32 ` Glenn Morris
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Jambunathan K @ 2013-01-25 15:05 UTC (permalink / raw)
  To: 13549

Jambunathan K <kjambunathan@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'.
-- 





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#13549: 24.3.50; FR: Improve grep output (show function names, when possible)
  2013-01-25 14:57 bug#13549: 24.3.50; FR: Improve grep output (show function names, when possible) Jambunathan K
  2013-01-25 15:05 ` Jambunathan K
@ 2013-01-25 17:32 ` Glenn Morris
  2013-01-25 18:55 ` Stefan Monnier
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Glenn Morris @ 2013-01-25 17:32 UTC (permalink / raw)
  To: Jambunathan K; +Cc: 13549


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.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#13549: 24.3.50; FR: Improve grep output (show function names, when possible)
  2013-01-25 14:57 bug#13549: 24.3.50; FR: Improve grep output (show function names, when possible) Jambunathan K
  2013-01-25 15:05 ` Jambunathan K
  2013-01-25 17:32 ` Glenn Morris
@ 2013-01-25 18:55 ` Stefan Monnier
  2013-02-03 13:49 ` Jambunathan K
  2013-05-22 20:44 ` Juri Linkov
  4 siblings, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2013-01-25 18:55 UTC (permalink / raw)
  To: Jambunathan K; +Cc: 13549

> 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






^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#13549: 24.3.50; FR: Improve grep output (show function names, when possible)
  2013-01-25 14:57 bug#13549: 24.3.50; FR: Improve grep output (show function names, when possible) Jambunathan K
                   ` (2 preceding siblings ...)
  2013-01-25 18:55 ` Stefan Monnier
@ 2013-02-03 13:49 ` Jambunathan K
  2013-05-22 20:44 ` Juri Linkov
  4 siblings, 0 replies; 9+ messages in thread
From: Jambunathan K @ 2013-02-03 13:49 UTC (permalink / raw)
  To: 13549

[-- Attachment #1: Type: text/plain, Size: 783 bytes --]

Jambunathan K <kjambunathan@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.


[-- Attachment #2: Type: text/plain, Size: 1014 bytes --]

=== 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)


[-- Attachment #3: Type: text/plain, Size: 6 bytes --]



-- 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#13549: 24.3.50; FR: Improve grep output (show function names, when possible)
  2013-01-25 14:57 bug#13549: 24.3.50; FR: Improve grep output (show function names, when possible) Jambunathan K
                   ` (3 preceding siblings ...)
  2013-02-03 13:49 ` Jambunathan K
@ 2013-05-22 20:44 ` Juri Linkov
  2013-05-22 22:03   ` Stefan Monnier
  4 siblings, 1 reply; 9+ messages in thread
From: Juri Linkov @ 2013-05-22 20:44 UTC (permalink / raw)
  To: Jambunathan K; +Cc: 13549

> 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
 






^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#13549: 24.3.50; FR: Improve grep output (show function names, when possible)
  2013-05-22 20:44 ` Juri Linkov
@ 2013-05-22 22:03   ` Stefan Monnier
  2013-05-24 20:55     ` Juri Linkov
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2013-05-22 22:03 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Jambunathan K, 13549

> -     ("^.+?-[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





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#13549: 24.3.50; FR: Improve grep output (show function names, when possible)
  2013-05-22 22:03   ` Stefan Monnier
@ 2013-05-24 20:55     ` Juri Linkov
  2013-05-25 13:08       ` Jambunathan K
  0 siblings, 1 reply; 9+ messages in thread
From: Juri Linkov @ 2013-05-24 20:55 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 13549-done, Jambunathan K

>> -     ("^.+?-[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.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#13549: 24.3.50; FR: Improve grep output (show function names, when possible)
  2013-05-24 20:55     ` Juri Linkov
@ 2013-05-25 13:08       ` Jambunathan K
  0 siblings, 0 replies; 9+ messages in thread
From: Jambunathan K @ 2013-05-25 13:08 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 13549-done


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@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.





^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-05-25 13:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-25 14:57 bug#13549: 24.3.50; FR: Improve grep output (show function names, when possible) Jambunathan K
2013-01-25 15:05 ` Jambunathan K
2013-01-25 17:32 ` Glenn Morris
2013-01-25 18:55 ` Stefan Monnier
2013-02-03 13:49 ` Jambunathan K
2013-05-22 20:44 ` Juri Linkov
2013-05-22 22:03   ` Stefan Monnier
2013-05-24 20:55     ` Juri Linkov
2013-05-25 13:08       ` Jambunathan K

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).