From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: find-file-read-args Date: Tue, 24 Nov 2009 19:08:59 +0200 Organization: JURTA Message-ID: <87k4xgt3uh.fsf@mail.jurta.org> References: <3b31caf90911051613w80af4cu61352a29ce5dcd77@mail.gmail.com> <87vdhoe73d.fsf@mail.jurta.org> <87y6mkb6qr.fsf@mail.jurta.org> <87bpjfiark.fsf@mail.jurta.org> <871vk8uo0q.fsf@mail.jurta.org> <87ocn8ayrw.fsf@mail.jurta.org> <4AFBE741.1040506@gmx.at> <87tyx05849.fsf@mail.jurta.org> <871vjz27lw.fsf@mail.jurta.org> <4B003A50.30601@gmx.at> <4B025430.1010204@gmx.at> <87my2ljxun.fsf@mail.jurta.org> <87bpit1ql9.fsf@mail.jurta.org> <87aaydrle7.fsf@mail.jurta.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1259083485 27061 80.91.229.12 (24 Nov 2009 17:24:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 24 Nov 2009 17:24:45 +0000 (UTC) Cc: martin rudalics , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Nov 24 18:24:38 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NCz82-0005V0-1A for ged-emacs-devel@m.gmane.org; Tue, 24 Nov 2009 18:24:38 +0100 Original-Received: from localhost ([127.0.0.1]:44119 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NCz81-0001N1-Fu for ged-emacs-devel@m.gmane.org; Tue, 24 Nov 2009 12:24:37 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NCyzW-0005nA-4W for emacs-devel@gnu.org; Tue, 24 Nov 2009 12:15:50 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NCyzR-0005kK-45 for emacs-devel@gnu.org; Tue, 24 Nov 2009 12:15:49 -0500 Original-Received: from [199.232.76.173] (port=48895 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NCyzQ-0005kF-T3 for emacs-devel@gnu.org; Tue, 24 Nov 2009 12:15:44 -0500 Original-Received: from smtp-out3.starman.ee ([85.253.0.5]:36752 helo=mx1.starman.ee) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NCyzQ-0007ir-BX for emacs-devel@gnu.org; Tue, 24 Nov 2009 12:15:44 -0500 X-Virus-Scanned: by Amavisd-New at mx1.starman.ee Original-Received: from mail.starman.ee (82.131.34.225.cable.starman.ee [82.131.34.225]) by mx1.starman.ee (Postfix) with ESMTP id 1D4863F4130; Tue, 24 Nov 2009 19:15:34 +0200 (EET) In-Reply-To: (Stefan Monnier's message of "Mon, 23 Nov 2009 21:33:43 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (x86_64-pc-linux-gnu) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:117690 Archived-At: > 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 ---- ;; 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/