all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* file name Completion in Shell (cmd.exe) on Emacs (MS Windows)
@ 2004-07-19 21:11 Sandip Chitale
  2004-07-20  6:00 ` Carsten Weinberg
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Sandip Chitale @ 2004-07-19 21:11 UTC (permalink / raw)


Folks,

Is there any way to make the file name completion correctly in a shell in
Windows emacs?

When I start (default) shell i.e. cmd.exe I get:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

c:\emacs\bin>ls e<tab>

At this point if I attempt file name completion by hitting tab I get files
in c:\emacs\bin.

Now I change the drive:

c:\emacs\bin>x:

X:\>ls e<tab>

At this point if I attempt file name completion by hitting tab I *still* get
files in c:\emacs\bin.

Now if I do:

X:\>cd x:\

and then do:

X:\>ls e<tab>

At this point if I attempt file name completion by hitting tab I do get
files from x:\

I have correctly set the shell-chdrive-regexp variable.

M-x shell-chdrive-regexp <RETURN> yields:

shell-chdrive-regexp's value is "[a-zA-Z]:"

Any ideas?

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: file name Completion in Shell (cmd.exe) on Emacs (MS Windows)
  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
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Carsten Weinberg @ 2004-07-20  6:00 UTC (permalink / raw)
  Cc: help-gnu-emacs

Sandip Chitale wrote:

>Folks,
>
>Is there any way to make the file name completion correctly in a shell in
>Windows emacs?
>
>  
>
run bash in windows emacs.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: file name Completion in Shell (cmd.exe) on Emacs (MS Windows)
  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
       [not found] ` <mailman.685.1090303150.1960.help-gnu-emacs@gnu.org>
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Mathias Dahl @ 2004-07-20  9:43 UTC (permalink / raw)


"Sandip Chitale" <sandipchitale@fairisaac.com> writes:

> Is there any way to make the file name completion
> correctly in a shell in Windows emacs?

Not sure you want this, but you could try out eshell (M-x
eshell) and see if you like it.

/Mathias

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: file name Completion in Shell (cmd.exe) on Emacs (MS Windows)
       [not found] ` <mailman.685.1090303150.1960.help-gnu-emacs@gnu.org>
@ 2004-07-20 17:07   ` Sandip Chitale
  0 siblings, 0 replies; 12+ messages in thread
From: Sandip Chitale @ 2004-07-20 17:07 UTC (permalink / raw)



"Carsten Weinberg" <cweinberg@freenet.de> wrote in message
news:mailman.685.1090303150.1960.help-gnu-emacs@gnu.org...
> Sandip Chitale wrote:
>
> >Folks,
> >
> >Is there any way to make the file name completion correctly in a shell in
> >Windows emacs?
> >
> >
> >
> run bash in windows emacs.
>

Some times I *have* to run the windows cmd.exe.

I do run bash some times. However the file name completion is intercepted by
emacs shell.el which runs into same problem.
The cygwin bash avoids the problem by using /cygdrive single rooted file
system instead of multiple drives.

Thanks for your suggestion but it does not help me.

Regards,
Sandip

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: file name Completion in Shell (cmd.exe) on Emacs (MS Windows)
  2004-07-20  9:43 ` Mathias Dahl
@ 2004-07-20 17:08   ` Sandip Chitale
  2004-07-21  9:36     ` Mathias Dahl
  0 siblings, 1 reply; 12+ messages in thread
From: Sandip Chitale @ 2004-07-20 17:08 UTC (permalink / raw)



"Mathias Dahl" <brakjoller@hotmail.com> wrote in message
news:ubrib2euk.fsf@hotmail.com...
> "Sandip Chitale" <sandipchitale@fairisaac.com> writes:
>
> > Is there any way to make the file name completion
> > correctly in a shell in Windows emacs?
>
> Not sure you want this, but you could try out eshell (M-x
> eshell) and see if you like it.
>
> /Mathias

Some times I *have* to run the windows cmd.exe.

Thanks for your suggestion but it does not help me.

Regards,
Sandip

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: file name Completion in Shell (cmd.exe) on Emacs (MS Windows)
  2004-07-20 17:08   ` Sandip Chitale
