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: find-file-read-args (was: FFAP) Date: Mon, 09 Nov 2009 12:09:33 +0200 Organization: JURTA Message-ID: <871vk8uo0q.fsf@mail.jurta.org> References: <3b31caf90911051613w80af4cu61352a29ce5dcd77@mail.gmail.com> <87vdhoe73d.fsf@mail.jurta.org> <87y6mkb6qr.fsf@mail.jurta.org> <87bpjfiark.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 1257763275 26564 80.91.229.12 (9 Nov 2009 10:41:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 9 Nov 2009 10:41:15 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Nov 09 11:41:07 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 1N7RgI-0003db-ME for ged-emacs-devel@m.gmane.org; Mon, 09 Nov 2009 11:41:07 +0100 Original-Received: from localhost ([127.0.0.1]:57185 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N7RgI-0008LL-3X for ged-emacs-devel@m.gmane.org; Mon, 09 Nov 2009 05:41:06 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N7RcH-0006qK-DC for emacs-devel@gnu.org; Mon, 09 Nov 2009 05:36:57 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N7RcC-0006mT-0O for emacs-devel@gnu.org; Mon, 09 Nov 2009 05:36:56 -0500 Original-Received: from [199.232.76.173] (port=43389 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N7RcB-0006mN-9X for emacs-devel@gnu.org; Mon, 09 Nov 2009 05:36:51 -0500 Original-Received: from smtp-out1.starman.ee ([85.253.0.3]:39961 helo=mx1.starman.ee) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N7RcA-0006MO-KK for emacs-devel@gnu.org; Mon, 09 Nov 2009 05:36:51 -0500 X-Virus-Scanned: by Amavisd-New at mx1.starman.ee Original-Received: from mail.starman.ee (62.65.208.58.cable.starman.ee [62.65.208.58]) by mx1.starman.ee (Postfix) with ESMTP id A14803F4153; Mon, 9 Nov 2009 12:36:43 +0200 (EET) In-Reply-To: <87bpjfiark.fsf@mail.jurta.org> (Juri Linkov's message of "Fri, 06 Nov 2009 23:19:45 +0200") 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:116741 Archived-At: > 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))) (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))) (defvar after-find-file-from-revert-buffer nil) -- Juri Linkov http://www.jurta.org/emacs/