all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* dir-specific grep-find-command?
@ 2003-06-15 23:54 Ed L Cashin
  2003-06-17 19:10 ` Kevin Rodgers
  0 siblings, 1 reply; 4+ messages in thread
From: Ed L Cashin @ 2003-06-15 23:54 UTC (permalink / raw)


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?

-- 
--Ed L Cashin     PGP public key: http://noserose.net/e/pgp/

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

* Re: dir-specific grep-find-command?
  2003-06-15 23:54 dir-specific grep-find-command? Ed L Cashin
@ 2003-06-17 19:10 ` Kevin Rodgers
  2003-06-19  5:13   ` Ed L Cashin
  0 siblings, 1 reply; 4+ messages in thread
From: Kevin Rodgers @ 2003-06-17 19:10 UTC (permalink / raw)


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>

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

* Re: dir-specific grep-find-command?
  2003-06-17 19:10 ` Kevin Rodgers
@ 2003-06-19  5:13   ` Ed L Cashin
  2003-06-20 15:07     ` Kevin Rodgers
  0 siblings, 1 reply; 4+ messages in thread
From: Ed L Cashin @ 2003-06-19  5:13 UTC (permalink / raw)


Kevin Rodgers <ihs_4664@yahoo.com> writes:

> Ed L Cashin wrote:
[ugly override of grep-find]

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

Excellent!  That seems to do exactly what I wanted.

Did you already know about those hooks or did you just know how to
find them, because I guess I failed to find them.

-- 
--Ed L Cashin     PGP public key: http://noserose.net/e/pgp/

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

* Re: dir-specific grep-find-command?
  2003-06-19  5:13   ` Ed L Cashin
@ 2003-06-20 15:07     ` Kevin Rodgers
  0 siblings, 0 replies; 4+ messages in thread
From: Kevin Rodgers @ 2003-06-20 15:07 UTC (permalink / raw)


Ed L Cashin wrote:

> Kevin Rodgers <ihs_4664@yahoo.com> writes:
>>(add-hook 'find-file-hooks 'in-kernel-hook)
>>(add-hook 'dired-mode-hook 'in-kernel-hook)
> 
> Excellent!  That seems to do exactly what I wanted.
> 
> Did you already know about those hooks or did you just know how to
> find them, because I guess I failed to find them.

After 20 years of using Emacs, I just knew about them.


But all conventional modes have a hook, so dired-mode-hook should have
been obvious.  And then rather than trying to predict what kind of files
might be in your kernel directory structure (i.e. what modes might be
used and thus hooks might need to be added to), the standard hook to use
is find-file-hooks (and find-file-not-found-hooks for new files).

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

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

end of thread, other threads:[~2003-06-20 15:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-15 23:54 dir-specific grep-find-command? Ed L Cashin
2003-06-17 19:10 ` Kevin Rodgers
2003-06-19  5:13   ` Ed L Cashin
2003-06-20 15:07     ` Kevin Rodgers

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.