[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PC-do-completion unconditionally adds wildcards to directory

From: Stefan Monnier
Subject: Re: PC-do-completion unconditionally adds wildcards to directory
Date: 16 Oct 2003 14:00:31 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

Stefan> So if I understand correctly, you are in directory
Stefan> "/vobs/ubtssw_onecell_images/sunos/sunboard/src/misc.cc@@/" and
Stefan> the prompt says "main/58" and you hit RET.  Two things I do not
Stefan> understand:
Stefan> 1 - why was the * added ?
> that's done by that section in PC-do-completion that I mentioned in my
> original error report (starting with ";; Add wildcards if necessary")

Sorry, it seems that you didn't have as much context as I thought:
I wrote the section that adds the *.
So my question was: why does the code that I wrote decide to add the *,
even though `main' is a an existing directory in which case the *
should not be added.

Stefan> Is `main' not a directory ?
> yes it's a directory

Stefan> What does (file-directory-p "main/") return when run from the
Stefan> misc.cc@@ directory ?
> t

Hmm... that's odd.  In the code:

      ;; Add wildcards if necessary
      (and filename
           (let ((dir (file-name-directory str))
                 (file (file-name-nondirectory str)))
             (while (and (stringp dir) (not (file-directory-p dir)))
               (setq dir (directory-file-name dir))
               (setq file (concat (replace-regexp-in-string
                                   PC-delim-regex "*\\&"
                                   (file-name-nondirectory dir))
                                  "*/" file))
               (setq dir (file-name-directory dir)))
             (setq str (concat dir file))))

based on what you tell me I expect that when we reach the `while',
`dir' is set to "main/" and `file' to "58" and (stringp dir) should
return t and (file-directory-p dir) should also return t so
the `and' expression should return nil and the body of the loop should
never be executed.

Maybe the problem is as you say: the default-directory is not set
to what I expect.

> the part where the * is added is simple and easy to understand and this code
> wasn't there in 21.3. I don't know why it was added.

It was added so you can do C-x C-f ~/e/e/e TAB RET to open up your
~/etc/emacs/emacs.el file.  Previously you had to do ~/e*/e*/e TAB RET.

> But I wonder why one would add the wildcard, if the next section is supposed
> to remove it.

It's supposed to remove it be wildcard-expansion, which doesn't just remove
the * but replaces it with something useful.  The fact that it does not get
removed is a separate bug, although probably caused by the same
underlying problem.

> I think I can now give you a simple example that make it possible to
> reproduce the problem:
> 1. Create ~/subdir
> 2. touch ~/subdir/file
> 3. In scratch buffer make sure the pwd is not ~
> 4. turn on partial-completion-mode
> 5. define and execute
> (defun get-name ()
>   (interactive)
>   (let ((insert-default-directory nil))
>     (read-file-name "read: " "~" "subdir/file" t "subdir/file")))
> (get-name)

Oh....right...now I remember: the default directory to be used for
completion is passed as the `predicate' rather than being passed in
Obviously, the original author of p-c-c didn't take it into account either
and I didn't notice the problem.

Can you try the patch below and tell us if it helps without breaking
something else ?


--- complete.el.~1.39.~ 2003-09-08 19:20:11.000000000 -0400
+++ complete.el 2003-10-16 13:59:10.000000000 -0400
@@ -1,6 +1,6 @@
 ;;; complete.el --- partial completion mechanism plus other goodies
-;; Copyright (C) 1990, 1991, 1992, 1993, 1999, 2000
+;; Copyright (C) 1990, 1991, 1992, 1993, 1999, 2000, 2003
 ;;  Free Software Foundation, Inc.
 ;; Author: Dave Gillespie <address@hidden>
@@ -394,7 +394,9 @@
       ;; Add wildcards if necessary
       (and filename
            (let ((dir (file-name-directory str))
-                 (file (file-name-nondirectory str)))
+                 (file (file-name-nondirectory str))
+                ;; The base dir for file-completion is passed in `predicate'.
+                (default-directory (expand-file-name pred)))
              (while (and (stringp dir) (not (file-directory-p dir)))
                (setq dir (directory-file-name dir))
                (setq file (concat (replace-regexp-in-string
@@ -408,6 +410,8 @@
       (and filename
           (string-match "\\*.*/" str)
           (let ((pat str)
+                ;; The base dir for file-completion is passed in `predicate'.
+                (default-directory (expand-file-name pred))
             (setq p (1+ (string-match "/[^/]*\\'" pat)))
             (while (setq p (string-match PC-delim-regex pat p))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]