From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh Newsgroups: gmane.emacs.bugs Subject: bug#62621: 29.0.60; uniquify can't make buffers unique based on things other than filename Date: Fri, 14 Apr 2023 12:08:37 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7117"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: 62621@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Apr 14 18:09:20 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1pnLzE-0001gl-Kx for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 14 Apr 2023 18:09:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pnLz0-0000I2-A6; Fri, 14 Apr 2023 12:09:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pnLyy-0000HR-SB for bug-gnu-emacs@gnu.org; Fri, 14 Apr 2023 12:09:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pnLyw-0000xx-Uj for bug-gnu-emacs@gnu.org; Fri, 14 Apr 2023 12:09:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pnLyw-0008PM-Pr for bug-gnu-emacs@gnu.org; Fri, 14 Apr 2023 12:09:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 14 Apr 2023 16:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62621 X-GNU-PR-Package: emacs Original-Received: via spool by 62621-submit@debbugs.gnu.org id=B62621.168148852432264 (code B ref 62621); Fri, 14 Apr 2023 16:09:02 +0000 Original-Received: (at 62621) by debbugs.gnu.org; 14 Apr 2023 16:08:44 +0000 Original-Received: from localhost ([127.0.0.1]:47400 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pnLye-0008OK-1e for submit@debbugs.gnu.org; Fri, 14 Apr 2023 12:08:44 -0400 Original-Received: from mxout5.mail.janestreet.com ([64.215.233.18]:39787) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pnLyc-0008O1-M3 for 62621@debbugs.gnu.org; Fri, 14 Apr 2023 12:08:43 -0400 In-Reply-To: (Spencer Baugh's message of "Sun, 02 Apr 2023 13:37:36 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:259935 Archived-At: FWIW, here is the (unpolished) patch I'm currently using. This is correct but it's not what I think the final form of this should look like. For better or for worse, I have now Deeply Understood uniquify, and I have various ideas for things to do to fix bugs in it and simplify it and add new features... see bug#62732 for my first step. (Which adds tests, even!) After some of those, then I can do this bug. One sneak peak of a feature which I think I can manage to add with some improvements to uniquify.el: a user customization which causes a new behavior in read-buffer, so that when it's running on a subset of buffers (by passing PREDICATE), it reads buffer names which are only uniquified among that subset. (So the buffer names will be shorter when that doesn't cause ambiguity). This would be really cool for project-switch-to-buffer, so that if you have two projects working on the same source repo with the same files open, you don't have to see the extra uniquify cruft at the start of the buffer name when you just want to look at buffers in a single project. diff --git a/lisp/uniquify.el b/lisp/uniquify.el index dee9ecba2ea..53b39920820 100644 --- a/lisp/uniquify.el +++ b/lisp/uniquify.el @@ -210,8 +210,8 @@ uniquify-rationalize-file-buffer-names (with-current-buffer newbuf (setq uniquify-managed nil)) (when dirname (setq dirname (expand-file-name (directory-file-name dirname))) - (let ((fix-list (list (uniquify-make-item base dirname newbuf - nil dirname))) + (let ((fix-list (list (let ((dirname (uniquify-buffer-file-name newbuf dirname))) + (uniquify-make-item base dirname newbuf nil dirname)))) items) (dolist (buffer (buffer-list)) (when (and (not (and uniquify-ignore-buffers-re @@ -258,20 +258,26 @@ uniquify-rationalize-file-buffer-names (uniquify-rationalize fix-list)))) ;; uniquify's version of buffer-file-name; result never contains trailing slash -(defun uniquify-buffer-file-name (buffer) +(require 'project) +(defun uniquify-buffer-file-name (buffer &optional dirname) "Return name of directory, file BUFFER is visiting, or nil if none. Works on ordinary file-visiting buffers and buffers whose mode is mentioned in `uniquify-list-buffers-directory-modes', otherwise returns nil." (with-current-buffer buffer - (let ((filename - (or buffer-file-name - (if (memq major-mode uniquify-list-buffers-directory-modes) - list-buffers-directory)))) - (when filename - (directory-file-name - (file-name-directory - (expand-file-name - (directory-file-name filename)))))))) + (let* ((filename + (or buffer-file-name + (if (memq major-mode uniquify-list-buffers-directory-modes) + list-buffers-directory))) + (dir (or dirname + (directory-file-name + (file-name-directory + (expand-file-name + (directory-file-name filename))))))) + (if-let (pr (project-current nil dir)) + (let* ((pr-dir (project-root pr)) + (pr-rel (file-relative-name dir pr-dir))) + (file-name-concat pr-dir (project-name pr) pr-rel)) + dir)))) (defun uniquify-rerationalize-w/o-cb (fix-list) "Re-rationalize the buffers in FIX-LIST, but ignoring `current-buffer'."