all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: find-file-read-args (was: FFAP)
Date: Mon, 09 Nov 2009 12:09:33 +0200	[thread overview]
Message-ID: <871vk8uo0q.fsf@mail.jurta.org> (raw)
In-Reply-To: <87bpjfiark.fsf@mail.jurta.org> (Juri Linkov's message of "Fri, 06 Nov 2009 23:19:45 +0200")

> Let's see what currently M-n does in file prompts (0. means the default
> input, and 1. - the minibuffer's content after one M-n):
>
> `C-x C-f' in a non-file buffer:
> 0. current directory name
>
> `C-x C-f' in a file buffer:
> 0. current directory name
> 1. file name of the current buffer
>
> `C-x C-v' in a file buffer:
> 0. file name of the current buffer
> 1. file name of the current buffer
> (the last case has duplicates)
>
> After adding a file name at point:
>
> `C-x C-f' in a non-file buffer:
> 0. current directory name
> 1. file name at point
>
> `C-x C-f' in a file buffer:
> 0. current directory name
> 1. file name of the current buffer
> 2. file name at point
>
> `C-x C-v' in a file buffer:
> 0. file name of the current buffer
> 1. file name at point
>
> So M-n more than once is only in a file buffer,
> where we could add a file name at point before
> the file name of the current buffer:
>
> `C-x C-f' in a file buffer:
> 0. current directory name
> 1. file name at point
> 2. file name of the current buffer

The patch below implements this scheme, and additionally
includes an approved but not installed change proposed
by Drew in http://thread.gmane.org/gmane.emacs.devel/74534
that allows `M-n' with `C-x C-f' to get the file at point
in Dired mode.

Other changes are:

1. When `ffap-guesser' is available, use it to provide
   an additional default value.  Since currently its
   guesses are much better than from `thing-at-point',
   it makes sense to load ffap.el in .emacs but without
   rebinding file-related keys to their equivalents
   by `ffap-bindings'.  This way standard keys will remain
   bound to default functions that will use `ffap-guesser' to
   get the file name at point and provide it as default.

2. When ffap.el is not loaded, then use `thing-at-point'
   to provide an additional default value.  But currently
   this code is commented out in the patch below,
   because in the current state, `thing-at-point' is useless
   since it doesn't check if the file at point exists.
   It blindly proposes any word at point as a file name.
   Perhaps a new scheme should be implemented like e.g.
   (thing-at-point 'existing-filename).

3. Added two new optional arguments `dir' and `initial'
   for `find-file-read-args' to allow `find-alternate-file'
   to use features of `find-file-read-args' shared among
   all filename-reading functions.

4. For the same reason, `find-file-literally' now relies on
   `find-file-read-args' as well.

Index: lisp/files.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/files.el,v
retrieving revision 1.1098
diff -c -r1.1098 files.el
*** lisp/files.el	6 Nov 2009 05:16:27 -0000	1.1098
--- lisp/files.el	9 Nov 2009 10:04:57 -0000
***************
*** 1297,1309 ****
  	     ,@body)
  	 (remove-hook 'minibuffer-setup-hook ,hook)))))
  
! (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)
--- 1297,1332 ----
  	     ,@body)
  	 (remove-hook 'minibuffer-setup-hook ,hook)))))
  
! (defun find-file-read-args (prompt mustmatch &optional dir initial)
    (list (let ((find-file-default
! 	       (cond
! 		(initial nil) ; don't duplicate initial and default values
! 		((eq major-mode 'dired-mode)
! 		 (and (dired-get-filename nil t)
! 		      (abbreviate-file-name (dired-get-filename nil t))))
! 		(buffer-file-name
! 		 (abbreviate-file-name buffer-file-name))))
! 	      (file-at-point
! 	       (cond ((fboundp 'ffap-guesser)
! 		      (let ((guess (ffap-guesser)))
! 			(if (or (not (stringp 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)))))
! 		     ;; ((fboundp 'thing-at-point)
! 		     ;;  (thing-at-point 'filename))
! 		     )))
! 	  (when file-at-point
! 	    (setq find-file-default
! 		  (delq nil (delete "" (delete-dups
! 					(list file-at-point
! 					      find-file-default))))))
  	  (minibuffer-with-setup-hook
  	      (lambda () (setq minibuffer-default find-file-default))
! 	    (read-file-name prompt dir default-directory mustmatch initial)))
  	t))
  
  (defun find-file (filename &optional wildcards)
***************
*** 1460,1469 ****
         (and file
  	    (setq file-name (file-name-nondirectory file)
  		  file-dir (file-name-directory file)))
!        (list (read-file-name
! 	      "Find alternate file: " file-dir nil
!               (confirm-nonexistent-file-or-buffer) file-name)
! 	     t))))
    (if (one-window-p)
        (find-file-other-window filename wildcards)
      (save-selected-window
--- 1483,1491 ----
         (and file
  	    (setq file-name (file-name-nondirectory file)
  		  file-dir (file-name-directory file)))
!        (find-file-read-args "Find alternate file: "
! 			    (confirm-nonexistent-file-or-buffer)
! 			    file-dir file-name))))
    (if (one-window-p)
        (find-file-other-window filename wildcards)
      (save-selected-window
***************
*** 1490,1499 ****
       (and file
  	  (setq file-name (file-name-nondirectory file)
  		file-dir (file-name-directory file)))
!      (list (read-file-name
! 	    "Find alternate file: " file-dir nil
!             (confirm-nonexistent-file-or-buffer) file-name)
! 	   t)))
    (unless (run-hook-with-args-until-failure 'kill-buffer-query-functions)
      (error "Aborted"))
    (when (and (buffer-modified-p) buffer-file-name)
--- 1512,1520 ----
       (and file
  	  (setq file-name (file-name-nondirectory file)
  		file-dir (file-name-directory file)))
!      (find-file-read-args "Find alternate file: "
! 			  (confirm-nonexistent-file-or-buffer)
! 			  file-dir file-name)))
    (unless (run-hook-with-args-until-failure 'kill-buffer-query-functions)
      (error "Aborted"))
    (when (and (buffer-modified-p) buffer-file-name)
***************
*** 2020,2026 ****
  In a Lisp program, if you want to be sure of accessing a file's
  contents literally, you should create a temporary buffer and then read
  the file contents into it using `insert-file-contents-literally'."
!   (interactive "FFind file literally: ")
    (switch-to-buffer (find-file-noselect filename nil t)))
  \f
  (defvar after-find-file-from-revert-buffer nil)
--- 2041,2050 ----
  In a Lisp program, if you want to be sure of accessing a file's
  contents literally, you should create a temporary buffer and then read
  the file contents into it using `insert-file-contents-literally'."
!   (interactive
!    (nbutlast				; remove the `wildcards' arg
!     (find-file-read-args "Find file literally: "
! 			 (confirm-nonexistent-file-or-buffer))))
    (switch-to-buffer (find-file-noselect filename nil t)))
  \f
  (defvar after-find-file-from-revert-buffer nil)

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




  parent reply	other threads:[~2009-11-09 10:09 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           ` Juri Linkov [this message]
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                                   ` find-file-read-args Stefan Monnier
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

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

  git send-email \
    --in-reply-to=871vk8uo0q.fsf@mail.jurta.org \
    --to=juri@jurta.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.