unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Irritation in C-u M-x grep, caused by overprotectiveness
@ 2007-07-29 11:09 Alan Mackenzie
  2007-07-29 13:49 ` Stefan Monnier
       [not found] ` <E1IFYM6-000453-N8@fencepost.gnu.org>
  0 siblings, 2 replies; 7+ messages in thread
From: Alan Mackenzie @ 2007-07-29 11:09 UTC (permalink / raw)
  To: emacs-devel

Hi, Emacs!

On the command line, do this:

    $ CC_FILESEL=cc-{align,awk,bytecomp,cmds,compat,defs,engine,fonts,langs,menus,mode,styles,subword,vars}.el
    $ export CC_FILESEL

, and start (or return) to an emacs session.  Load a file from
.../lisp/progmodes, for example:

    C-x C-f ...../lisp/progmodes/cc-mode.el

.  This establishes the current directory.  With this as the current
buffer, do:

    M-x grep

, which prompts with "Run grep (like this): grep -nH -e " in the
mini-buffer.  Fill in the minibuffer like this:

    Run grep (like this): grep -nH -e kwd-clause-end $CC_FILESEL

, and start the grep with <CR>.  This will bring up, inter alia,
cc-engine.el.  Put point on a symbol in this file and do this:

    C-u M-x grep <CR>

.  Emacs 21 returns this prompt in the minibuffer:

    grep -n c-keyword-member $CC_FILESEL
                             ^^^^^^^^^^^

, which is better than what Emacs 22 currently returns:

    grep -nH c-keyword-member *.el
                              ^^^^

If I give an environment variable as "filename", the chances are I'll
want to use it in subsequent greps.  I think the current behaviour is a
bug, a regression, albeit a small one.  However, it's been irritating
me, water torture style (drip, drip, drip, drip, drip, ......), ever
since the release of Emacs 22 to the point where I just can't take it
any more.

#########################################################################

This manipulation is done in `grep-default-command' in
.../progmodes/grep.el.  In the following patch, I simply add a check for
the first character of "the filename" being ?$.  This doesn't seem very
satisfactory because it might not be portable enough.  There doesn't
seem to be a function `env-variable-name-p' which would be useful here.
    
I've also answered RMS's RFC from V1.65 from a year and 9 hours ago.  In
the process I've renamed `sh-arg-re' to `pattern-re' to make the code
more understandable.


2007-07-29  Alan Mackenzie  <acm@muc.de>

	* progmodes/grep.el (grep-default-command): Add comments.  Rename
	`sh-arg-re' to `pattern-re'.  Don't splat the filename from the
	history if it is an environment variable.


Index: grep.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/grep.el,v
retrieving revision 1.76
diff -c -r1.76 grep.el
*** grep.el	26 Jul 2007 05:27:27 -0000	1.76
--- grep.el	29 Jul 2007 10:44:14 -0000
***************
*** 537,550 ****
  (defun grep-default-command ()
    "Compute the default grep command for C-u M-x grep to offer."
    (let ((tag-default (shell-quote-argument (grep-tag-default)))
! 	;; This a regexp to match single shell arguments.
! 	;; Could someone please add comments explaining it?
! 	(sh-arg-re "\\(\\(?:\"\\(?:[^\"]\\|\\\\\"\\)+\"\\|'[^']+'\\|[^\"' \t\n]\\)+\\)")
  	(grep-default (or (car grep-history) grep-command)))
      ;; In the default command, find the arg that specifies the pattern.
      (when (or (string-match
! 	       (concat "[^ ]+\\s +\\(?:-[^ ]+\\s +\\)*"
! 		       sh-arg-re "\\(\\s +\\(\\S +\\)\\)?")
  	       grep-default)
  	      ;; If the string is not yet complete.
  	      (string-match "\\(\\)\\'" grep-default))
--- 537,551 ----
  (defun grep-default-command ()
    "Compute the default grep command for C-u M-x grep to offer."
    (let ((tag-default (shell-quote-argument (grep-tag-default)))
! 	;; pattern-re is a regexp to match a grep pattern; that's a sequence
! 	;; of single or double quoted strings and non-WS characters.  It
! 	;; doesn't try to handle backslashes properly; maybe it should.
! 	(pattern-re "\\(\\(?:\"\\(?:[^\"]\\|\\\\\"\\)+\"\\|'[^']+'\\|[^\"' \t\n]\\)+\\)")
  	(grep-default (or (car grep-history) grep-command)))
      ;; In the default command, find the arg that specifies the pattern.
      (when (or (string-match
! 	       (concat "[^ ]+\\s +\\(?:-[^ ]+\\s +\\)*" ; (POSIX) command with options
! 		       pattern-re "\\(\\s +\\(\\S +\\)\\)?") ; pattern + optional filename
  	       grep-default)
  	      ;; If the string is not yet complete.
  	      (string-match "\\(\\)\\'" grep-default))
***************
*** 552,564 ****
        ;; But first, maybe replace the file name pattern.
        (condition-case nil
  	  (unless (or (not (stringp buffer-file-name))
! 		      (when (match-beginning 2)
! 			(save-match-data
! 			  (string-match
! 			   (wildcard-to-regexp
! 			    (file-name-nondirectory
! 			     (match-string 3 grep-default)))
! 			   (file-name-nondirectory buffer-file-name)))))
  	    (setq grep-default (concat (substring grep-default
  						  0 (match-beginning 2))
  				       " *."
--- 553,566 ----
        ;; But first, maybe replace the file name pattern.
        (condition-case nil
  	  (unless (or (not (stringp buffer-file-name))
! 		      (when (match-beginning 3) ; "filename"(s) in grep-default?
! 			(or (save-match-data
! 			      (string-match
! 			       (wildcard-to-regexp
! 				(file-name-nondirectory
! 				 (match-string 3 grep-default)))
! 			       (file-name-nondirectory buffer-file-name)))
! 			    (eq (aref grep-default (match-beginning 3)) ?$))))
  	    (setq grep-default (concat (substring grep-default
  						  0 (match-beginning 2))
  				       " *."



-- 
Alan Mackenzie (Ittersbach, Germany).

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

end of thread, other threads:[~2007-08-01 14:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-29 11:09 Irritation in C-u M-x grep, caused by overprotectiveness Alan Mackenzie
2007-07-29 13:49 ` Stefan Monnier
2007-07-29 15:30   ` Alan Mackenzie
2007-07-29 17:33     ` Stefan Monnier
     [not found] ` <E1IFYM6-000453-N8@fencepost.gnu.org>
2007-07-31 21:07   ` Alan Mackenzie
2007-08-01 14:07     ` Stefan Monnier
2007-08-01 14:30     ` Richard Stallman

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