[Top][All Lists]

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

Re: dir-specific grep-find-command?

From: Kevin Rodgers
Subject: Re: dir-specific grep-find-command?
Date: Tue, 17 Jun 2003 13:10:24 -0600
User-agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv: Gecko/20020406 Netscape6/6.2.2

Ed L Cashin wrote:

Hi.  I often have to do grep-find in the linux kernel sources, and I
never want grep to search through object files and the like.  I wrote
a little script, kern-grep-find, that does this:

  test -z "$*" && exit 0
find . -type f \
      ! \( -name '*.o' \
      -o -name 'vmlinu*' \
      -o -name '*.ko' \
      -o -name '*.a' \
      -o -name '*.so' \) \
      -print0 | xargs -0 -e grep -n -e "$*"

... and then I wanted that to be the default command for those times
when I'm doing dired or using a buffer in the kernel sources.  For
want of a more elegant solution, I created a list of regexps that
match my kernel source directories and am overriding the grep-find
function in my .emacs file, modifying grep-find like this:

      (unless grep-find-command
      (list (read-from-minibuffer "Run find (like this): "
-                                grep-find-command nil nil
-                                'grep-find-history))))
+                                (if (in-kernel 0)
+                                    "kern-grep-find "
+                                    grep-find-command) nil nil
+                                    'grep-find-history))))
   (let ((null-device nil))             ; see grep
     (grep command-args)))

... so that it calls my "in-kernel" function to see whether the
default-directory matches one of my kernel source dir regexps.  If
we're in the kernel sources, it uses the script, otherwise, it uses
This works, but it seems really ugly.  Since grep-find doesn't have
any hooks, and I'm not immediately sure how hooks would even work, I
don't know what else to do.

Does anyone have any ideas or suggestions?

How about something like this:

(defun in-kernel-hook ()
  "If `in-kernel', override global `grep-find-command' value."
  (if (in-kernel 0)
      (set (make-local-variable 'grep-find-command) "kern-grep-find")))

(add-hook 'find-file-hooks 'in-kernel-hook)
(add-hook 'dired-mode-hook 'in-kernel-hook)

<a href="mailto:&lt;kevin.rodgers&#64;;";>Kevin Rodgers</a>

reply via email to

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