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: Sun, 21 Mar 2021 21:44:19 +0200 Message-ID: References: <87czwh9rv9.fsf@gmail.com> <87zgz526gx.fsf@gmail.com> <80c15296-ebf7-3030-993f-ffb01051d570@yandex.ru> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------6E74F3541890116B3741E4F2" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32632"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 Cc: emacs-devel To: Matthias Meulien Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Mar 21 20:45:33 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 1lO40z-0008NR-3w for ged-emacs-devel@m.gmane-mx.org; Sun, 21 Mar 2021 20:45:33 +0100 Original-Received: from localhost ([::1]:59852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lO40y-0007QU-4t for ged-emacs-devel@m.gmane-mx.org; Sun, 21 Mar 2021 15:45:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60114) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lO3zu-0006xT-IB for emacs-devel@gnu.org; Sun, 21 Mar 2021 15:44:26 -0400 Original-Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:33763) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lO3zs-0001CB-EU for emacs-devel@gnu.org; Sun, 21 Mar 2021 15:44:26 -0400 Original-Received: by mail-wm1-x32d.google.com with SMTP id w203-20020a1c49d40000b029010c706d0642so10339413wma.0 for ; Sun, 21 Mar 2021 12:44:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=mIe9cmPmkdlQtJA0kNFUhWbNxLeTYnMHsabQ7XJoVBg=; b=stwS+GuFSOmSWBi+I8Wh0UWtrW9mp9d090294xLk2bIzcJd2bGSvm68c6MwidEpobS Wy1kXEaWfryDhbIrn4vLegx6xCK0jZN8707vFqlHcFiIC857FSXO1XRxn8x30z12K5JR 4hUMpVONZ8RNTuHkYrkIZj7r0/7v3BrKepcIr2HPrp8XDzMwAKG/5RXIMJettfEDiIst PMaz/Z6ZW1eerC4pgbhhu2v5F0iaKEIdaS28Uoy/9JXUxbUGd+HAgJD3Z+/9T5KzAIkq orVh8eJbZwbGcvSrLH2QPzVm6BOnsRI8uVnIVuFS5iG6RrLYPol/y862YUVK/mwuVMeZ KVyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:from:to:cc:references:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=mIe9cmPmkdlQtJA0kNFUhWbNxLeTYnMHsabQ7XJoVBg=; b=FyZE/0cW/AxkYWxJaJDP3kgVu3NOs2Dt+t5G3tWEfZ4IQjVfq7bahjycxlWnWvDQa7 DWfhvCh+u13mT9WQnvUGzmnJMckTatInrojf6j7HdCQcGSmVDWBVKl7Ym4xMMdXaXytt flx5tvvEDGUJw3losZ54EFGcd6AVsuSq6rwduwoTa+0fFMdzz9jl1TUEk9SGQYMhtuM3 QOJBAlSjv8g92V+h26/7+QsQpLxSNBAsyoz1HXe+gp1sCSF69txk6ANepX9D1pzVL9IB Xf9BkPp2EGrHIv3tfAm+91JIo9VbNZqeAgo8p/JK5J7zdc++GxvRef9NBYjfeWQ0cvJj B57w== X-Gm-Message-State: AOAM532YV4kfw3qpZNLokGp07whtda8FAJyiZShhcgp4layMWylhPs3S WaJBn4ey58q/x2V6PR9oeO4jI2eNoyA= X-Google-Smtp-Source: ABdhPJxclM7Ji/2oSZ/foCNB/9EdbVyAYVitrmZuZxOff3ywbUtOWpX5zlKYU8NE1hl9JEGbVwX/gg== X-Received: by 2002:a1c:2390:: with SMTP id j138mr12718503wmj.72.1616355861721; Sun, 21 Mar 2021 12:44:21 -0700 (PDT) Original-Received: from [192.168.0.6] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id v2sm23785694wmj.1.2021.03.21.12.44.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 21 Mar 2021 12:44:20 -0700 (PDT) In-Reply-To: <80c15296-ebf7-3030-993f-ffb01051d570@yandex.ru> Content-Language: en-US Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=raaahh@gmail.com; helo=mail-wm1-x32d.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.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, 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:266720 Archived-At: This is a multi-part message in MIME format. --------------6E74F3541890116B3741E4F2 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 15.03.2021 02:41, Dmitry Gutov wrote: >> I think there's a problem even without using C-u: >> >> `project-shell' from a buffer whose associated project root path is >> /src/project1 creates a buffer named *shell*. >> >> Then `project-shell' from a buffer whose associated project root path is >> /src/project2 creates a buffer named *shell* (I am using the >> default `post-forward-angle-brackets' for `uniquify-buffer-name-style'). >> >> But the uniquify rationalize mecanism doesn't rename the first buffer to >> *shell* which happens to be the case for buffers visiting >> files... > > Yup, that's another bug. It should also how up for vc-dir buffers too. Actually, it didn't occur for vc-dir buffers. So it's arguably a bug in my code. Attaching the updated patch which fixes that particular problem, though I'm a little more suspicious of some of uniquify's choices now. In particular, this code depends on list-buffers-directory being set to a value in particular format which is very non-obvious from this variable's docstring. And to have uniquify work similarly with buffers created by M-x shell and M-x eshell as well, these commands need similar changes (we can't really depend on them in project.el because it's an ELPA Core package), as well as shell-mode and eshell-mode being listed in uniquify-list-buffers-directory-modes. --------------6E74F3541890116B3741E4F2 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 b6a886f731..5b1c92ec9d 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -895,6 +895,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. @@ -904,15 +920,16 @@ 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-same-window shell-buffer) - (shell (generate-new-buffer-name default-project-shell-name))))) + (existing-buffer (unless current-prefix-arg + (project--find-existing-buffer 'shell-mode + default-directory)))) + (if existing-buffer + (pop-to-buffer-same-window existing-buffer) + (let* ((uniquify-list-buffers-directory-modes + (cons 'shell-mode uniquify-list-buffers-directory-modes))) + (shell (create-file-buffer (expand-file-name "*shell*"))) + (setq list-buffers-directory (expand-file-name "*shell*" default-directory)) + (setq project--origin-project-root default-directory))))) ;;;###autoload (defun project-eshell () @@ -922,17 +939,22 @@ project-eshell With \\[universal-argument] prefix arg, create a new Eshell buffer even if one already exists." (interactive) + (require 'eshell) (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-same-window eshell-buffer) - (eshell t)))) + (existing-buffer (unless current-prefix-arg + (project--find-existing-buffer 'eshell-mode + default-directory)))) + (if existing-buffer + (pop-to-buffer-same-window existing-buffer) + (let* ((uniquify-list-buffers-directory-modes + (cons 'eshell-mode uniquify-list-buffers-directory-modes)) + (buf (create-file-buffer (expand-file-name eshell-buffer-name)))) + (pop-to-buffer-same-window buf) + (unless (derived-mode-p 'eshell-mode) + (eshell-mode)) + (setq list-buffers-directory (expand-file-name eshell-buffer-name default-directory)) + (setq project--origin-project-root default-directory))))) ;;;###autoload (defun project-async-shell-command () --------------6E74F3541890116B3741E4F2--