Subject: Re: bug#60968: 30.0.50; M-x shell keeps an old default-directory

From: Michael Albinus <[email-masked]>
Date: Fri, 20 Jan 2023 20:00:46 +0100

Manuel Giraud <[email-masked]> writes:

Hi Manuel,

> Here is an annoyance I bump into sometimes.  Recipe:
>
>     C-x C-f /-:somewhere-remote:
>     M-x shell ;; Emacs asks me about the remote shell and that is not
>               ;; what I want
>     C-g
>     C-x C-f somewhere-local
>     M-x shell ;; Emacs still asks me about the previous remote shell
>
> It seems to come from the fact that when in shell.el line 865 the
> "*shell*" buffer is already created and its default-directory set…  Or
> maybe, I'm just doing it wrong when I want a shell.

This is the specified behavior of the `shell' command. From the
docstring:

--8<---------------cut here---------------start------------->8---
If BUFFER exists but shell process is not running, make new shell.
If BUFFER exists and shell process is running, just switch to BUFFER.
--8<---------------cut here---------------end--------------->8---

That is, the shell buffer is reused, even if you have interrupted with
C-g, and the shell didn't start yet. And so its default-directory.

If you want another buffer (and another shell therefore), the following
from the docstring is relevant:

--8<---------------cut here---------------start------------->8---
Interactively, a prefix arg means to prompt for BUFFER.
--8<---------------cut here---------------end--------------->8---

So your use case needs "C-u M-x shell". Or you delete the shell buffer
after you have interrupted with C-g.

Best regards, Michael.