From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: sbaugh@catern.com Newsgroups: gmane.emacs.bugs Subject: bug#62732: 29.0.60; uniquify-trailing-separator-p affects any buffer whose name matches a dir in CWD Date: Sun, 09 Jul 2023 14:49:24 +0000 (UTC) Message-ID: <87h6qdm970.fsf@catern.com> References: <87h6tpn8d5.fsf@catern.com> <87edotn7sx.fsf@catern.com> <87a5zhmexh.fsf@catern.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19822"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 62732@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jul 09 16:50:28 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 1qIVk3-0004xj-8v for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 09 Jul 2023 16:50:28 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIVjg-0000uF-DC; Sun, 09 Jul 2023 10:50:04 -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 1qIVjf-0000u6-AP for bug-gnu-emacs@gnu.org; Sun, 09 Jul 2023 10:50:03 -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 1qIVjf-0005gN-1j for bug-gnu-emacs@gnu.org; Sun, 09 Jul 2023 10:50:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qIVje-0001jb-EP for bug-gnu-emacs@gnu.org; Sun, 09 Jul 2023 10:50:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: sbaugh@catern.com Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 09 Jul 2023 14:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62732 X-GNU-PR-Package: emacs Original-Received: via spool by 62732-submit@debbugs.gnu.org id=B62732.16889141736626 (code B ref 62732); Sun, 09 Jul 2023 14:50:02 +0000 Original-Received: (at 62732) by debbugs.gnu.org; 9 Jul 2023 14:49:33 +0000 Original-Received: from localhost ([127.0.0.1]:46983 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qIVjA-0001in-Gr for submit@debbugs.gnu.org; Sun, 09 Jul 2023 10:49:32 -0400 Original-Received: from s.wrqvtbkv.outbound-mail.sendgrid.net ([149.72.123.24]:36106) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qIVj8-0001ia-6Y for 62732@debbugs.gnu.org; Sun, 09 Jul 2023 10:49:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=catern.com; h=from:subject:in-reply-to:references:mime-version:to:cc:content-type: content-transfer-encoding:cc:content-type:from:subject:to; s=s1; bh=Q0AC9LCvwlAI5F5LEYTeFmfQVxPkqIQy6ccZSVzIQJM=; b=ZVi8OImeWOZoGsEA4JVxVMa2qcsmyfPkWDklBCZeSVHodjEigMeWxt7KHXaxK2vTYCto cB8LgpUSKFx/oJX9QKV3aTtCZ9CO/VYa+h8Tjl+4aor2c+TawwEX92Q0J9/HocV1gAUq8K NdnTWCPQ80s9X1W06fnPeMETjuqaPt/I7VRKw5q0qqDx34fqS6RPPxnzPZlpbDXevWdcbd /15n59tVykunmJR7w88JMD6VTo5TVJ11oaaKkcHCPKIxSnu2KEtGiC69BGnR4pabdbGvFM QWG9IAhTs4jmA5ciwM9SWnCPRa/QNRizptclfbnqSV8GIeMKJx8ZJy7a2elfu7oQ== Original-Received: by filterdrecv-66949dbc98-gwbzx with SMTP id filterdrecv-66949dbc98-gwbzx-1-64AAC8F4-17 2023-07-09 14:49:24.70791341 +0000 UTC m=+5152176.490730328 Original-Received: from earth.catern.com (unknown) by geopod-ismtpd-0 (SG) with ESMTP id Yo7Qb36mQ3Gr_QPX11zyGQ Sun, 09 Jul 2023 14:49:24.555 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=::1; helo=localhost; envelope-from=sbaugh@catern.com; receiver=iro.umontreal.ca Original-Received: from localhost (localhost [IPv6:::1]) by earth.catern.com (Postfix) with ESMTPSA id 0DC3F60077; Sun, 9 Jul 2023 10:49:23 -0400 (EDT) In-Reply-To: (Stefan Monnier's message of "Sat, 08 Jul 2023 13:48:55 -0400") X-SG-EID: ZgbRq7gjGrt0q/Pjvxk7wM0yQFRdOkTJAtEbkjCkHbK6mWrOJW9S248jf8F2zd/LlSA4SWAyIihuHZsV8Ai9eKsB0zAteHJhjAbKFS5coM1K4eT8rTysm9fx5RWlVoAnziBVxGKgM/VJ5B6sIFRyXIVwC4vhOrK0n2hcogoW/+F0gI+FbBQ02iywDp9DnPRZIvHpTHG9p78sJJhX7KIj+A== X-Entity-ID: d/0VcHixlS0t7iB1YKCv4Q== 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:264840 Archived-At: Stefan Monnier writes: >> Ping again on this latest version of my patch. I have some actual >> features I'd like to add to uniquify, but they're on top of this patch. >> Plus it would be nice to land the tests added in my patch. > > Sorry for not following up further, but I was waiting for a reaction to > my proposal to replace the additional arg to `create-file-buffer` > by the patch below. Ah, that unfortunately doesn't work, at least on its own. It causes the tests I added for uniquify to immediately fail. The reason it doesn't work, I believe, is that it makes us try to uniquify buffers with their numeric suffix included (which is the initial name the buffer gets). And such buffers are of course already unique, so uniquify stops doing anything. We could remove the suffix, but what we really want is just "the name we wanted to give the buffer, before any uniquifying", aka the basename. And we have that in create-file-buffer, so it seems better to just pass it down directly. > If we can't avoid changing the API of `create-file-buffer`, I'd like > a comment explaining clearly why. So, the thing we want to communicate to uniquify is, the basename of the buffer: the name we want for the buffer before it's made unique. For regular files this is (file-name-nondirectory file), the last component of the file name. Before this patch, the basename (as passed to uniquify) was always (file-name-nondirectory (directory-file-name dir)) for directories. So directories and regular files looked the same to uniquify. So it needed to add the trailing separator some other way (by checking file-directory-p). After this patch, the trailing separator is added *as part of the basename* as passed to uniquify. So uniquify doesn't need to do anything, just uniquify the buffer like it would any other, and indeed uniquify.el no longer uses uniquify-trailing-separator-p at all. > As it stands the patch is a bit vague > about that, if not confusing: > > ;; FIXME we really need to fold the uniquify stuff in here by default, > -;; not using advice, and add it to the doc string. > -(defun create-file-buffer (filename) > +(defun create-file-buffer (filename &optional directory) > "Create a suitably named buffer for visiting FILENAME, and return it. > FILENAME (sans directory) is used unchanged if that name is free; > -otherwise a string <2> or <3> or ... is appended to get an unused name. > +otherwise the buffer is renamed according to > +`uniquify-buffer-name-style' to get an unused name. > > Emacs treats buffers whose names begin with a space as internal buffers. > To avoid confusion when visiting a file whose name begins with a space, > -this function prepends a \"|\" to the final result if necessary." > +this function prepends a \"|\" to the final result if necessary. > + > +If DIRECTORY is non-nil, a file name separator will be added to > +the buffer name according to `uniquify-trailing-separator-p'." > > Where will that separator be added? It is added in create-file-buffer, in the calculation of basename. > And why is the arg called `directory`? Because we are indicating that this filename is a directory, or at least that we want to visit this filename as if it was a directory. > And why/when is that arg needed, since the separator will often be > introduced anyway by uniquify even with a nil arg? This is now the only place that uniquify-trailing-separator-p is used, so the separator won't be introduced if DIRECTORY is nil.