all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Roland Winkler <winkler@gnu.org>
To: Andreas Schwab <schwab@linux-m68k.org>
Cc: emacs-devel@gnu.org
Subject: Re: M-x shell question
Date: Thu, 18 Aug 2016 11:51:43 +0800	[thread overview]
Message-ID: <87oa4qwx80.fsf@gnu.org> (raw)
In-Reply-To: <877fbfuosk.fsf@linux-m68k.org> (Andreas Schwab's message of "Wed, 17 Aug 2016 22:24:27 +0200")

On Wed, Aug 17 2016, Andreas Schwab wrote:
> Emacs doesn't know what the shell is currently running, sending a cd
> command may not do what you want.

For many years I have been using the command below.  If the shell
appears to be busy, this command puts "cd dir" into the input history,
which makes the shell command available via comint-previous-input.


(defun my-shell (&optional buffer)
  "Use `default-directory' of current buffer as working dir of `*shell*' buffer.
Also, switch to `*shell*' buffer.
Optional arg BUFFER has same meaning as for command `shell'."
  (interactive ; code taken from `shell'
   (list
    (if current-prefix-arg
        (read-buffer "Shell buffer: "
                     (generate-new-buffer-name "*shell*")))))
  (unless default-directory
    (error "default-directory of current buffer is nil"))
  (let ((edir (expand-file-name default-directory))
        (cdir (concat "cd " (abbreviate-file-name default-directory))))
    (shell (get-buffer-create (or buffer "*shell*")))
    ;; change directory, unless we are already where we want to be
    (unless (string= edir (expand-file-name default-directory))
      (goto-char (point-max))
      (if (looking-back comint-prompt-regexp nil)
          (progn (insert cdir)
                 (comint-send-input))
        (message "shell `%s' seems to be busy, cannot change directory"
                 (buffer-name))
        (comint-add-to-input-history cdir)))))



  reply	other threads:[~2016-08-18  3:51 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-17 17:45 M-x shell question Richard Stallman
2016-08-17 18:09 ` raman
2016-08-17 19:04   ` Uwe Brauer
2016-08-17 21:13     ` raman
2016-08-18 14:07   ` Richard Stallman
2016-08-18 14:13     ` Fwd: " Kaushal Modi
2016-08-19  5:29       ` Richard Stallman
2016-08-19  5:49         ` Kaushal Modi
2016-08-19  7:18           ` Eli Zaretskii
2016-08-19 13:21           ` Robert Weiner
2016-08-19 14:14             ` Kaushal Modi
2016-08-19 14:35               ` Robert Weiner
2016-08-19 14:45                 ` Kaushal Modi
2016-08-19  7:16         ` Eli Zaretskii
2016-08-18 14:22     ` Oleh Krehel
2016-08-18 15:11     ` Andreas Schwab
2016-08-19  2:53       ` Tino Calancha
2016-08-18 15:27     ` raman
2016-08-17 19:12 ` Robert Weiner
2016-08-17 20:24 ` Andreas Schwab
2016-08-18  3:51   ` Roland Winkler [this message]
2016-08-18 14:06   ` Richard Stallman

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87oa4qwx80.fsf@gnu.org \
    --to=winkler@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=schwab@linux-m68k.org \
    /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.
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.