unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Juri Linkov <juri@jurta.org>
Cc: martin rudalics <rudalics@gmx.at>, emacs-devel@gnu.org
Subject: Re: find-file-read-args
Date: Mon, 23 Nov 2009 15:17:57 -0500	[thread overview]
Message-ID: <jwvbpithvd0.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87bpit1ql9.fsf@mail.jurta.org> (Juri Linkov's message of "Mon, 23 Nov 2009 11:59:54 +0200")

>> so I'd like to understand how you reproduce it.

> This can be reproduced by typing M-n in the minibuffer of commands
> other than find-file-*, e.g. `insert-file', `append-to-file',
> `write-file', `write-region', `load-file', `recode-file-name',
> `make-directory', `delete-directory', `copy-directory'.

I meant "how does your code reproduce the right behavior for C-x C-f".
But I think I'm beginning to understand why it works.

>>> + 	   ((eq major-mode 'dired-mode)
>>> + 	    (let ((filename (dired-get-filename nil t)))
>>> + 	      (when filename
>>> + 		(if (file-directory-p filename)
>>> + 		    (file-name-as-directory (abbreviate-file-name filename))
>>> + 		  (abbreviate-file-name filename)))))))
>> This is ugly.  Why does it have to be here rather than somewhere in dired?
> I can't find a function in dired.el and dired-aux.el that uses
> `abbreviate-file-name' necessary for the minibuffer reading a file name.

We must be miscommunicating: I don't want to have dired-specific code
(including no test for (eq major-mode 'dired-mode)) in read-file-name,
because it's ugly.  Can't the same behavior be obtained by changing some
code in dired rather than in minibuffer.el?

>>> + 	(filename-at-point
>>> + 	 (cond
>>> + 	  ((fboundp 'ffap-guesser)
>>> + 	   ;; Logic from `ffap-read-file-or-url' and `dired-at-point-prompter'
>>> + 	   (let ((guess (ffap-guesser)))
>>> + 	     (setq guess
>>> + 		   (if (or (not guess)
>>> + 			   (and (fboundp 'ffap-url-p)
>>> + 				(ffap-url-p guess))
>>> + 			   (and (fboundp 'ffap-file-remote-p)
>>> + 				(ffap-file-remote-p guess)))
>>> + 		       guess
>>> + 		     (abbreviate-file-name (expand-file-name guess))))
>>> + 	     (when guess
>>> + 	       (if (file-directory-p guess)
>>> + 		   (file-name-as-directory guess)
>>> + 		 guess))))
>>> + 	  ;; ((fboundp 'thing-at-point)
>>> + 	  ;;  (thing-at-point 'filename))
>>> + 	  )))
>> 
>> I think this should be moved to a separate function (e.g. so it can be
>> used by a separate key-binding) in file.el.  That function could/should
>> obey a new hook file-name-at-point-functions hook which we'd run with
>> run-hook-with-args-until-success.

> OK, I'll create a new function that could later be bound to a dedicated key.

Thanks.  Tho it doesn't need to be a command (e.g. that function
shouldn't want to insert anything into the buffer, so it'll probably be
better to have a separate command, unless we want to rely on
called-interactively-p).

>> Is it really necessary to throw away the minibuffer-default if it's not
>> a cons?  I'd rather keep it and just add file-name-at-point.  That would
>> make the change a lot more "obviously safe".
> For most file/directory reading functions the minibuffer-default
> duplicates the initial input, so the first typing M-n is useless since
> it doesn't change the minibuffer's contents.

Right, and that's what the minibuffer-setup-hook thingy in
find-file-read-args was trying to do.

> I'll try to better detect this situation than checking for a cons.

Yes, I think your solution is at least as good as the previous one.
But please check explicitly for "default == initial input", that will
make the code both safer and easier to understand.

>>> Index: lisp/dired-aux.el
>> Am I right that this part of the change is not strictly necessary?

> dired-aux.el is from other threads with the subject
> "dired-dwim-target" and "dired-dwim-target-directory" that has
> separate reasonings for separate but related changes.  I'll send a new
> patch for dired-aux.el in another message.

That was my impression as well.  Thank you for separating them.


        Stefan




  reply	other threads:[~2009-11-23 20:17 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-06  0:13 find-file-literally-at-point Edward O'Connor
2009-11-06  1:45 ` find-file-literally-at-point Juri Linkov
2009-11-06  4:20   ` FFAP (was: find-file-literally-at-point) Stefan Monnier
2009-11-06  4:41     ` FFAP Miles Bader
2009-11-06 15:20       ` FFAP Stefan Monnier
2009-11-06  4:45     ` FFAP Juri Linkov
2009-11-06  8:50       ` FFAP Eli Zaretskii
2009-11-06 10:37         ` FFAP Juri Linkov
2009-11-06 15:18       ` FFAP Stefan Monnier
2009-11-06 21:19         ` FFAP Juri Linkov
2009-11-07  1:32           ` FFAP Stefan Monnier
2009-11-09  0:52             ` FFAP Juri Linkov
2009-11-09  6:33               ` FFAP Stefan Monnier
2009-11-09 10:09           ` find-file-read-args (was: FFAP) Juri Linkov
2009-11-09 14:28             ` find-file-read-args Stefan Monnier
2009-11-10  0:57               ` find-file-read-args Juri Linkov
2009-11-12  9:56               ` find-file-read-args Juri Linkov
2009-11-12 10:45                 ` find-file-read-args martin rudalics
2009-11-12 10:51                   ` find-file-read-args Juri Linkov
2009-11-15 15:09                     ` find-file-read-args Juri Linkov
2009-11-15 17:28                       ` find-file-read-args martin rudalics
2009-11-16  1:23                         ` find-file-read-args Stefan Monnier
2009-11-17  7:43                           ` find-file-read-args martin rudalics
2009-11-17  9:59                             ` find-file-read-args Juri Linkov
2009-11-17 17:42                               ` dired-dwim-target-directory (was: find-file-read-args) Juri Linkov
2009-11-17 17:43                               ` Juri Linkov
2009-11-23  4:19                               ` find-file-read-args Stefan Monnier
2009-11-23  9:59                                 ` find-file-read-args Juri Linkov
2009-11-23 20:17                                   ` Stefan Monnier [this message]
2009-11-23 21:17                                     ` find-file-read-args Juri Linkov
2009-11-24  2:33                                       ` find-file-read-args Stefan Monnier
2009-11-24 17:08                                         ` find-file-read-args Juri Linkov
2009-11-24 19:40                                           ` find-file-read-args Stefan Monnier
2009-11-23 21:17                                 ` find-file-literally (was: find-file-read-args) Juri Linkov
2009-11-25  2:10                                   ` find-file-literally Stefan Monnier
2009-11-09 10:14           ` read-file-name (was: FFAP) Juri Linkov
2009-11-09 14:31             ` read-file-name Stefan Monnier
2009-11-10  0:55               ` read-file-name Juri Linkov
2009-11-10 17:25                 ` read-file-name Stefan Monnier
2009-11-09 10:30           ` dired-read-dir-and-switches (was: FFAP) Juri Linkov
2009-11-09 10:36           ` M-! M-n should fetch filename (Re: FFAP) Juri Linkov
2009-11-09 14:35             ` Stefan Monnier
2009-11-10  0:59               ` Juri Linkov
2009-11-10 17:29                 ` Stefan Monnier
2009-11-11  0:12                   ` Juri Linkov
2009-11-15 15:12           ` dired-dwim-target (was: FFAP) Juri Linkov
2009-11-23 21:12             ` dired-dwim-target-defaults (was: dired-dwim-target) Juri Linkov
2009-11-09  0:44   ` find-file-literally-at-point Juri Linkov
2009-11-09  2:00     ` find-file-literally-at-point Miles Bader
2009-11-09  2:11       ` find-file-literally-at-point Juri Linkov
2009-11-10  0:49         ` find-file-literally-at-point Juri Linkov
2009-11-09 10:01   ` utf-8-with-signature (was: find-file-literally-at-point) Juri Linkov
2009-11-06 10:20 ` find-file-literally-at-point Eduard Wiebe
2009-11-09  0:55   ` find-file-literally-at-point Juri Linkov
2009-11-09 19:49     ` find-file-literally-at-point Eduard Wiebe

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=jwvbpithvd0.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=juri@jurta.org \
    --cc=rudalics@gmx.at \
    /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 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).