7

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.

Drew
  • 75,699
  • 9
  • 109
  • 225
Jenia Ivanov
  • 427
  • 4
  • 14
  • 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 –  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@:`. 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
  • Okay. Yes that could be the problem then. I haven't used Emacs on Windows for a while, so I'll have to defer to someone who has. – Scott Weldon May 13 '15 at 16:59
  • Have a look at this discussion, and possible fix. https://lists.gnu.org/archive/html/bug-gnu-emacs/2013-10/msg00840.html Even if the patch doesn't work, the idea of generating a backtrace may help us see what's going on. If you can, please add one to your question. (Set `debug-on-error` to `t`.) – Joe Corneli May 30 '15 at 20:50
  • Joe Corneli, thanks but that didn't fix it. I have a slightly different problem. LIke I have no errors in the process. It's just that emacs doesnt follow the directory that I'm editing right now. It thinks that the current directory is the directory where the emacs.exe was. – Jenia Ivanov Jun 01 '15 at 14:00
  • `C://plink:@:/home/asti/folder` - this is not a valid filename, it should be `/plink:@:/home/asti/folder`. – npostavs Aug 16 '19 at 10:45

1 Answers1

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!