unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* find-file-read-args: cursor's file as default in Dired
@ 2007-07-10  2:32 Drew Adams
  2007-07-10 22:01 ` Richard Stallman
  0 siblings, 1 reply; 9+ messages in thread
From: Drew Adams @ 2007-07-10  2:32 UTC (permalink / raw)
  To: Emacs-Devel

Here's find-file-read-args:

(defun find-file-read-args (prompt mustmatch)
  (list (let ((find-file-default
	       (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))

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:

(defun find-file-read-args (prompt mustmatch)
  (list (let ((find-file-default
               (if (eq major-mode 'dired-mode)
                   (abbreviate-file-name (dired-get-file-for-visit))
                 (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))

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: find-file-read-args: cursor's file as default in Dired
  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
  0 siblings, 1 reply; 9+ messages in thread
From: Richard Stallman @ 2007-07-10 22:01 UTC (permalink / raw)
  To: Drew Adams; +Cc: emacs-devel

    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?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: find-file-read-args: cursor's file as default in Dired
  2007-07-10 22:01 ` Richard Stallman
@ 2007-07-10 22:34   ` Drew Adams
  2007-07-10 23:17     ` Juri Linkov
  0 siblings, 1 reply; 9+ messages in thread
From: Drew Adams @ 2007-07-10 22:34 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

>     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.

----------------8<----------------------------------

diff -c "c:/drews-lisp-20/cvs-lisp/NEWS-22-2007-07-10.txt"
"c:/drews-lisp-20/cvs-lisp/NEWS-22-patched-2007-07-10.txt"
*** c:/drews-lisp-20/cvs-lisp/NEWS-22-2007-07-10.txt	Tue Jul 10 15:30:16
2007
--- c:/drews-lisp-20/cvs-lisp/NEWS-22-patched-2007-07-10.txt	Tue Jul 10
15:31:52 2007
***************
*** 4163,4168 ****
--- 4163,4171 ----
  modification times.  Magic file name handlers can handle this
  operation.

+ *** In Dired, the default file to visit with `find-file' is the file
+ on the same line as the cursor.
+
  ** Input changes:

  *** Functions `y-or-n-p', `read-char', `read-key-sequence' and the like,
that
----------------8<----------------------------------
diff -c "c:/drews-lisp-20/cvs-lisp/files-CVS-2007-07-10.el"
"c:/drews-lisp-20/cvs-lisp/files-CVS-patched-2007-07-10.el"
*** c:/drews-lisp-20/cvs-lisp/files-CVS-2007-07-10.el	Tue Jul 10 15:18:52
2007
--- c:/drews-lisp-20/cvs-lisp/files-CVS-patched-2007-07-10.el	Tue Jul 10
15:20:24 2007
***************
*** 1065,1076 ****

  (defun find-file-read-args (prompt mustmatch)
    (list (let ((find-file-default
! 	       (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))

  (defun find-file (filename &optional wildcards)
    "Edit file FILENAME.
--- 1065,1078 ----

  (defun find-file-read-args (prompt mustmatch)
    (list (let ((find-file-default
!                (if (eq major-mode 'dired-mode)
!                    (abbreviate-file-name (dired-get-file-for-visit))
!                  (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))

  (defun find-file (filename &optional wildcards)
    "Edit file FILENAME.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: find-file-read-args: cursor's file as default in Dired
  2007-07-10 22:34   ` Drew Adams
@ 2007-07-10 23:17     ` Juri Linkov
  2007-07-11  0:49       ` Drew Adams
  0 siblings, 1 reply; 9+ messages in thread
From: Juri Linkov @ 2007-07-10 23:17 UTC (permalink / raw)
  To: Drew Adams; +Cc: rms, emacs-devel

>>     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.

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: find-file-read-args: cursor's file as default in Dired
  2007-07-10 23:17     ` Juri Linkov
@ 2007-07-11  0:49       ` Drew Adams
  2007-07-11  2:33         ` Stefan Monnier
  2007-07-11  8:04         ` Juri Linkov
  0 siblings, 2 replies; 9+ messages in thread
From: Drew Adams @ 2007-07-11  0:49 UTC (permalink / raw)
  To: Juri Linkov; +Cc: rms, emacs-devel

> >>     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))

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: find-file-read-args: cursor's file as default in Dired
  2007-07-11  0:49       ` Drew Adams
@ 2007-07-11  2:33         ` Stefan Monnier
  2007-07-11  8:04         ` Juri Linkov
  1 sibling, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2007-07-11  2:33 UTC (permalink / raw)
  To: Drew Adams; +Cc: Juri Linkov, rms, emacs-devel

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

Again, please post context diffs rather than just code,


        Stefan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: find-file-read-args: cursor's file as default in Dired
  2007-07-11  0:49       ` Drew Adams
  2007-07-11  2:33         ` Stefan Monnier
@ 2007-07-11  8:04         ` Juri Linkov
  2007-07-11 15:20           ` Drew Adams
  1 sibling, 1 reply; 9+ messages in thread
From: Juri Linkov @ 2007-07-11  8:04 UTC (permalink / raw)
  To: Drew Adams; +Cc: rms, emacs-devel

>> `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).

Just use (dired-get-filename nil t).

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: find-file-read-args: cursor's file as default in Dired
  2007-07-11  8:04         ` Juri Linkov
@ 2007-07-11 15:20           ` Drew Adams
  2007-07-11 22:59             ` Juri Linkov
  0 siblings, 1 reply; 9+ messages in thread
From: Drew Adams @ 2007-07-11 15:20 UTC (permalink / raw)
  To: Juri Linkov; +Cc: rms, emacs-devel

> >> `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?
> 
> Just use (dired-get-filename nil t).

Great; go for it. 

(Were you aware of that simple solution when you reported the bug?)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: find-file-read-args: cursor's file as default in Dired
  2007-07-11 15:20           ` Drew Adams
@ 2007-07-11 22:59             ` Juri Linkov
  0 siblings, 0 replies; 9+ messages in thread
From: Juri Linkov @ 2007-07-11 22:59 UTC (permalink / raw)
  To: Drew Adams; +Cc: rms, emacs-devel

>> >> `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?
>>
>> Just use (dired-get-filename nil t).
>
> Great; go for it.
>
> (Were you aware of that simple solution when you reported the bug?)

No, sorry, while reporting a bug I wasn't sure something like this is better.
Later after looking at the error messages in the dired-get-file-for-visit
I realised that they are not necessary for the default value.

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-07-11 22:59 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).