emacs-devel
[Top][All Lists]
Advanced

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

RE: find-file-read-args: cursor's file as default in Dired


From: Drew Adams
Subject: RE: find-file-read-args: cursor's file as default in Dired
Date: Tue, 10 Jul 2007 17:49:16 -0700

> >>     Here's what it should be, so that `M-n' with `C-x C-f' gives
> >>     you the file of the cursor in Dired mode:
> >>
> >> That is a good feature.  Would you please send a patch and change log
> >> entry, and text for etc/NEWS?
> >
> > ----------------8<----------------------------------
> >
> > 2007-07-10  Drew Adams  <address@hidden>
> >
> >       *files.el (find-file-read-args): Default in Dired mode is
> >       cursor's file.
>
> `dired-get-file-for-visit' causes `C-x C-f' to fail when typed on
> a non-file line in the dired buffer.

Good catch. How about one of these instead? I prefer the second; it's
simpler and quicker (`minibuffer-message' pauses).

;; This one gives you error feedback.
(defun find-file-read-args (prompt mustmatch)
  (list (let ((find-file-default
               (if (eq major-mode 'dired-mode)
                   (let ((this-file
                          (condition-case err
                              (dired-get-file-for-visit)
                            (error
                             (and (save-selected-window
                                    (select-window (minibuffer-window))
                                    (minibuffer-message
                                     (error-message-string err))))))))
                     (and this-file (abbreviate-file-name this-file)))
                 (and buffer-file-name (abbreviate-file-name
                                        buffer-file-name)))))
          (minibuffer-with-setup-hook
              (lambda () (setq minibuffer-default find-file-default))
            (read-file-name prompt nil default-directory mustmatch)))
        t))

;; This one just gets on with it.
(defun find-file-read-args (prompt mustmatch)
  (list (let ((find-file-default
               (if (eq major-mode 'dired-mode)
                   (let ((this-file (condition-case nil
                                        (dired-get-file-for-visit)
                                      (error nil))))
                     (if this-file
                         (abbreviate-file-name this-file)
                       (and buffer-file-name (abbreviate-file-name
                                              buffer-file-name))))
                 (and buffer-file-name (abbreviate-file-name
                                        buffer-file-name)))))
          (minibuffer-with-setup-hook
              (lambda () (setq minibuffer-default find-file-default))
            (read-file-name prompt nil default-directory mustmatch)))
        t))






reply via email to

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