@ 2004-07-21  9:36     ` Mathias Dahl
  0 siblings, 0 replies; 12+ messages in thread
From: Mathias Dahl @ 2004-07-21  9:36 UTC (permalink / raw)


"Sandip Chitale" <sandipchitale@fairisaac.com> writes:

> Some times I *have* to run the windows cmd.exe.

You can run cmd.exe commands from eshell. If you give an
example on what you want to achieve, maybe someone has some
more tips.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: file name Completion in Shell (cmd.exe) on Emacs (MS Windows)
  2004-07-19 21:11 file name Completion in Shell (cmd.exe) on Emacs (MS Windows) Sandip Chitale
                   ` (2 preceding siblings ...)
       [not found] ` <mailman.685.1090303150.1960.help-gnu-emacs@gnu.org>
@ 2004-07-21 17:47 ` Sandip Chitale
  2004-07-21 19:03   ` FCC
  2004-07-23  8:46   ` martin
  2004-07-22  3:54 ` Bruce Ingalls
  4 siblings, 2 replies; 12+ messages in thread
From: Sandip Chitale @ 2004-07-21 17:47 UTC (permalink / raw)


I got a lot of suggestions to use other shells like bash and eshell etc.
However the problem with the cmd.exe still remains.

The issue I am talking about is specific to the Microsoft windows (NT, XP)
command prompt i.e. cmd.exe. The cmd.exe has a command:

C:\ > D:

D:\ >

to switch drives.

However, the code in shell-mode (shell.el) does not seem to *correctly*
switch the notion of default-directory for the *shell* buffer when drive
switching command is issued (well, it attempts to deal with the issue but
defun cd in files.el seems to have a bug (related to filename-abosolute-p
predicate) which prevents this from working).

The file completion works relative to default-directory of the buffer. Thus
the file completions I get are not relative to the new drive and hence new
current directory.

One more subtle issue is that cmd.exe seems to remember current directory
for each drive which is restored when the user switches to that drive. For
example:

C:\ > pwd

C:\

C:\ > D:

D:\ >

C:\ > C:

C:\ > cd \WINDOWS

C:\WINDOWS > D:

D:\ > C:

C:\WINDOWS >

Notice how the C:\WINDOWS was remembered as the last current directory for
C: drive.

(I have hacked the shell.el to do this by maintaining an assoc list of drive
to current directory on the drive which is updated before switching the
drive. The association list is used to restire the directory after switching
the drive. If a mapping is not found the root directory of the default is
used)

The shell.el has a concept of shell-chdrive-regexp which is used to detect
drive switching commands. However it seems that its use is not being fully
implemented. Kind of makes sense...people use emacs on Windows to get away
from Windows ;)

Sandip

"Sandip Chitale" <sandipchitale@fairisaac.com> wrote in message
news:40fc38f9$0$23869$14726298@news.sunsite.dk...
> Folks,
>
> Is there any way to make the file name completion correctly in a shell in
> Windows emacs?
>
> When I start (default) shell i.e. cmd.exe I get:
>
> Microsoft Windows XP [Version 5.1.2600]
> (C) Copyright 1985-2001 Microsoft Corp.
>
> c:\emacs\bin>ls e<tab>
>
> At this point if I attempt file name completion by hitting tab I get files
> in c:\emacs\bin.
>
> Now I change the drive:
>
> c:\emacs\bin>x:
>
> X:\>ls e<tab>
>
> At this point if I attempt file name completion by hitting tab I *still*
get
> files in c:\emacs\bin.
>
> Now if I do:
>
> X:\>cd x:\
>
> and then do:
>
> X:\>ls e<tab>
>
> At this point if I attempt file name completion by hitting tab I do get
> files from x:\
>
> I have correctly set the shell-chdrive-regexp variable.
>
> M-x shell-chdrive-regexp <RETURN> yields:
>
> shell-chdrive-regexp's value is "[a-zA-Z]:"
>
> Any ideas?
>
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: file name Completion in Shell (cmd.exe) on Emacs (MS Windows)
  2004-07-21 17:47 ` Sandip Chitale
@ 2004-07-21 19:03   ` FCC
  2004-07-23  8:46   ` martin
  1 sibling, 0 replies; 12+ messages in thread
From: FCC @ 2004-07-21 19:03 UTC (permalink / raw)


Sandip Chitale said the following on 7/21/2004 7:47 PM:
> 
> However, the code in shell-mode (shell.el) does not seem to *correctly*
> switch the notion of default-directory for the *shell* buffer when drive
> switching command is issued (well, it attempts to deal with the issue but
> defun cd in files.el seems to have a bug (related to filename-abosolute-p
> predicate) which prevents this from working).
> 
> The file completion works relative to default-directory of the buffer. Thus
> the file completions I get are not relative to the new drive and hence new
> current directory.
> 

