all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "Juri Linkov" <juri@jurta.org>
Cc: rms@gnu.org, emacs-devel@gnu.org
Subject: RE: find-file-read-args: cursor's file as default in Dired
Date: Tue, 10 Jul 2007 17:49:16 -0700	[thread overview]
Message-ID: <BNELLINCGFJLDJIKDGACMEGPCAAA.drew.adams@oracle.com> (raw)
In-Reply-To: <877ip77t8u.fsf@jurta.org>

> >>     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  <drew.adams@oracle.com>
> >
> >       *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	other threads:[~2007-07-11  0:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-10  2:32 find-file-read-args: cursor's file as default in Dired Drew Adams
2007-07-10 22:01 ` Richard Stallman
2007-07-10 22:34   ` Drew Adams
2007-07-10 23:17     ` Juri Linkov
2007-07-11  0:49       ` Drew Adams [this message]
2007-07-11  2:33         ` Stefan Monnier
2007-07-11  8:04         ` Juri Linkov
2007-07-11 15:20           ` Drew Adams
2007-07-11 22:59             ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BNELLINCGFJLDJIKDGACMEGPCAAA.drew.adams@oracle.com \
    --to=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    --cc=juri@jurta.org \
    --cc=rms@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.