unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: martin rudalics <rudalics@gmx.at>, emacs-devel@gnu.org
Subject: Re: find-file-read-args
Date: Tue, 24 Nov 2009 19:08:59 +0200	[thread overview]
Message-ID: <87k4xgt3uh.fsf@mail.jurta.org> (raw)
In-Reply-To: <jwvfx843bil.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Mon, 23 Nov 2009 21:33:43 -0500")

> Now I wonder: is that code necessary at all?  If dired sets
> file-name-at-point-functions, the dired-get-filename would get in the
> minibuffer-defaults via file-name-at-point-functions, wouldn't it?
>
> The idea with "no dired-specific code" is that if it's useful for dired
> it's also useful for VC-Dir, PCL-CVS, etc...
> So it looks like file-name-at-point-functions would be a good way to get
> what we want.
> WDYT?

This works correctly with this patch that adds `dired-file-name-at-point'.
(Only relevant changes included, omitting unchanged parts of the whole
patch from the previous message).

Index: lisp/dired.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/dired.el,v
retrieving revision 1.444
diff -c -r1.444 dired.el
*** lisp/dired.el	19 Nov 2009 16:49:24 -0000	1.444
--- lisp/dired.el	24 Nov 2009 17:08:33 -0000
***************
*** 587,592 ****
--- 587,603 ----
  \f
  ;; The dired command
  
+ ;;;###autoload
+ (progn (defun dired-file-name-at-point ()
+   "Try to get a file name at point in the current dired buffer.
+ This hook is inteneded to be put in `file-name-at-point-functions'."
+   (when (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)))))))
+ 
  (defun dired-read-dir-and-switches (str)
    ;; For use in interactive.
    (reverse (list

Index: lisp/files.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/files.el,v
retrieving revision 1.1101
diff -c -r1.1101 files.el
*** lisp/files.el	13 Nov 2009 22:19:51 -0000	1.1101
--- lisp/files.el	24 Nov 2009 17:08:20 -0000
***************
*** 411,416 ****
--- 411,426 ----
    :type '(hook :options (cvs-dired-noselect dired-noselect))
    :group 'find-file)
  
+ (defcustom file-name-at-point-functions '(dired-file-name-at-point
+ 					  ffap-guess-file-name-at-point)
+   "List of functions to try in sequence to get the file name at point.
+ Each function should return either nil or a file name found at the
+ location of point in the current buffer."
+   :type '(hook :options (dired-file-name-at-point
+ 			 ffap-guess-file-name-at-point))
+   :group 'find-file)
+ 
  ;;;It is not useful to make this a local variable.
  ;;;(put 'find-file-not-found-hooks 'permanent-local t)
  (defvar find-file-not-found-functions nil

Index: lisp/minibuffer.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/minibuffer.el,v
retrieving revision 1.99
diff -c -r1.99 minibuffer.el
*** lisp/minibuffer.el	19 Nov 2009 22:05:42 -0000	1.99
--- lisp/minibuffer.el	24 Nov 2009 17:08:28 -0000
***************
*** 1320,1325 ****
--- 1320,1352 ----
  ;; Not always defined, but only called if next-read-file-uses-dialog-p says so.
  (declare-function x-file-dialog "xfns.c"
                    (prompt dir &optional default-filename mustmatch only-dir-p))
+ (declare-function dired-get-filename "dired" (&optional localp no-error-if-not-filep))
+ 
+ (defun read-file-name-defaults (&optional dir initial)
+   (let ((default
+ 	  (cond
+ 	   ;; With non-nil `initial', use `dir' as the first default.
+ 	   ;; Essentially, this mean reversing the normal order of the
+ 	   ;; current directory name and the current file name, i.e.
+ 	   ;; 1. with normal file reading:
+ 	   ;; 1.1. initial input is the current directory
+ 	   ;; 1.2. the first default is the current file name
+ 	   ;; 2. with non-nil `initial' (for `find-alternate-file'):
+ 	   ;; 2.2. initial input is the current file name
+ 	   ;; 2.1. the first default is the current directory
+ 	   (initial (abbreviate-file-name dir))
+ 	   ;; In file buffers, try to get the current file name
+ 	   (buffer-file-name
+ 	    (abbreviate-file-name buffer-file-name))))
+ 	(file-name-at-point
+ 	 (run-hook-with-args-until-success 'file-name-at-point-functions)))
+     (when file-name-at-point
+       (setq default (delete-dups
+ 		     (delete "" (delq nil (list file-name-at-point default))))))
+     ;; Append new defaults to the end of existing `minibuffer-default'.
+     (append
+      (if (listp minibuffer-default) minibuffer-default (list minibuffer-default))
+      (if (listp default) default (list default)))))
  
  (defun read-file-name (prompt &optional dir default-filename mustmatch initial predicate)
    "Read file name, prompting with PROMPT and completing in directory DIR.

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




  reply	other threads:[~2009-11-24 17:08 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                                   ` 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                                         ` Juri Linkov [this message]
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=87k4xgt3uh.fsf@mail.jurta.org \
    --to=juri@jurta.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --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).