bug#81613: [PATCH] Make vc-dir use display-buffer instead of pop-to-buffer

Protesilaos <[email protected]>
Newsgroups gmane.emacs.bugs
Message-ID <[email protected]>
> Date: Fri, 14 Aug 2026 11:43:58 +0100
> 
> Protesilaos [13/Aug  9:42pm +03] wrote:
>> So if we want to match 'derived-mode' then my patch should be updated 
>> to
>> use 'pop-to-buffer' instead of 'display-buffer', or is there something
>> else?
> 
> I think that's right, yes.

Thanks! I prepared the new patch.
0001-Make-vc-dir-set-its-major-mode-before-displaying-its.patch (text/x-diff, 3 KB)
From f358bb37b3bebd2f63cbb4cd30b735d16ffa79e1 Mon Sep 17 00:00:00 2001
Message-ID: <f358bb37b3bebd2f63cbb4cd30b735d16ffa79e1.1786705662.git.info@protesilaos.com>
From: Protesilaos <[email protected]>
Date: Fri, 14 Aug 2026 14:07:32 +0300
Subject: [PATCH] Make vc-dir set its major mode before displaying its buffer

* etc/NEWS: Announce the change.
* lisp/vc/vc-dir.el (vc-dir): Create the buffer, prepare it, then call 'pop-to-buffer'.
---
 etc/NEWS          |  6 ++++++
 lisp/vc/vc-dir.el | 26 ++++++++++++++------------
 2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 43c667647e1..f7791658896 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -197,6 +197,12 @@ has a VC backend.  If it doesn't, but the directory's truename does
 have a backend, and 'vc-follow-symlinks' is non-nil, the truename is
 used instead.  Previously, the truename was used unconditionally.
 
+---
+*** VC-Dir sets its major mode before displaying its buffer.
+This means that a 'display-buffer-alist' element can now match the
+buffer with '(derived-mode . vc-dir-mode)'. Whereas before it could only
+match it reliably with a regular expression like "\\`\\*vc-dir\\*\\'".
+
 +++
 *** Improved creation of commit log entry from ChangeLog.
 When VC detects that all log entries for the current changeset come from
diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el
index d75dce77493..db436fa6554 100644
--- a/lisp/vc/vc-dir.el
+++ b/lisp/vc/vc-dir.el
@@ -2027,18 +2027,20 @@ (defun vc-dir (dir &optional backend)
 	  nil t nil nil)))))
   (unless backend
     (setq backend (vc-responsible-backend dir)))
-  (let (pop-up-windows)		      ; based on cvs-examine; bug#6204
-    (pop-to-buffer (vc-dir-prepare-status-buffer "*vc-dir*" dir backend)))
-  (if (derived-mode-p 'vc-dir-mode)
-      (vc-dir-refresh)
-    ;; FIXME: find a better way to pass the backend to `vc-dir-mode'.
-    (let ((use-vc-backend backend))
-      (vc-dir-mode)
-      ;; Activate the backend-specific minor mode, if any.
-      (when-let* ((minor-mode
-                   (intern-soft (format "vc-dir-%s-mode"
-                                        (downcase (symbol-name backend))))))
-        (funcall minor-mode 1)))))
+  (let ((pop-up-windows)		      ; based on cvs-examine; bug#6204
+        (buffer (vc-dir-prepare-status-buffer "*vc-dir*" dir backend)))
+    (with-current-buffer buffer
+      (if (derived-mode-p 'vc-dir-mode)
+          (vc-dir-refresh)
+        ;; FIXME: find a better way to pass the backend to `vc-dir-mode'.
+        (let ((use-vc-backend backend))
+          (vc-dir-mode)
+          ;; Activate the backend-specific minor mode, if any.
+          (when-let* ((minor-mode
+                       (intern-soft (format "vc-dir-%s-mode"
+                                            (downcase (symbol-name backend))))))
+            (funcall minor-mode 1)))))
+    (pop-to-buffer buffer)))
 
 (defun vc-default-dir-extra-headers (_backend _dir)
   ;; Be loud by default to remind people to add code to display
-- 
2.47.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.