From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.devel Subject: Re: Name of buffers created by project-shell Date: Thu, 4 Mar 2021 05:21:59 +0200 Message-ID: References: <87czwh9rv9.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2FEDA340E64C5F08C753FCC5" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31633"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 To: Matthias Meulien , emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Mar 04 04:23:11 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lHeZy-00088B-Si for ged-emacs-devel@m.gmane-mx.org; Thu, 04 Mar 2021 04:23:10 +0100 Original-Received: from localhost ([::1]:33694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lHeZx-0003SE-Ri for ged-emacs-devel@m.gmane-mx.org; Wed, 03 Mar 2021 22:23:09 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54804) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lHeZ0-0002z2-PH for emacs-devel@gnu.org; Wed, 03 Mar 2021 22:22:10 -0500 Original-Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:35066) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lHeYy-0000Ri-QA for emacs-devel@gnu.org; Wed, 03 Mar 2021 22:22:10 -0500 Original-Received: by mail-wm1-x330.google.com with SMTP id o16so8177449wmh.0 for ; Wed, 03 Mar 2021 19:22:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=fk2UiBZfBeHxwfBKXLOe/lmQrQ9EtckqOwSj1X3dpKE=; b=VEA7SUkMYtHgPySsMmoCYaoX6r2JJbLOP5oEf30Fpraew9s23Md4/4VISgc1aSAtQ4 DLYWshHsbAuTbndlPIQ2DYLe9POkxECzf+So2oQKlpab0o4fg51/WC1LR0iMFLM/uCyB gbVW0BKovc0YHsSQU1Zdpa4cG+BRY0zjo88z6DZ4dCYVVnOpzSvb5ANZRWVaGhbzHAAz gFehY0gKUxfBB0fuyoR58hyNcb+uDOcxL6NKHzfLoa42EPYm3zDBE+941meeQ5ruLL2m kP2ChXRuJux0qSBysK+Rz2NNJZuVbeG80R4hPl1zd73uJMSwShFYzYcyg1jeNZWRFc5U kpiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=fk2UiBZfBeHxwfBKXLOe/lmQrQ9EtckqOwSj1X3dpKE=; b=tZ/XB0yi4kBGZdNRismz45pprwy+yDB+5pJLstAiAVYGPXkIzh13sBDK65wUSGgSpu +slsLf0qGkvE4hYXTEiKu2J3WVc/jMFr6m05HMYde20QI4zXAXN2k3F4TQVeNsprL6i4 B5WprGJKTU9ta50Re0XovZMv36E83MIs6JBvgVVR37BTfXTNMiVb08XDwEaRku1iGQdL jBjxRyE0lZW1NNM4xfid60XjzBNqVkAOw9TpA/pXIuroaaIVEb4hOPlrH+pGNS0yzQ/s 1USZTsKWnT1lmILSGOdL7HUN4C0Xet1UYnvMysAwnmSdRJrVxwVGW5y26ue+/ELm7WWS HMMQ== X-Gm-Message-State: AOAM532c4yZNHtXPGP3VYnr3cGwodRBwJoJETZvPyR350zwK0+GDSoDH H0niT9gIANv1HbnwW8pNxT1qQMR9bG0= X-Google-Smtp-Source: ABdhPJxi5QPI44ldrht/BWjIE/QDSw8w0pbgl/+u2h1UeWMFr1EzlnY0GqfwHCUNx63RHI9GeAJ2hA== X-Received: by 2002:a7b:c084:: with SMTP id r4mr1656610wmh.166.1614828126912; Wed, 03 Mar 2021 19:22:06 -0800 (PST) Original-Received: from [192.168.0.6] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id y8sm7690566wmi.46.2021.03.03.19.22.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Mar 2021 19:22:05 -0800 (PST) In-Reply-To: <87czwh9rv9.fsf@gmail.com> Content-Language: en-US Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=raaahh@gmail.com; helo=mail-wm1-x330.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:265929 Archived-At: This is a multi-part message in MIME format. --------------2FEDA340E64C5F08C753FCC5 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi Matthias, On 02.03.2021 23:18, Matthias Meulien wrote: > When I C-x p v (project-vc-dir) from a buffer with project root called, > say, "myproject" , I switch to a buffer called *vc-dir*. > When I C-x p s (project-shell) from a buffer with same project root, I > switch to a buffer called *myproject-shell* > > Later, I found it not very convenient when switching between buffers by > name using C-x b (switch-to-buffer) to have one buffer with a prefix > build from the project root and one with a suffix. Don't you think we > should homogenize those namings?   Since when I M-x shell then C-u M-x > shell, I switch to a *shell*<2> buffer, I'd suggest to rename the buffer > created by project-shell to *shell*... What you're asking for makes sense, but there is a snag because of how these commands are implemented. vc-dir doesn't choose the buffer name format itself. It ultimately calls create-file-buffer (which has an advice made by uniquify) which renames the buffer based on uniquify-buffer-name-style (if uniquify is loaded in the current session), of course. The problem with that function is that it always creates a new buffer. So, before calling it, vc-dir-prepare-status-buffer does a search for existing buffer and can find existing one if it matches by major mode and default directory. Both shell and eshell buffers can change their default-directory, but we can track which project they belong to with a new variable. See the attached patch. There's one problem, though: when called with C-u, the piece of behavior which reads as "create a new inferior shell buffer even if one already exists" now creates buffers uniquely named according to uniquify's rules, which seems to mean *shell* emacs-master/*shell* vc/emacs-master/*shell* instead of what one might expect, like emacs-master/*shell* emacs-master/*shell*<2> emacs-master/*shell*<3> Perhaps the solution is not to go through uniquify for this, but then we project-shell can't really be consistent with project-vc-dir. --------------2FEDA340E64C5F08C753FCC5 Content-Type: text/x-patch; charset=UTF-8; name="uniquify-project-shell.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="uniquify-project-shell.diff" diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 944b886ce5..f61a3ebea6 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -917,6 +917,22 @@ project-vc-dir (interactive) (vc-dir (project-root (project-current t)))) +(defvar-local project--origin-project-root nil) + +(defun project--find-existing-buffer (mode root) + (seq-find + (lambda (buf) + (and + (buffer-live-p buf) + (provided-mode-derived-p + (buffer-local-value 'major-mode buf) + mode) + (equal (buffer-local-value + 'project--origin-project-root + buf) + root))) + (buffer-list))) + ;;;###autoload (defun project-shell () "Start an inferior shell in the current project's root directory. @@ -926,15 +942,12 @@ project-shell if one already exists." (interactive) (let* ((default-directory (project-root (project-current t))) - (default-project-shell-name - (concat "*" (file-name-nondirectory - (directory-file-name - (file-name-directory default-directory))) - "-shell*")) - (shell-buffer (get-buffer default-project-shell-name))) - (if (and shell-buffer (not current-prefix-arg)) - (pop-to-buffer shell-buffer) - (shell (generate-new-buffer-name default-project-shell-name))))) + (existing-buffer (project--find-existing-buffer + 'shell-mode default-directory))) + (if (and existing-buffer (not current-prefix-arg)) + (pop-to-buffer existing-buffer) + (shell (create-file-buffer (expand-file-name "*shell*"))) + (setq project--origin-project-root default-directory)))) ;;;###autoload (defun project-eshell () @@ -946,15 +959,14 @@ project-eshell (interactive) (defvar eshell-buffer-name) (let* ((default-directory (project-root (project-current t))) - (eshell-buffer-name - (concat "*" (file-name-nondirectory - (directory-file-name - (file-name-directory default-directory))) - "-eshell*")) - (eshell-buffer (get-buffer eshell-buffer-name))) - (if (and eshell-buffer (not current-prefix-arg)) - (pop-to-buffer eshell-buffer) - (eshell t)))) + (existing-buffer (project--find-existing-buffer + 'eshell-mode default-directory))) + (if (and existing-buffer (not current-prefix-arg)) + (pop-to-buffer existing-buffer) + (let ((eshell-buffer-name + (buffer-name (create-file-buffer (expand-file-name "*eshell*"))))) + (eshell) + (setq project--origin-project-root default-directory))))) ;;;###autoload (defun project-async-shell-command () --------------2FEDA340E64C5F08C753FCC5--