From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gabriel Newsgroups: gmane.emacs.bugs Subject: bug#47132: 28.0.50; [PATCH] Uniquify: trailing-separator-p + strip-common-suffix Date: Sun, 14 Mar 2021 02:50:06 -0300 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10895"; mail-complaints-to="usenet@ciao.gmane.io" To: 47132@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Mar 14 07:06:35 2021 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 1lLJta-0002jY-EM for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 14 Mar 2021 07:06:34 +0100 Original-Received: from localhost ([::1]:60222 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLJtZ-0007Dm-G6 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 14 Mar 2021 01:06:33 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44526) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLJt4-0007CK-Sv for bug-gnu-emacs@gnu.org; Sun, 14 Mar 2021 01:06:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49519) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLJt4-0003l2-Hr for bug-gnu-emacs@gnu.org; Sun, 14 Mar 2021 01:06:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lLJt4-0006B1-DK for bug-gnu-emacs@gnu.org; Sun, 14 Mar 2021 01:06:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Gabriel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 14 Mar 2021 06:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 47132 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.161570192523696 (code B ref -1); Sun, 14 Mar 2021 06:06:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 14 Mar 2021 06:05:25 +0000 Original-Received: from localhost ([127.0.0.1]:32832 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lLJsS-0006A7-RC for submit@debbugs.gnu.org; Sun, 14 Mar 2021 01:05:25 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:33598) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lLJsQ-00069x-8x for submit@debbugs.gnu.org; Sun, 14 Mar 2021 01:05:23 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44512) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLJsP-0007B0-T1 for bug-gnu-emacs@gnu.org; Sun, 14 Mar 2021 01:05:22 -0500 Original-Received: from mail-oln040092005098.outbound.protection.outlook.com ([40.92.5.98]:25838 helo=NAM02-SN1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLJsN-0003GB-F0 for bug-gnu-emacs@gnu.org; Sun, 14 Mar 2021 01:05:21 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FfSlvPyZP1pc55CjIOBdOtxZS9KoE7CT5IHh4C6ufeyxI/GHPJaG2yoOMWAUXEtSOyKGJ3HMaDXEOYY/In6iCAtA+sMoD794hLHnmCSxqmChHF24r2A9s2TB5PGIaOP4l9fieJK7zU74/JQy1eYsXe8FS1XFzNfdoawfet83QwN8obTNTyni7WB0qeBNqK9DEBvX8L7Kc+jETJA0rzMmLip+qpNoZHc12483vE0bR02P+OAhPuuIr31R86V7MyU7vFmw9RN1OuExEaJKcJQ4RzYQqVUCDbtzDNQ09XVn40TORhaW+FWpDEmO1EEusz7Dmym4StbvfnNVhlF/KPEinQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ma9PfYK2+C2Gmmf6sKeSnnddCPTWDEDv0Y6JAY8pioo=; b=DQNMZrMn87yfa2SoubJK9Ptt2Ie+jp/kqRyxs5YSceK2ihenR5hhB3fF5z9xm+SzPan/vaT172uM0wCTjayBa5k5N9C2iTCdXs3NMeJusJuXSygJQp3Uae7NFimhHh2k44GupY9RTf6LG4Dfnbkp01qSxGvdKkgPAaSBRMtkiaD1Gy4HkKQRY2GFGG2ZNMtcTOxoakR/R2HgJkey31RV7SeoCrsAFQOeJLw588TV76TqPcPnzDLxwlRRPADov/W3ICBZFE9PI75ipQZrct3mya/4hVzaLZWCok9TLhxLqo81W4O82WlFfOl9xw/D7zbYR75ob7bo0iQ/imyOlQXJTg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ma9PfYK2+C2Gmmf6sKeSnnddCPTWDEDv0Y6JAY8pioo=; b=f0ki8jZfN0IaN4teluH+cEDgTzwxpgloC4Fe3KHsBEwArjWFpvRiz4/qv0CE8PNHJBsaExB3iZQoL+uKSPuKLGQ9tDg1R9gIc7QCEtGjEmrMoql5Us7Htl1GHWnwIV5CpwqrArrR3Momj7RW/LQjm15XKsR/2a9qmLRiJ9G3KyrBcGCKmvqTjysKWVmcfAcVRxogLU0ZQQTvH1yysLMW67B0woCuuUjiKEskrQ17FsY4fystLFf9VcxWWBzrk+1ZWnAqTmQzcaP83ZtlkdXPhWgIzyEIS9MNRYGYPGWQxgDiVYh+Xq8TSBRD2Wf1IYgEZ+oEFfVN5VsOwD62PBTyiw== Original-Received: from SN1NAM02FT033.eop-nam02.prod.protection.outlook.com (10.152.72.52) by SN1NAM02HT018.eop-nam02.prod.protection.outlook.com (10.152.73.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.25; Sun, 14 Mar 2021 05:50:14 +0000 Original-Received: from CH2PR01MB5879.prod.exchangelabs.com (2a01:111:e400:7e44::4c) by SN1NAM02FT033.mail.protection.outlook.com (2a01:111:e400:7e44::133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32 via Frontend Transport; Sun, 14 Mar 2021 05:50:14 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:BA547F6462115ECD6554B17681FF780B645661ECF5A5533A4554F53A7A5E9B2B; UpperCasedChecksum:D4A8958C0098A35B4C8F19C866F99B17E7DA7BD86AF64F6E5271730F0646138C; SizeAsReceived:7255; Count:42 Original-Received: from CH2PR01MB5879.prod.exchangelabs.com ([fe80::592f:9a58:d8cd:d9c9]) by CH2PR01MB5879.prod.exchangelabs.com ([fe80::592f:9a58:d8cd:d9c9%7]) with mapi id 15.20.3912.031; Sun, 14 Mar 2021 05:50:14 +0000 X-TMN: [KVqofWfL1C4IP0UdRkdX0mkp50Rjed5OSR26cohRQZtjWGZyLT/WXKH6EaC6Xesr] X-ClientProxiedBy: CP2P15201CA0008.LAMP152.PROD.OUTLOOK.COM (2603:10d6:102:1a::18) To CH2PR01MB5879.prod.exchangelabs.com (2603:10b6:610:3c::12) X-Microsoft-Original-Message-ID: <87wnuamghd.fsf@hotmail.com> X-MS-Exchange-MessageSentRepresentingType: 1 Original-Received: from precision5540 (2804:431:c7f3:d29c:53b4:90fd:7c9c:69ef) by CP2P15201CA0008.LAMP152.PROD.OUTLOOK.COM (2603:10d6:102:1a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.31 via Frontend Transport; Sun, 14 Mar 2021 05:50:11 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 42 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 7d03fc62-2175-4a73-67e0-08d8e6ad08c4 X-MS-TrafficTypeDiagnostic: SN1NAM02HT018: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: V63mT8j9muM0YQhb+7qf7cYc7fdDibgPUUQTVaNyowwfFBApxkDkCs2WCu/a716ZJ3mA4zDNhxLcunfAgUiJXKGQoOjZJYF2xGXgzKezeBn1WHlJGrywa9bxwF83XxC1xxtWKdbiSlq4mGWtRdWu4INX3sh6iI46biVrHF6WmDgusb0opLyaNIbsJjn5q0GaKpYyh2348l1dshsDhx9kyBxT9RyRxNdi0gLRzEdgmwafS08RSip9FaJNH0cpDCd+WHsxEamfO9Re6/18WpMf7IXFlvGELUkla7atNcH+LK5cnFgeX16vcyU3oTcsFDjhPC/ONABpR8A9A0sVZoo0lqK/FdNenp5GPxNN7ySB7gsLa4SOAAGaHuR1OebrDwzL X-MS-Exchange-AntiSpam-MessageData: OohEnkZtHkV1Rh754rJfpwjtXVDHcCEyQFTRVyVQAJebUfMaPZNQYofsIstvVRNrrYUGBF3RSP3kZ9Kma5/fzq+Nu3Jmcv748e0LhpEUZtLcZgLahr0Dj7yeu3+5OiJacmNhbsI/8x3Il4k4XbLSGDLRjQVtM1HpGU/LhygfrX55xaaxeH7vpul1U+ZNmXgIUqKTRk1DHASsm9nysWCGBQ== X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7d03fc62-2175-4a73-67e0-08d8e6ad08c4 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Mar 2021 05:50:14.0305 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT033.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1NAM02HT018 Received-SPF: pass client-ip=40.92.5.98; envelope-from=gabriel376@hotmail.com; helo=NAM02-SN1-obe.outbound.protection.outlook.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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" Xref: news.gmane.io gmane.emacs.bugs:202332 Archived-At: --=-=-= Content-Type: text/plain A possible bug exists on uniquify.el when 'uniquify-strip-common-suffix' and 'uniquify-trailing-separator-p' are both set to true. Case 1: when 'uniquify-strip-common-suffix' is t and 'uniquify-trailing-separator-p' is nil 1. emacs -Q 2. Configure uniquify: (setq-default uniquify-buffer-name-style 'forward uniquify-strip-common-suffix t uniquify-trailing-separator-p nil) 3. Open two similar dired buffers, e.g.: C-x C-f "~/A/gnu/emacs/lisp" RET C-x C-f "~/B/gnu/emacs/lisp" RET 4. The buffers will be renamed to 'A/lisp' and 'B/lisp' as expected, because 'uniquify-strip-common-suffix' is true and 'uniquify-trailing-separator-p' is nil Case 2: when 'uniquify-strip-common-suffix' is nil and 'uniquify-trailing-separator-p' is t 1. emacs -Q 2. Configure uniquify: (setq-default uniquify-buffer-name-style 'forward uniquify-strip-common-suffix nil uniquify-trailing-separator-p t) 3. Open two similar dired buffers, e.g.: C-x C-f "~/A/gnu/emacs/lisp" RET C-x C-f "~/B/gnu/emacs/lisp" RET 4. The buffers will be renamed to 'A/gnu/emacs/lisp/' and 'B/gnu/emacs/lisp/' as expected, because 'uniquify-strip-common-suffix' is nil and 'uniquify-trailing-separator-p' is true Case 3: when 'uniquify-strip-common-suffix' is t and 'uniquify-trailing-separator-p' is t 1. emacs -Q 2. Configure uniquify: (setq-default uniquify-buffer-name-style 'forward uniquify-strip-common-suffix t uniquify-trailing-separator-p t) 3. Open two similar dired buffers, e.g.: C-x C-f "~/A/gnu/emacs/lisp" RET C-x C-f "~/B/gnu/emacs/lisp" RET 4. The buffers will be renamed to 'A/lisp' and 'B/lisp'. The common suffix was removed as expected, but the trailing separator is missing Cause: It seems that the following verification on 'uniquify-get-proposed-name' fails because dirname is not the true dirname, but the one with the common suffix stripped. Thus, 'file-directory-p' fails to find the directory: ;; Distinguish directories by adding extra separator. (if (and uniquify-trailing-separator-p (file-directory-p (expand-file-name base dirname)) ;; <-- HERE (not (string-equal base ""))) (cond ((eq uniquify-buffer-name-style 'forward) (setq base (file-name-as-directory base))) ;; (setq base (concat base "/"))) ((eq uniquify-buffer-name-style 'reverse) (setq base (concat (or uniquify-separator "\\") base))))) The dirname on the line above is '~/A' and '~/B' for each invocation (common suffix was stripped), so 'expand-file-name' expands to '~/A/lisp' and '~/B/lisp' and 'file-directory-p' fails to find it. The function that removes the common suffix is 'uniquify-rationalize'. I managed to create a patch where the original dirname is preserved in the 'uniquify-item' struct and passed along as an optional argument, so 'uniquify-get-proposed-name' can properly verify if the directory exists. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Make-uniquify-trailing-separator-p-work-with-uniquif.patch >From 2ca185f2f7fbbc7f68f78c0d052242a3329a6e53 Mon Sep 17 00:00:00 2001 From: Gabriel do Nascimento Ribeiro Date: Sun, 14 Mar 2021 02:33:20 -0300 Subject: [PATCH] Make uniquify-trailing-separator-p work with uniquify-strip-common-suffix lisp/uniquify.el: (uniquify-item): New slot 'original-dirname'. (uniquify-rationalize-file-buffer-names): Use new slot. (uniquify-rationalize): Use new slot. (uniquify-get-proposed-name): New optional argument 'original-dirname' to properly add a trailing separator when the corresponding user option is set and the dirname is an existing directory. --- lisp/uniquify.el | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lisp/uniquify.el b/lisp/uniquify.el index c1ec90e290..9c0576ee93 100644 --- a/lisp/uniquify.el +++ b/lisp/uniquify.el @@ -175,8 +175,8 @@ uniquify-list-buffers-directory-modes (cl-defstruct (uniquify-item (:constructor nil) (:copier nil) (:constructor uniquify-make-item - (base dirname buffer &optional proposed))) - base dirname buffer proposed) + (base dirname buffer &optional proposed original-dirname))) + base dirname buffer proposed original-dirname) ;; Internal variables used free (defvar uniquify-possibly-resolvable nil) @@ -211,7 +211,7 @@ 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))) + (let ((fix-list (list (uniquify-make-item base dirname newbuf nil dirname))) items) (dolist (buffer (buffer-list)) (when (and (not (and uniquify-ignore-buffers-re @@ -284,7 +284,9 @@ uniquify-rationalize ;; Refresh the dirnames and proposed names. (setf (uniquify-item-proposed item) (uniquify-get-proposed-name (uniquify-item-base item) - (uniquify-item-dirname item))) + (uniquify-item-dirname item) + nil + (uniquify-item-original-dirname item))) (setq uniquify-managed fix-list))) ;; Strip any shared last directory names of the dirname. (when (and (cdr fix-list) uniquify-strip-common-suffix) @@ -307,7 +309,8 @@ uniquify-rationalize (uniquify-item-dirname item)))) (and f (directory-file-name f))) (uniquify-item-buffer item) - (uniquify-item-proposed item)) + (uniquify-item-proposed item) + (uniquify-item-original-dirname item)) fix-list))))) ;; If uniquify-min-dir-content is 0, this will end up just ;; passing fix-list to uniquify-rationalize-conflicting-sublist. @@ -335,13 +338,13 @@ uniquify-rationalize-a-list (uniquify-rationalize-conflicting-sublist conflicting-sublist old-proposed depth))) -(defun uniquify-get-proposed-name (base dirname &optional depth) +(defun uniquify-get-proposed-name (base dirname &optional depth original-dirname) (unless depth (setq depth uniquify-min-dir-content)) (cl-assert (equal (directory-file-name dirname) dirname)) ;No trailing slash. ;; Distinguish directories by adding extra separator. (if (and uniquify-trailing-separator-p - (file-directory-p (expand-file-name base dirname)) + (file-directory-p (expand-file-name base original-dirname)) (not (string-equal base ""))) (cond ((eq uniquify-buffer-name-style 'forward) (setq base (file-name-as-directory base))) @@ -410,7 +413,8 @@ uniquify-rationalize-conflicting-sublist (uniquify-get-proposed-name (uniquify-item-base item) (uniquify-item-dirname item) - depth))) + depth + (uniquify-item-original-dirname item)))) (uniquify-rationalize-a-list conf-list depth)) (unless (string= old-name "") (uniquify-rename-buffer (car conf-list) old-name))))) -- 2.27.0 --=-=-=--