[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: M-x shell question
From: |
Roland Winkler |
Subject: |
Re: M-x shell question |
Date: |
Thu, 18 Aug 2016 11:51:43 +0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.95 (gnu/linux) |
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)))))
- Re: Fwd: M-x shell question, (continued)
- Re: Fwd: M-x shell question, Eli Zaretskii, 2016/08/19
- Re: M-x shell question, Oleh Krehel, 2016/08/18
- Re: M-x shell question, Andreas Schwab, 2016/08/18
- Re: M-x shell question, Tino Calancha, 2016/08/18
- Re: M-x shell question, raman, 2016/08/18
Re: M-x shell question, Robert Weiner, 2016/08/17
Re: M-x shell question, Andreas Schwab, 2016/08/17