From: "Sandip Chitale" <sandipchitale@fairisaac.com>
Subject: Re: file name Completion in Shell (cmd.exe) on Emacs (MS Windows)
Date: Fri, 23 Jul 2004 09:51:26 -0700 [thread overview]
Message-ID: <4101420f$0$66466$14726298@news.sunsite.dk> (raw)
In-Reply-To: 6ar7r3cdr0.fsf@rochooni.net
<martin@rochooni.net> wrote in message news:6ar7r3cdr0.fsf@rochooni.net...
>
> "SC" == Sandip Chitale <sandipchitale@fairisaac.com> writes:
> SC> Date: Wed, 21 Jul 2004 10:47:14 -0700
>
> 8<--------------------------------------------------------------------
>
> SC> The shell.el has a concept of shell-chdrive-regexp which is used to
detect
> SC> drive switching commands. However it seems that its use is not being
fully
> SC> implemented. Kind of makes sense...people use emacs on Windows to get
away
> SC> from Windows ;)
>
> hi,
>
> i stepped through the relevant function shell-directory-tracker with
> edebug.
>
> it finally calls the function error an returns "Couldn't cd".
>
> martin
Yes. I had traced the problem to that also. It seems to be a problem with:
file-name-absolute-p
which returns false for "<drive letter>:". Thus cd fails with "Couldn't cd"
error.
Even if "cd" had worked correctly it would still be wrong because it would
have made
default-directory as the root of that drive and not the last "current"
directory on that drive.
So basically what need to happen is that shell.el needs to keep track for
current directory before
switching the drive in some kind of buffer local association list e.g.
(("d:" . "d:/") ("x:" . "x:/") ("c:" . "c:/emacs/lisp/"))
And, after switching the drive set the default-directory to the value (dir)
for the drive key in the association list.
Of course, if the value is not found in the association list
default-directory is set to root of the drive.
This is what I have done in my locally hacked shell.el and it works great.
Here are relevant functions:
(defvar shell-drive-to-directory-map nil "The variable keeps track of drive
and directory mapping.")
(defun shell-get-directory-for-drive (drive)
"Get directory for drive."
(let ((dir (cdr (assoc drive shell-drive-to-directory-map))))
(if dir
dir
(shell-set-directory-for-drive drive (concat (expand-file-name
drive)))
(cdr (assoc drive shell-drive-to-directory-map))
)))
(defun shell-set-directory-for-drive-from-dir (dir)
"Add the drive to directory mapping from dir."
(setq dir (expand-file-name dir))
(if (string-match (concat "\\`\\(" shell-chdrive-regexp
"\\)\\(.*\\)\\'")
dir)
(shell-set-directory-for-drive (match-string 1 dir) (match-string 0
dir))
(error "Could not set directory for drive based on dir.")))
(defun shell-set-directory-for-drive (drive dir)
"Add the drive to directory mapping."
(setq shell-drive-to-directory-map (delq drive
shell-drive-to-directory-map))
(let ((mapping (assoc drive shell-drive-to-directory-map)))
(if mapping
(setcdr mapping dir)
(add-to-list 'shell-drive-to-directory-map (cons drive dir)))))
(defun shell-directory-tracker (str)
"..."
:
:
((and shell-chdrive-regexp
(string-match (concat "\\`\\(" shell-chdrive-regexp
"\\)\\($\\|[ \t]\\)")
cmd))
(shell-set-directory-for-drive-from-dir default-directory) ;; record
current dir for later recovery
(shell-process-cd (shell-get-directory-for-drive
(comint-substitute-in-file-name cmd)))))
:
:
:)
(define-derived-mode shell-mode comint-mode "Shell"
"..."
:
:
:
(make-local-variable 'shell-dirtrackp)
(setq shell-dirtrackp t)
(make-local-variable 'shell-drive-to-directory-map)
(setq shell-drive-to-directory-map nil)
:
:)
Sandip
next prev parent reply other threads:[~2004-07-23 16:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-19 21:11 file name Completion in Shell (cmd.exe) on Emacs (MS Windows) Sandip Chitale
2004-07-20 6:00 ` Carsten Weinberg
2004-07-20 9:43 ` Mathias Dahl
2004-07-20 17:08 ` Sandip Chitale
2004-07-21 9:36 ` Mathias Dahl
[not found] ` <mailman.685.1090303150.1960.help-gnu-emacs@gnu.org>
2004-07-20 17:07 ` Sandip Chitale
2004-07-21 17:47 ` Sandip Chitale
2004-07-21 19:03 ` FCC
2004-07-23 8:46 ` martin
2004-07-23 16:51 ` Sandip Chitale [this message]
2004-07-22 3:54 ` Bruce Ingalls
2004-07-22 17:24 ` Sandip Chitale
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='4101420f$0$66466$14726298@news.sunsite.dk' \
--to=sandipchitale@fairisaac.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).