help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: shell mode, changing directory


From: Phillip Lord
Subject: Re: shell mode, changing directory
Date: 24 Mar 2003 16:21:29 +0000
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2.93

>>>>> "Piet" == Piet van Oostrum <piet@cs.uu.nl> writes:

>>>>> "Bingham, Jay" <Jay.Bingham@hp.com> (BJ) wrote:

  BJ> On Friday, March 21, 2003 12:23 PM Alan Shutko wrote:
  >>> Phillip Lord <p.lord@russet.org.uk> writes:

  >>> Specifically I want to write two commands. The first is "move
  >>> CWD of shell to the same as the file of the current buffer"
  >>> (currently you can achieve this, by killing the *shell* buffer,
  >>> and typing M-x shell). And secondly I want to be able to use the
  >>> ECB's (ecb.sourceforge.net) directory window, to move shells
  >>> CWD.

  Piet> [snip]

  BJ> I hope that this helps clarify his needs.

  Piet> I use myself a slightly different approach, which in fact
  Piet> might even be more confortable: I have a command that starts a
  Piet> shell in the current directory which encodes the directory
  Piet> name in the buffer name. If there is already a shell running
  Piet> in the current directory it uses that buffer rather than
  Piet> starting a new one.

*Stuff snipped*

Hmmm. I'm not sure. This might actually be more convenient that my
approach, although, its liable to result in a lot of shell buffers
open. I am not sure which is better. I normally only use a single
shell buffer, although this is generally so I can find it (with M-x
shell, or C-xC-b) quickly. This is why I always wanted a *shell*
buffer which I can use manually. 

Possible the solution is a bit of both. If I am navigating around a
Java source hierarchy, then probably I would want the single shell
approach, as generally you want a single shell window, with a single
shared history (full of "ant test" commands!). But if I am using
several directories with different things in (latex document in one,
java source in another, and various application launchers in a
third!), I'd probably want your approach. 

Anyway I put my cheesy and inadequate approach up on the board for
informational purposes. Maybe we should work this up into a more
general "select a shell with a specific directory" kind of package,
with in true emacs fashion, a vast and bewildering array of different
options. 

Cheers

Phil

ps sorry about the terrible "phil-" prefix, but I find it hard to come
up with non clashing, and yet still meaningful prefixes for all my
little fixes, and fiddles)


(global-set-key "\C-cd" 'phil-show-shift-shell-to-current-dir)

(defun phil-show-shift-shell-to-current-dir()
  (interactive)
  (phil-shift-shell-to-current-dir)
  (other-window 1)
  (switch-to-buffer "*shell*"))

(defun phil-shift-shell-to-current-dir()
  (interactive)
  (let ((file-name(buffer-file-name
                   (current-buffer))))
    (if (not file-name)
        (error "Current buffer is not associated with a file"))
    (phil-shift-shell-to-directory
     (file-name-directory file-name))))

(defun phil-shift-shell-to-directory(directory)
  (let* ((poss-shell (get-buffer "*shell*"))
        (shell-buffer
         (if poss-shell
             poss-shell
           (shell)))
        (shell-process 
         (get-buffer-process shell-buffer))
        (directory-string (concat "cd " directory "\n")))
    (save-excursion
      (set-buffer shell-buffer)
      (process-send-string 
       shell-process directory-string)
      (cd directory)
      (process-send-string 
       shell-process "pwd\n"))))
      

                         
   
    


reply via email to

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