emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Irritation in C-u M-x grep, caused by overprotectiveness


From: Alan Mackenzie
Subject: Irritation in C-u M-x grep, caused by overprotectiveness
Date: Sun, 29 Jul 2007 11:09:10 +0000
User-agent: Mutt/1.5.9i

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  <address@hidden>

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]