all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: dir-specific grep-find-command?
Date: Tue, 17 Jun 2003 13:10:24 -0600	[thread overview]
Message-ID: <3EEF67A0.1020507@yahoo.com> (raw)
In-Reply-To: 87znki6gnb.fsf@cs.uga.edu

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
>         (grep-compute-defaults))
>       (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
> grep-find-command. 
> 
> 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;ihs.com&gt;">Kevin Rodgers</a>

  reply	other threads:[~2003-06-17 19:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-15 23:54 dir-specific grep-find-command? Ed L Cashin
2003-06-17 19:10 ` Kevin Rodgers [this message]
2003-06-19  5:13   ` Ed L Cashin
2003-06-20 15:07     ` Kevin Rodgers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3EEF67A0.1020507@yahoo.com \
    --to=ihs_4664@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.