6

I'm using Emacs on Windows.

I also have a VirtualBox VM that I connect to using plink.

But then, when I use the eshell, and I do cd <some folder> it tells me No such directory found via CDPATH environment variable even though I started the eshell from a dired buffer and directly typed cd folder.

I think the key is to make this variable command-line-default-directory follow the directory where the buffer is opened at?

Just to reiterate my question, suppose I'm in C://plink:<username>@<ip>:/home/asti/folder, I want to be able to type cd foldername and not get the error No such directory found via CDPATH environment variable.

migrated from stackoverflow.com May 12 '15 at 13:41

This question came from our site for professional and enthusiast programmers.

  • I wasn't able to reproduce this on my GNU/Linux machine. (I opened dired to a directory on my VM using Tramp, and then did M-x eshell. I was able to cd successfully.) What version of Emacs are you using? – Scott Weldon May 11 '15 at 18:47
  • Hi Scott. I use 24.5.1 – Jenia Ivanov May 11 '15 at 19:06
  • Does the error occur when you start Emacs with emacs -Q? – Scott Weldon May 11 '15 at 19:22
  • Hi Scott. Yes, it's the same when I use the -Q option. I opened emacs with the -Q option. And did M-x : and typed (setq tramp-default-method "plink") and did C-x C-f /username@<ip>:. Then I opened the eshell and did cd .. and got the error: No such directory found via CDPATH environment variabl – Jenia Ivanov May 13 '15 at 16:47
  • By the way, I use windows as the host machine, I think that is why. – Jenia Ivanov May 13 '15 at 16:50
1

I solved this with the following overloaded function:

(defun cd (dir)
  "Make DIR become the current buffer's default directory.
If your environment includes a `CDPATH' variable, try each one of
that list of directories (separated by occurrences of
`path-separator') when resolving a relative directory name.
The path separator is colon in GNU and GNU-like systems."
  (interactive
   (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 is (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
                           t))))
  (unless cd-path
    (setq cd-path (or (parse-colon-path (getenv "CDPATH"))
                      (list "./"))))
  (cd-absolute
   (or (locate-file dir (cons default-directory cd-path) nil
                    (lambda (f) (and (file-directory-p f) 'dir-ok)))
       (error "No such directory found via CDPATH environment variable"))))

This prepends, in the 3rd from last line, default-directory to the cdpath (default ("./")), which works around what appears to be a bug with Windows Emacs locate-file-internal. It may have unforseen side-effects!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.