bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#15504: 24.3; find-dired's numerous prompts are inflexible and annoyi


From: Trent W. Buck
Subject: bug#15504: 24.3; find-dired's numerous prompts are inflexible and annoying
Date: Wed, 02 Oct 2013 11:45:16 +1000

I prefer to do M-x grep RET and then type something complicated like

    grep -r --include '*.c' --exclude-dir .git . -e foo -e bar

...rather than M-x rgrep which has lots of stupid prompts that then get
stuck together in a fixed kind of way.

In the same vein, I hate M-x find dired RET multiple prompts.  For a few
years I've been using a munged up replacement that just asks for a
single command, and runs it (below).  The history handling is a bit
buggered, and it breaks the existing multi-prompt style (presumably some
people prefer it).

Daniel Colascione liked my approach and asked me to publish it,
(presumably) so it can be cleaned up and pushed into Emacs proper.
I don't care enough to do that work myself, but I'm happy to talk to
anyone who does.  I've already done the copyright assignment dance.

PS: find -ls's output is actually crap, because the entries don't line
up properly and files with spaces become "foo\ bar" which dired mode
doesn't like, so I generally end up doing "find -exec ls -lidsh {} +".


(setq
 find-ls-option                         ; http://emacsbugs.donarmstrong.com/4403
 (let ((help (shell-command-to-string (format "%s --help" find-program))))
   (if (string-match " -ls\\>" help)
       '("-ls" . "-lids")
     (if (string-match "{} \\+" help)
         '("-exec ls -ldh {} +" . "-ldh")
       '("-exec ls -ldh {} \\;" . "-ldh")))))

;;; Guerilla patch -- redefine FIND-DIRED to act less like RGREP and more like
;;; GREP.  That is, prompt for an arbitrary command instead of "helpfully"
;;; constructing a command from an inflexible series of prompts.  Defaults to
;;; "find -ls"; "find -exec ls {} +" is also possible to e.g. sort by file size.
(eval-after-load "dired"
  '(eval-after-load "find-dired"
     '(progn
        (defvar find-command/twb (concat find-program " " (car find-ls-option)))
        (defvar find-command-history/twb nil)
        (defun find-dired (command)
          "Like find-dired, but let me just WRITE the command instead of
trying to construct it for me.  Cf. `grep' vs. `rgrep'."
          (interactive (list (read-string "Run find: " find-command/twb 
'(find-command-history/twb . 1))))
          (let ((dired-buffers dired-buffers)
                (dir default-directory))
            (switch-to-buffer (get-buffer-create "*Find*"))
            (setq default-directory dir)

            ;; See if there's still a `find' running, and offer to kill
            ;; it first, if it is.
            (let ((find (get-buffer-process (current-buffer))))
              (when find
                (if (or (not (eq (process-status find) 'run))
                        (yes-or-no-p "A `find' process is running; kill it? "))
                    (condition-case nil
                        (progn
                          (interrupt-process find)
                          (sit-for 1)
                          (delete-process find))
                      (error nil))
                  (error "Cannot have two processes in `%s' at once" 
(buffer-name)))))

            (widen)
            (kill-all-local-variables)
            (setq buffer-read-only nil)
            (erase-buffer)
            (setq find-command command) ; save for next interactive call
            ;; Start the find process.
            (shell-command (concat command "&") (current-buffer))
            ;; The next statement will bomb in classic dired (no optional arg 
allowed)
            (dired-mode default-directory (cdr find-ls-option))
            (let ((map (make-sparse-keymap)))
              (set-keymap-parent map (current-local-map))
              (define-key map "\C-c\C-k" 'kill-find)
              (use-local-map map))
            (make-local-variable 'dired-sort-inhibit)
            (setq dired-sort-inhibit t)
            (set (make-local-variable 'revert-buffer-function)
                 `(lambda (ignore-auto noconfirm)
                    (find-dired ,find-command)))
            ;; Set subdir-alist so that Tree Dired will work:
            (if (fboundp 'dired-simple-subdir-alist)
                ;; will work even with nested dired format (dired-nstd.el,v 1.15
                ;; and later)
                (dired-simple-subdir-alist)
              ;; else we have an ancient tree dired (or classic dired, where
              ;; this does no harm)
              (set (make-local-variable 'dired-subdir-alist)
                   (list (cons default-directory (point-min-marker)))))
            (set (make-local-variable 'dired-subdir-switches) 
find-ls-subdir-switches)
            (setq buffer-read-only nil)
            ;; Subdir headlerline must come first because the first marker in
            ;; subdir-alist points there.
            (insert "  " default-directory ":\n")
            ;; Make second line a ``find'' line in analogy to the ``total'' or
            ;; ``wildcard'' line.
            (insert "  " command "\n")
            (setq buffer-read-only t)
            (let ((proc (get-buffer-process (current-buffer))))
              (set-process-filter proc (function find-dired-filter))
              (set-process-sentinel proc (function find-dired-sentinel))
              ;; Initialize the process marker; it is used by the filter.
              (move-marker (process-mark proc) 1 (current-buffer)))
            (setq mode-line-process '(":%s")))))))




In GNU Emacs 24.3.1 (armv7l-unknown-linux-gnueabi)
 of 2013-03-15 on elba
System Description:     Ubuntu 11.10

Configured using:
 `configure '--without-x' '--without-sound' '--without-all'
 '--with-x-toolkit=no' '--with-xpm=no' '--with-gif=no' '--with-jpeg=no'
 '--with-tiff=no' '--with-png=no' '--with-dbus=no' '--with-gsettings=no'
 '--with-gnutls=no' '--prefix=/home/twb/opt/emacs-24.3''





reply via email to

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