From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Boruch Baum Newsgroups: gmane.emacs.bugs Subject: bug#44023: dired-allow-duplicate-buffers Date: Thu, 15 Oct 2020 15:22:31 -0400 Message-ID: <20201015192231.rezuhk7foiyq3uff@E15-2016.optimum.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="msxhrqipppmkva3s" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40032"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: NeoMutt/20180716 To: 44023@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 15 21:23:33 2020 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 1kT8qb-000AJa-Ei for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 15 Oct 2020 21:23:33 +0200 Original-Received: from localhost ([::1]:54460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kT8qa-0001KV-6L for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 15 Oct 2020 15:23:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kT8q6-0001KH-Nx for bug-gnu-emacs@gnu.org; Thu, 15 Oct 2020 15:23:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45061) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kT8q6-0003bv-E6 for bug-gnu-emacs@gnu.org; Thu, 15 Oct 2020 15:23:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kT8q6-0006oO-BC for bug-gnu-emacs@gnu.org; Thu, 15 Oct 2020 15:23:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Boruch Baum Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 15 Oct 2020 19:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 44023 X-GNU-PR-Package: emacs X-Debbugs-Original-To: Emacs Bug Reporting Original-Received: via spool by submit@debbugs.gnu.org id=B.160278976726148 (code B ref -1); Thu, 15 Oct 2020 19:23:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 15 Oct 2020 19:22:47 +0000 Original-Received: from localhost ([127.0.0.1]:56607 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kT8pq-0006ng-N0 for submit@debbugs.gnu.org; Thu, 15 Oct 2020 15:22:47 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:43228) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kT8po-0006nY-Fb for submit@debbugs.gnu.org; Thu, 15 Oct 2020 15:22:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50752) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kT8pn-0001J6-Fz for bug-gnu-emacs@gnu.org; Thu, 15 Oct 2020 15:22:44 -0400 Original-Received: from mout.gmx.net ([212.227.17.22]:43211) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kT8ph-0003Ze-RM for bug-gnu-emacs@gnu.org; Thu, 15 Oct 2020 15:22:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1602789754; bh=/SJJnVZEy5RRIWKc56csu+wxNMnvC4MyH2vuiIAczGg=; h=X-UI-Sender-Class:Date:From:To:Subject; b=JAspH/DB2Fdcjn1donsSvYiqfAFkt0DsBsUsanCQlg1IqwhG7lph5ZhYD7XJwBcuP VRTBOlzHYD2hkQxMtwadtaAJr9pG62hBkqQPS8FXV59oHqJBgSEpxkK+sL1SEieRMA hJ57OR8BLBl5T2BmlI73FEicYzLLCtT9cSCnVQLU= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from E15-2016.optimum.net ([72.89.170.172]) by mail.gmx.com (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1N0XD2-1kGzlN45n2-00wUrX for ; Thu, 15 Oct 2020 21:22:34 +0200 Content-Disposition: inline X-Provags-ID: V03:K1:c+GDlkmTijU7Xy4gbBe21iABJGeGt3VRZYQzzcKEbz/ePdWYvU6 cEA6AgwdSeB8eunnLnPRbNK/tgu9IBq9n9IXEGt/U92rXM6OOlcD3YSgGVGRfSggBQIh3R9 gRfyeyiFKby647cIdRGGNoHMWQcCi1t39Pd15erfrjUtl1hGji/E551HxctN5kaZZ5lNx3P ab6GAtlmiUNpG3EBD2iqA== X-UI-Out-Filterresults: notjunk:1;V03:K0:Ud0RRKRQEAY=:WIuzdZL/kEVsz08/8+ShxF dblNn0HN14hZNumw/wm8FAp3Fea811+zb0Vv//BOZRk4SfSvyXtCAfZd/h/naV71l/Mtdk7tD ETFyMHK847fxaH+VlNfRO4Pe4lsdkFnxflyqyU4uIcNekZWWHFnJObGuCiOLUk2e35/upSdag sOznSlNQZYJ//Jj54zmPoXHaNgqt2n2yVGnOXQvjr46ZfbfT/uOnmDeaVV9vzY2aBlhIo5oTc Vs9TlilGF2ERDXyX+PjXBjfmLxJweRUZrGPjLqiTTyK4QmD4RjcAxWvaj1AbX2virIlv1Uujc vsmK1qVBOeDWZhnJsdaSz74DnS/fnQNEnUY2++79A2X2bAyfWWmqxsnZ7GwN/bfjJ8feGiRoF UkoS4u5CChl7pB3DMFZfvljiUkptMW9yxDtfA73k/ALkp98jfpRNl5ozRV0TStgHg+Uf1KaZZ cbGLvp5sPhqyoz86paKrNLaBzUXF4QIO0DIJgw1WNa1BPIjSbd8h4RIiRZFphqPA/7fgXooft 0Z3622bYb/BfEHc69AUu/8QSjcanCYfhXd9gKniS1eafZzrcmZnWISej1GPbY8BVBrNLLt14F ibsID9wSE/tl0DxrbgGqYonG63UZUzLVGOigiSjebXwlyqkjl9JXGGK+H7HujiUuX4xun1l2l 95dLwPy1jW/o9kxIfpY37dV8VFi8Dtdj91UjbxeCcylDP57Ly0E4O7OtBRt+gCjD0ZnSMZ12h q4x9Z2yOTqiCcw5fv/AoHJqjHT0hoDgrtDP3692kDmPkuUzjVSfbU7NNvh/utcMZe1cSs6oC Received-SPF: pass client-ip=212.227.17.22; envelope-from=boruch_baum@gmx.com; helo=mout.gmx.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/15 14:57:52 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=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:190629 Archived-At: --msxhrqipppmkva3s Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable The attached patch adds a defcustom option to allow multiple buffers to visit the same directory. This became desirable to me for an extension I wrote (soon to be submitted) to store each chain of dired buffers' 'navigation history' and allow going back/forward to any point in the history. As you all know, this has been a feature common to all file *managers* since almost forever; technically dired is a directory editor, not a file manager, but I expect many will find the feature desirable, even expected, since all other similar programs have it. In going through the existing dired code, it seems that some functions presume that multiple buffers can be visiting the same directory. See: dired-find-buffer-nocreate dired-fun-in-all-buffers dired-clean-up-after-deletion Also, implicit in the comment for `dired-find-buffer-nocreate' is that more than one match may exist for a dired directory buffer. So, maybe this once existed or was planned? The first patch is for the option. The second patch is a change of comments to docstrings. =2D- hkp://keys.gnupg.net CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0 --msxhrqipppmkva3s Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="1.patch" Content-Transfer-Encoding: quoted-printable diff --git a/NEWS b/NEWS index a76447d..ca7f31b 100644 =2D-- a/NEWS +++ b/NEWS @@ -284,6 +284,10 @@ time zones will use a form like "+0100" instead of "C= ET". ** Dired ++++ +*** New user option: 'dired-allow-duplicate-buffers' +If set, allows multiple dired buffers to visit the same directory. + --- *** Broken and circular links are shown with the 'dired-broken-symlink' f= ace. diff --git a/dired.el b/dired.el index 7839ace..36c2f17 100644 =2D-- a/dired.el +++ b/dired.el @@ -353,6 +353,12 @@ is anywhere on its Dired line, except the beginning o= f the line." :group 'dired :version "28.1") +(defcustom dired-allow-duplicate-buffers t + "Allow multiple `dired' buffers to visit the same directory." + :type 'boolean + :group 'dired + :version "28.1") + ;; Internal variables (defvar dired-marker-char ?* ; the answer is 42 @@ -1152,9 +1158,11 @@ The return value is the target column for the file = names." ;; see there. (let* ((old-buf (current-buffer)) (dirname (if (consp dir-or-list) (car dir-or-list) dir-or-list)) - ;; Look for an existing buffer. - (buffer (dired-find-buffer-nocreate dirname mode)) - ;; Note that buffer already is in dired-mode, if found. + (buffer (when (not (bound-and-true-p dired-allow-duplicate-buffe= rs)) + ;; Look for an existing buffer. + (dired-find-buffer-nocreate dirname mode) + ;; Note that buffer already is in dired-mode, if found= . + )) (new-buffer-p (null buffer))) (or buffer (setq buffer (create-file-buffer (directory-file-name dirname)))) --msxhrqipppmkva3s Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="2.patch" diff --git a/dired.el b/dired.el index 36c2f17..2ecd6bd 100644 --- a/dired.el +++ b/dired.el @@ -1143,19 +1143,21 @@ The return value is the target column for the file names." (forward-line))))))) (defun dired-internal-noselect (dir-or-list &optional switches mode) - ;; If DIR-OR-LIST is a string and there is an existing dired buffer - ;; for it, just leave buffer as it is (don't even call dired-revert). - ;; This saves time especially for deep trees or with ange-ftp. - ;; The user can type `g' easily, and it is more consistent with find-file. - ;; But if SWITCHES are given they are probably different from the - ;; buffer's old value, so call dired-sort-other, which does - ;; revert the buffer. - ;; Revert the buffer if DIR-OR-LIST is a cons or `dired-directory' - ;; is a cons and DIR-OR-LIST is a string. - ;; A pity we can't possibly do "Directory has changed - refresh? " - ;; like find-file does. - ;; Optional argument MODE is passed to dired-find-buffer-nocreate, - ;; see there. + "Internal function for `dired-noselect'. + +If DIR-OR-LIST is a string and there is an existing dired buffer +for it, just leave buffer as it is (don't even call `dired-revert'). +This saves time especially for deep trees or with `ange-ftp'. +The user can type `g' easily, and it is more consistent with `find-file'. +But if SWITCHES are given they are probably different from the +buffer's old value, so call `dired-sort-other', which does +revert the buffer. +Revert the buffer if DIR-OR-LIST is a cons or `dired-directory' +is a cons and DIR-OR-LIST is a string. +A pity we can't possibly do \"Directory has changed - refresh?\" +like `find-file' does. +Optional argument MODE is passed to `dired-find-buffer-nocreate', +see there." (let* ((old-buf (current-buffer)) (dirname (if (consp dir-or-list) (car dir-or-list) dir-or-list)) (buffer (when (not (bound-and-true-p dired-allow-duplicate-buffers)) @@ -1219,20 +1221,24 @@ The return value is the target column for the file names." buffer)) (defvar dired-buffers nil - ;; Enlarged by dired-advertise - ;; Queried by function dired-buffers-for-dir. When this detects a - ;; killed buffer, it is removed from this list. - "Alist of expanded directories and their associated Dired buffers.") + "Alist of expanded directories and their associated Dired buffers. +The list is enlarged by `dired-advertise'. Function +`dired-buffers-for-dir' queries this list and removes killed +buffers from it, when detected.") (defvar dired-find-subdir) +;; `dired-find-subdir' is defined in `dired-x.el' ;; FIXME add a doc-string, and document dired-x extensions. (defun dired-find-buffer-nocreate (dirname &optional mode) - ;; This differs from dired-buffers-for-dir in that it does not consider - ;; subdirs of default-directory and searches for the first match only. - ;; Also, the major mode must be MODE. - (if (and (featurep 'dired-x) - dired-find-subdir + "Internal function for `dired-internal-noselect'. +Searches among buffers of major-mode MODE (default `dired-mode') +for one visiting DIRNAME, and returns the first one found. This +differs from `dired-buffers-for-dir' in that it does not consider +subdirs of `default-directory', it searches only for the first +match, and it can restrict its search to buffers of +major-mode MODE." + (if (and (featurep 'dired-x) dired-find-subdir ;; Don't try to find a wildcard as a subdirectory. (string-equal dirname (file-name-directory dirname))) (let* ((cur-buf (current-buffer)) --msxhrqipppmkva3s--