From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Roland Winkler Newsgroups: gmane.emacs.devel Subject: Re: M-x shell question Date: Thu, 18 Aug 2016 11:51:43 +0800 Message-ID: <87oa4qwx80.fsf@gnu.org> References: <877fbfuosk.fsf@linux-m68k.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1471492326 16188 195.159.176.226 (18 Aug 2016 03:52:06 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 18 Aug 2016 03:52:06 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.95 (gnu/linux) Cc: emacs-devel@gnu.org To: Andreas Schwab Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Aug 18 05:52:03 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1baEN8-0003vo-Jb for ged-emacs-devel@m.gmane.org; Thu, 18 Aug 2016 05:52:02 +0200 Original-Received: from localhost ([::1]:50563 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baEN5-0000o1-JR for ged-emacs-devel@m.gmane.org; Wed, 17 Aug 2016 23:51:59 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49753) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baEMw-0000nv-MP for emacs-devel@gnu.org; Wed, 17 Aug 2016 23:51:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1baEMv-0005js-OX for emacs-devel@gnu.org; Wed, 17 Aug 2016 23:51:50 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:51031) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baEMv-0005jn-L5; Wed, 17 Aug 2016 23:51:49 -0400 Original-Received: from [2400:dd01:1009:4:2cd9:5d4f:ec3e:38ae] (port=43054 helo=regnitz) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1baEMu-00087S-Lh; Wed, 17 Aug 2016 23:51:49 -0400 In-Reply-To: <877fbfuosk.fsf@linux-m68k.org> (Andreas Schwab's message of "Wed, 17 Aug 2016 22:24:27 +0200") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:206641 Archived-At: 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)))))