From dartvax!bu.edu!lll-winken!uunet!wuarchive!mit-eddie!uw-beaver!cornell!stefan Mon May 6 17:41:53 EDT 1991 Article: 1823 of gnu.emacs.help Path: dartvax!bu.edu!lll-winken!uunet!wuarchive!mit-eddie!uw-beaver!cornell!stefan From: stefan@CS.Cornell.EDU (Kjartan Stefansson) Newsgroups: gnu.emacs.help Subject: Re: Can Dired "find" ? Message-ID: <1991May6.142147.29911@cs.cornell.edu> Date: 6 May 91 14:21:47 GMT References: <1991May6.055120.13435@dartvax.dartmouth.edu> Sender: news@cs.cornell.edu (USENET news user) Organization: Cornell Univ. CS Dept, Ithaca NY 14853 Lines: 38 Nntp-Posting-Host: moot.cs.cornell.edu harelb@cabot (Harel Barzilai) writes: >I know I can type "C-x d" and then give a regexp like "*foo*" ; but >dired does this *within a given directory* There is an ugly "find" >command I can barely use and don't understand well, which can look >thru subdirectories, recursively. I agree that the find command is ugly. But once you understand it, it's easy to use. I have an alias in my .cshrc file as follows: alias search "find . -name ''\!*'' -print" so when I type search '*foo*' it prints out all occurrences of *foo*, searching recursively through subdirectories. >Is there a way to make dired to this, or does someone have code I >could put into my .emacs? If you want an emacs command for this, here is one. It simply invokes the find-command. You can put this code in your .emacs file and bind it to some appropriate key: (defun my-find(REGEXP) "Finds and lists files matching REGEXP in current directory" (interactive "sEnter file pattern: ") (shell-command (concat "find . -name \"" REGEXP "\" -print"))) >Many thanks, >Harel Enjoy, Kjartan (stefan@cs.cornell.edu) ################################################################## From dartvax!hsdndev!wuarchive!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!pacbell.com!lll-winken!iggy.GW.Vitalink.COM!widener!ukma!usenet.ins.cwru.edu!tut.cis.ohio-state.edu!unreplyable!garbage Wed May 8 01:30:22 EDT 1991 ################################################################## Article: 297 of gnu.emacs.sources Path: dartvax!hsdndev!wuarchive!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!pacbell.com!lll-winken!iggy.GW.Vitalink.COM!widener!ukma!usenet.ins.cwru.edu!tut.cis.ohio-state.edu!unreplyable!garbage From: roland@CHURCHY.GNU.AI.MIT.EDU (Roland McGrath) Newsgroups: gnu.emacs.sources Subject: find-dired.el -- Run a `find' command and dired the result. Message-ID: <9105070227.AA06805@churchy.gnu.ai.mit.edu> Date: 6 May 91 21:27:50 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: Source only Discussion and requests in gnu.emacs.help. Lines: 94 This package lets you run a `find' command get a buffer doing dired on the result. You can use the buffer while the `find' is still running, doing things with the files which have been found so far. ;;; find-dired.el -- Run a `find' command and dired the result. ;;; Copyright (C) 1991 Roland McGrath ;;; ;;; This program is free software; you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 1, or (at your option) ;;; any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; A copy of the GNU General Public License can be obtained from this ;;; program's author (send electronic mail to roland@ai.mit.edu) or from ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA ;;; 02139, USA. ;;; ;;; Send bug reports to roland@gnu.ai.mit.edu. ;;; To use this file, byte-compile it, install it somewhere ;;; in your load-path, and put: ;;; (autoload 'find-dired "find-dired" nil t) ;;; in your .emacs, or site-init.el, etc. ;;; To bind it to a key, put, e.g.: ;;; (global-set-key "\C-cf" 'find-dired) ;;; in your .emacs. (require 'dired) (defvar find-args nil "Last arguments given to `find' by \\[find-dired].") (defun find-dired (dir args) "Run `find' and go into dired-mode on a buffer of the output. The command run is \"find . \\( ARGS \\) -ls\" (after changing into DIR)." (interactive (list (read-file-name "Run find in directory: " nil "" t) (read-string "Run find (with args): " find-args))) (if (equal dir "") (setq dir default-directory)) ;; Expand DIR, and make sure it has a trailing slash. (setq dir (file-name-as-directory (expand-file-name dir))) ;; Check that it's really a directory. (or (file-directory-p dir) (error "%s is not a directory!" dir)) (switch-to-buffer (get-buffer-create "*Find*")) (widen) (kill-all-local-variables) (setq buffer-read-only nil) (erase-buffer) (setq default-directory dir find-args args args (concat "find . \\( " args " \\) -ls")) (insert " " args "\n" " " dir ":\n") (set-process-filter (start-process-shell-command "find" (current-buffer) args) 'find-dired-filter) (set-process-sentinel (get-buffer-process (current-buffer)) 'find-dired-sentinel) (dired-mode) (setq mode-line-process '(": %s"))) (defun find-dired-filter (proc string) "Filter for \\[find-dired] processes." (save-excursion (set-buffer (process-buffer proc)) (save-restriction (widen) (save-excursion (let ((end (point-max)) (match-data (match-data)) (buffer-read-only nil)) (unwind-protect (progn (goto-char end) (insert string) (goto-char end) (while (re-search-forward "^" nil t) (insert " "))) (store-match-data match-data))))))) (defun find-dired-sentinel (proc state) "Sentinel for \\[find-dired] processes." (save-excursion (set-buffer (process-buffer proc)) (setq mode-line-process nil) (message "%s is done finding." (current-buffer)))) (provide 'find-dired)