From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#7924: 23.2.91; Documentation about CDPATH is a little misleading Date: Tue, 01 Feb 2011 17:11:52 -0500 Message-ID: References: <87r5bz72vm.fsf@sc3d.org> <87k4hnp9ui.fsf@stupidchicken.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1296600110 3834 80.91.229.12 (1 Feb 2011 22:41:50 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 1 Feb 2011 22:41:50 +0000 (UTC) Cc: 7924@debbugs.gnu.org, Reuben Thomas To: Chong Yidong Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Feb 01 23:41:43 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PkOuk-0002H7-TB for geb-bug-gnu-emacs@m.gmane.org; Tue, 01 Feb 2011 23:41:41 +0100 Original-Received: from localhost ([127.0.0.1]:43526 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PkOpX-0007j9-1J for geb-bug-gnu-emacs@m.gmane.org; Tue, 01 Feb 2011 17:36:11 -0500 Original-Received: from [140.186.70.92] (port=45628 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PkOpG-0007hJ-7m for bug-gnu-emacs@gnu.org; Tue, 01 Feb 2011 17:36:04 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PkOp3-0002al-Em for bug-gnu-emacs@gnu.org; Tue, 01 Feb 2011 17:35:42 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:36307) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PkOp3-0002ac-AP for bug-gnu-emacs@gnu.org; Tue, 01 Feb 2011 17:35:41 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1PkOKQ-0000kW-8p; Tue, 01 Feb 2011 17:04:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 01 Feb 2011 22:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 7924 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 7924-submit@debbugs.gnu.org id=B7924.12965978132848 (code B ref 7924); Tue, 01 Feb 2011 22:04:02 +0000 Original-Received: (at 7924) by debbugs.gnu.org; 1 Feb 2011 22:03:33 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PkOJw-0000js-Ma for submit@debbugs.gnu.org; Tue, 01 Feb 2011 17:03:33 -0500 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PkOJu-0000jf-97 for 7924@debbugs.gnu.org; Tue, 01 Feb 2011 17:03:31 -0500 Original-Received: from faina.iro.umontreal.ca (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id p11MCOmA001250; Tue, 1 Feb 2011 17:12:24 -0500 Original-Received: by faina.iro.umontreal.ca (Postfix, from userid 20848) id 7860C1300EB; Tue, 1 Feb 2011 17:11:52 -0500 (EST) In-Reply-To: <87k4hnp9ui.fsf@stupidchicken.com> (Chong Yidong's message of "Sat, 29 Jan 2011 18:29:41 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV3735=0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Tue, 01 Feb 2011 17:04:02 -0500 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:43825 Archived-At: >> Both in the manual and in the docstring for `cd', one might reasonably >> infer (as I did!) that CDPATH will be searched when completing relative >> directory names, but this is not the case. >>=20 >> Is there in fact any way to get this to work? It=E2=80=99s something tha= t one >> can do nicely in bash in a terminal, for example, but not in shell-mode. > I think this needs new code in `read-file-name-internal' (the completion > function for read-file-name). The patch below seems to work in my brief testing. Stefan =3D=3D=3D modified file 'lisp/files.el' --- lisp/files.el 2011-02-01 20:53:09 +0000 +++ lisp/files.el 2011-02-01 22:06:43 +0000 @@ -700,25 +700,36 @@ `path-separator') when resolving a relative directory name. The path separator is colon in GNU and GNU-like systems." (interactive - (list (read-directory-name "Change default directory: " + (list + ;; FIXME: There's a subtle bug in the completion below. Seems linked + ;; to a fundamental difficulty of implementing `predicate' correctly. + ;; The manifestation is that TAB may list non-directories in the case = where + ;; those files also correspond to valid directories (if your cd-path i= s (A/ + ;; B/) and you have A/a a file and B/a a directory, then both `a' and = `a/' + ;; will be listed as valid completions). + ;; This is because `a' (listed because of A/a) is indeed a valid choice + ;; (which will lead to the use of B/a). + (minibuffer-with-setup-hook + (lambda () + (setq minibuffer-completion-table + (apply-partially #'locate-file-completion-table + cd-path nil)) + (setq minibuffer-completion-predicate + (lambda (dir) + (locate-file dir cd-path nil + (lambda (f) (and (file-directory-p f) 'dir-= ok)))))) + (unless cd-path + (setq cd-path (or (parse-colon-path (getenv "CDPATH")) + (list "./")))) + (read-directory-name "Change default directory: " default-directory default-directory - (and (member cd-path '(nil ("./"))) - (null (getenv "CDPATH")))))) - (if (file-name-absolute-p dir) - (cd-absolute (expand-file-name dir)) - (if (null cd-path) - (let ((trypath (parse-colon-path (getenv "CDPATH")))) - (setq cd-path (or trypath (list "./"))))) - (if (not (catch 'found - (mapc - (function (lambda (x) - (let ((f (expand-file-name (concat x dir)))) - (if (file-directory-p f) - (progn - (cd-absolute f) - (throw 'found t)))))) - cd-path) - nil)) + t)))) + (unless cd-path + (setq cd-path (or (parse-colon-path (getenv "CDPATH")) + (list "./")))) + (cd-absolute + (or (locate-file dir cd-path nil + (lambda (f) (and (file-directory-p f) 'dir-ok))) (error "No such directory found via CDPATH environment variable")))) =20 (defun load-file (file) =3D=3D=3D modified file 'src/lread.c' --- src/lread.c 2011-01-31 18:47:03 +0000 +++ src/lread.c 2011-02-01 21:57:03 +0000 @@ -1223,7 +1223,9 @@ file name when searching. If non-nil, PREDICATE is used instead of `file-readable-p'. PREDICATE can also be an integer to pass to the access(2) function, -in which case file-name-handlers are ignored. */) +in which case file-name-handlers are ignored. +This function will normally skip directories, so if you want it to find +directories, make sure the PREDICATE function return `dir-ok' for them. *= /) (Lisp_Object filename, Lisp_Object path, Lisp_Object suffixes, Lisp_Obje= ct predicate) { Lisp_Object file; @@ -1233,6 +1235,7 @@ return file; } =20 +static Lisp_Object Qdir_ok; =20 /* Search for a file whose name is STR, looking in directories in the Lisp list PATH, and trying suffixes from SUFFIX. @@ -1350,9 +1353,12 @@ if (NILP (predicate)) exists =3D !NILP (Ffile_readable_p (string)); else - exists =3D !NILP (call1 (predicate, string)); - if (exists && !NILP (Ffile_directory_p (string))) - exists =3D 0; + { + Lisp_Object tmp =3D call1 (predicate, string); + exists =3D !NILP (tmp) + && (EQ (tmp, Qdir_ok) + || !NILP (Ffile_directory_p (string))); + } =20 if (exists) { @@ -4369,6 +4375,9 @@ Qfile_truename =3D intern_c_string ("file-truename"); staticpro (&Qfile_truename) ; =20 + Qdir_ok =3D intern_c_string ("dir-ok"); + staticpro (&Qdir_ok); +=20=20 Qdo_after_load_evaluation =3D intern_c_string ("do-after-load-evaluation= "); staticpro (&Qdo_after_load_evaluation) ; =20