Here is what I have on

GNU Emacs 21.3.1 (i386-msvc-nt5.1.2600) of 2003-03-28 on buffy

using M-x eshell RET:

Welcome to the Emacs shell

c:/windows $ e:
e:/Work/mpm4bv $ cd ..
e:/Work $ c:
c:/windows $ e:
e:/Work $ c:
c:/windows $ e:
e:/Work $ cd mpm4bv/
e:/Work/mpm4bv $ c:
c:/windows $ cd WinSxS/
c:/windows/WinSxS $

File name completion works fine with eshell-mode, but not with 
shell-mode as you have pointed out. Personally I have quit using 
shell-mode long time ago, because eshell-mode seemed to respond faster 
to commands like C-c C-c than shell-mode. I probably had a couple of 
other reasons, which I do not remember well now.

I suggest you use eshell-mode unless you have time to fix (all the 
problems with) shell-mode.

FCC

===
Any philosophy that can be put in a nutshell belongs there
-Unknown

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: file name Completion in Shell (cmd.exe) on Emacs (MS Windows)
  2004-07-19 21:11 file name Completion in Shell (cmd.exe) on Emacs (MS Windows) Sandip Chitale
                   ` (3 preceding siblings ...)
  2004-07-21 17:47 ` Sandip Chitale
@ 2004-07-22  3:54 ` Bruce Ingalls
  2004-07-22 17:24   ` Sandip Chitale
  4 siblings, 1 reply; 12+ messages in thread
From: Bruce Ingalls @ 2004-07-22  3:54 UTC (permalink / raw)


Sandip Chitale wrote:
> Is there any way to make the file name completion correctly in a shell in
> Windows emacs?

Windows NT, 2000 & XP have an undocumented registry setting.
Go into Regedit (after backing it up, and be sure you know what you are 
doing)
Change
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\CompletionChar
to
9
hex
This will set the command completion to TAB.

Note that Microsoft cmd completion is not as good as Gnu.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: file name Completion in Shell (cmd.exe) on Emacs (MS Windows)
  2004-07-22  3:54 ` Bruce Ingalls
@ 2004-07-22 17:24   ` Sandip Chitale
  0 siblings, 0 replies; 12+ messages in thread
From: Sandip Chitale @ 2004-07-22 17:24 UTC (permalink / raw)


"Bruce Ingalls" <ingallsb@verizon._NO.SPAM_.net> wrote in message
news:xTGLc.38724$F8.19654@nwrdny02.gnilink.net...
> Sandip Chitale wrote:
> > Is there any way to make the file name completion correctly in a shell
in
> > Windows emacs?
>
> Windows NT, 2000 & XP have an undocumented registry setting.
> Go into Regedit (after backing it up, and be sure you know what you are
> doing)
> Change
> HKEY_CURRENT_USER\Software\Microsoft\Command Processor\CompletionChar
> to
> 9
> hex
> This will set the command completion to TAB.
>
> Note that Microsoft cmd completion is not as good as Gnu.

Thanks for the info. I already knew about the completion char registry
setting. That is not the problem.

When cmd.exe runs as a shell under emacs, the completion functionality is
provided by emacs. In other words emacs intercepts the tab key to perform
the completion. The completion is performed relative to the
default-directory of shell buffer. The problem is emacs does not correctly
track the default-directory after a command to switch the drive (e.g. C: or
D:) is issued.

Anyhow I have solved the problem by hacking shell.el as described in my
other post.

Sandip

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: file name Completion in Shell (cmd.exe) on Emacs (MS Windows)
  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
  1 sibling, 1 reply; 12+ messages in thread
From: martin @ 2004-07-23  8:46 UTC (permalink / raw)



"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

8<--------------------------------------------------------------------
-- 
martin dot fischer at boschrexroth dot de

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: file name Completion in Shell (cmd.exe) on Emacs (MS Windows)
  2004-07-23  8:46   ` martin
@ 2004-07-23 16:51     ` Sandip Chitale
  0 siblings, 0 replies; 12+ messages in thread
From: Sandip Chitale @ 2004-07-23 16:51 UTC (permalink / raw)



<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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2004-07-23 16:51 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2004-07-22  3:54 ` Bruce Ingalls
2004-07-22 17:24   ` Sandip Chitale

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.