home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / alt / lucidem / help / 691 next >
Encoding:
Text File  |  1992-11-16  |  10.1 KB  |  252 lines

  1. x-gateway: rodan.UU.NET from help-lucid-emacs to alt.lucid-emacs.help; Mon, 16 Nov 1992 08:24:43 EST
  2. Date: Mon, 16 Nov 1992 13:19:07 GMT
  3. From: djh@CIS.Prime.COM (David Hughes)
  4. Message-ID: <9211161319.AA19117@CIS.Prime.COM>
  5. Subject: Re: Minor addition for find-dired.el
  6. Newsgroups: alt.lucid-emacs.help
  7. Path: sparky!uunet!wendy-fate.uu.net!help-lucid-emacs
  8. Sender: help-lucid-emacs-request@lucid.com
  9. Lines: 241
  10.  
  11. Excerpt of message (sent 5 November 92) by Russell Ritchie:
  12. > Here's a quick and dirty addition for find-dired.el that let's you run lots
  13. > of finds at once (good if you still haven't found what you're looking for)...
  14. > 83c
  15. >   ;; (switch-to-buffer (get-buffer-create "*Find*"))
  16. >   (switch-to-buffer (generate-new-buffer "*Find*"))
  17.  
  18. Here is another patch for dired/find-dired.el based on Russell's idea. This
  19. supplies an autoloading variable 'find-dired-multiple-buffers' which if non
  20. nil causes find-dired to create a new buffer per find. It also changes the
  21. buffer name to something more meaningful.
  22.  
  23. Enjoy.
  24.  
  25. --
  26. Regards, David
  27.  
  28. 8< ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CUT HERE for file: find-dired.el
  29. ;;; find-dired.el -- Run a `find' command and dired the output
  30. ;;; Copyright (C) 1991 Roland McGrath
  31.  
  32. (defconst find-dired-version (substring "!Revision: 1.14 !" 11 -2)
  33.   "Id: find-dired.el,v 1.14 1992/04/16 14:22:07 sk RelBeta ")
  34.  
  35. ;;; This program is free software; you can redistribute it and/or modify
  36. ;;; it under the terms of the GNU General Public License as published by
  37. ;;; the Free Software Foundation; either version 2, or (at your option)
  38. ;;; any later version.
  39. ;;;
  40. ;;; This program is distributed in the hope that it will be useful,
  41. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  42. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  43. ;;; GNU General Public License for more details.
  44. ;;;
  45. ;;; A copy of the GNU General Public License can be obtained from this
  46. ;;; program's author (send electronic mail to roland@ai.mit.edu) or from
  47. ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
  48. ;;; 02139, USA.
  49. ;;;
  50. ;; LISPDIR ENTRY for the Elisp Archive ===============================
  51. ;;    LCD Archive Entry:
  52. ;;    find-dired|Roland McGrath, Sebastian Kremer
  53. ;;    |roland@gnu.ai.mit.edu, sk@thp.uni-koeln.de
  54. ;;    |Run a `find' command and dired the output
  55. ;;    |Date: 1992/04/16 14:22:07 |Revision: 1.14 |
  56.  
  57. ;; INSTALLATION ======================================================
  58.  
  59. ;; To use this file, byte-compile it, install it somewhere in your
  60. ;; load-path, and put:
  61.  
  62. ;;   (autoload 'find-dired "find-dired" nil t)
  63. ;;   (autoload 'find-name-dired "find-dired" nil t)
  64. ;;   (autoload 'find-grep-dired "find-dired" nil t)
  65.  
  66. ;; in your ~/.emacs, or site-init.el, etc.
  67.  
  68. ;; To bind it to a key, put, e.g.:
  69. ;;
  70. ;;   (global-set-key "\C-cf" 'find-dired)
  71. ;;   (global-set-key "\C-cn" 'find-name-dired)
  72. ;;   (global-set-key "\C-cl" 'find-grep-dired)
  73. ;;
  74. ;; in your ~/.emacs.
  75.  
  76. (require 'dired)
  77. (provide 'find-dired)
  78.  
  79. ;;;###autoload
  80. (defvar find-ls-option (if (eq system-type 'berkeley-unix) "-ls"
  81.                          "-exec ls -ldi {} \\;")
  82.   "*Option to `find' to produce an `ls -l'-type listing.")
  83.  
  84. ;;;###autoload
  85. (defvar find-grep-options (if (eq system-type 'berkeley-unix) "-s" "-l")
  86.   "*Option to grep to be as silent as possible.
  87. On Berkeley systems, this is `-s', for others it seems impossible to
  88. suppress all output, so `-l' is used to print nothing more than the
  89. file name.")
  90.  
  91. ;;;###autoload
  92. (defvar find-dired-multiple-buffers t
  93.   "*If non-nil, generates a new buffer for each find")
  94.  
  95. (defvar find-args nil
  96.   "Last arguments given to `find' by \\[find-dired].")
  97.  
  98. ;;;###autoload
  99. (defun find-dired (dir args)
  100.   "Run `find' and go into dired-mode on a buffer of the output.
  101. The command run (after changing into DIR) is
  102.  
  103.     find . \\( ARGS \\) -ls"
  104.   (interactive (list (read-file-name "Run find in directory: " nil "" t)
  105.                      (if (featurep 'gmhist)
  106.                          (read-with-history-in 'find-args-history
  107.                                                "Run find (with args): ")
  108.                        (read-string "Run find (with args): " find-args))))
  109.   ;; Expand DIR ("" means default-directory), and make sure it has a
  110.   ;; trailing slash.
  111.   (setq dir (file-name-as-directory (expand-file-name dir)))
  112.   ;; Check that it's really a directory.
  113.   (or (file-directory-p dir)
  114.       (error "find-dired needs a directory: %s" dir))
  115.   (switch-to-buffer (if find-dired-multiple-buffers
  116.                         (generate-new-buffer (concat "*Find-in-"
  117.                                                      (file-name-nondirectory (directory-file-name dir))
  118.                                                      "/..*"))
  119.                       (get-buffer-create "*Find*")))
  120.   (widen)
  121.   (kill-all-local-variables)
  122.   (setq buffer-read-only nil)
  123.   (erase-buffer)
  124.   (setq default-directory dir
  125.         find-args args                  ; save for next interactive call
  126.         args (concat "find . "
  127.                      (if (string= args "")
  128.                          ""
  129.                        (concat "\\( " args " \\) "))
  130.                      find-ls-option))
  131.   ;; The next statement will bomb in classic dired (no optional arg allowed)
  132.   ;; find(1)'s -ls corresponds to these switches.
  133.   ;; Note -b, at least GNU find quotes spaces etc. in filenames
  134.   (dired-mode dir "-gilsb")
  135.   ;; Set subdir-alist so that Tree Dired will work:
  136.   (if (fboundp 'dired-simple-subdir-alist)
  137.       ;; will work even with nested dired format (dired-nstd.el,v 1.15
  138.       ;; and later)
  139.       (dired-simple-subdir-alist)
  140.     ;; else we have an ancient tree dired (or classic dired, where
  141.     ;; this does no harm)
  142.     (set (make-local-variable 'dired-subdir-alist)
  143.          (list (cons default-directory (point-min-marker)))))
  144.   (setq buffer-read-only nil)
  145.   ;; Subdir headlerline must come first because the first marker in
  146.   ;; subdir-alist points there.
  147.   (insert "  " dir ":\n")
  148.   ;; Make second line a ``find'' line in analogy to the ``total'' or
  149.   ;; ``wildcard'' line.
  150.   (insert "  " args "\n")
  151.   ;; Start the find process
  152.   (set-process-filter (start-process-shell-command "find"
  153.                                                    (current-buffer) args)
  154.                       (function find-dired-filter))
  155.   (set-process-sentinel (get-buffer-process (current-buffer))
  156.                         (function find-dired-sentinel))
  157.   (setq mode-line-process '(": %s")))
  158.  
  159. ;;;###autoload
  160. (defun find-name-dired (dir pattern)
  161.   "Search DIR recursively for files matching the globbing pattern PATTERN,
  162. and run dired on those files.
  163. PATTERN is a shell wildcard (not an Emacs regexp) and need not be quoted.
  164. The command run (after changing into DIR) is
  165.  
  166.     find . -name 'PATTERN' -ls"
  167.   (interactive
  168.    "DFind-name (directory): \nsFind-name (filename wildcard): ")
  169.   (find-dired dir (concat "-name '" pattern "'")))
  170.  
  171. ;; This functionality suggested by
  172. ;; From: oblanc@watcgl.waterloo.edu (Olivier Blanc)
  173. ;; Subject: find-dired, lookfor-dired
  174. ;; Date: 10 May 91 17:50:00 GMT
  175. ;; Organization: University of Waterloo
  176.  
  177. (fset 'lookfor-dired 'find-grep-dired)
  178. ;;;###autoload
  179. (defun find-grep-dired (dir args)
  180.   "Find files in DIR containing a regexp ARG and start Dired on output.
  181. The command run (after changing into DIR) is
  182.  
  183.     find . (-type f -exec test -r {} \\\; -exec grep -s ARG {} \\\; -ls
  184.  
  185. Thus ARG can also contain additional grep options."
  186.   (interactive "DFind-grep (directory): \nsFind-grep (grep args): ")
  187.   ;; find -exec doesn't allow shell i/o redirections in the command,
  188.   ;; or we could use `grep -l >/dev/null'
  189.   (find-dired dir
  190.               (concat "-type f -exec test -r {} \\\; -exec grep " find-grep-options " " args " {} \\\; ")))
  191.  
  192. (defun find-dired-filter (proc string)
  193.   ;; Filter for \\[find-dired] processes.
  194.   (let ((buf (process-buffer proc)))
  195.     (if (buffer-name buf)               ; not killed?
  196.         (save-excursion
  197.           (set-buffer buf)
  198.           (save-restriction
  199.             (widen)
  200.             (save-excursion
  201.               (let ((buffer-read-only nil)
  202.                     (end (point-max)))
  203.                 (goto-char end)
  204.                 (insert string)
  205.                 (goto-char end)
  206.                 (or (looking-at "^")
  207.                     (forward-line 1))
  208.                 (while (looking-at "^")
  209.                   (insert "  ")
  210.                   (forward-line 1))
  211.                 ;; Convert ` ./FILE' to ` FILE'
  212.                 ;; This would lose if the current chunk of output
  213.                 ;; starts or ends within the ` ./', so backup up a bit:
  214.                 (goto-char (- end 3))   ; no error if < 0
  215.                 (while (search-forward " ./" nil t)
  216.                   (delete-region (point) (- (point) 2)))))))
  217.       ;; The buffer has been killed.
  218.       (delete-process proc))))
  219.  
  220. (defun find-dired-sentinel (proc state)
  221.   ;; Sentinel for \\[find-dired] processes.
  222.   (let ((buf (process-buffer proc)))
  223.     (if (buffer-name buf)
  224.         (save-excursion
  225.           (set-buffer buf)
  226.           (toggle-read-only)
  227.           (setq mode-line-process ": Done")
  228.           (save-excursion
  229.             (let ((msg (format "find-dired %s finished." (current-buffer))))
  230.               (set-buffer (window-buffer (minibuffer-window)))
  231.               (insert (substring msg 0 (1- (length msg))))))))))
  232.  
  233. (or (fboundp 'start-process-shell-command)
  234.     ;; From version 19 subr.el.
  235.     (defun start-process-shell-command (name buffer &rest args)
  236.       "Start a program in a subprocess.  Return the process object for it.
  237. Args are NAME BUFFER COMMAND &rest COMMAND-ARGS.
  238. NAME is name for process.  It is modified if necessary to make it unique.
  239. BUFFER is the buffer or (buffer-name) to associate with the process.
  240.  Process output goes at end of that buffer, unless you specify
  241.  an output stream or filter function to handle the output.
  242.  BUFFER may be also nil, meaning that this process is not associated
  243.  with any buffer
  244. Third arg is command name, the name of a shell command.
  245. Remaining arguments are the arguments for the command.
  246. Wildcards and redirection are handle as usual in the shell."
  247.       (if (eq system-type 'vax-vms)
  248.           (apply 'start-process name buffer args)
  249.         (start-process name buffer shell-file-name "-c"
  250.                        (concat "exec " (mapconcat 'identity args " "))))))
  251.