master 02fb63f7fe9 1/2: VC-Dir: Let backends supply a custom mode and key binding hints

Sean Whitton <[email protected]> Mon, 6 Jul 2026 10:52:19 -0400 (EDT)
Newsgroups gmane.emacs.diffs
Message-ID <[email protected]>
branch: master
commit 02fb63f7fe9aca2974d47095e5281919d173967a
Author: Sean Whitton <[email protected]>
Commit: Sean Whitton <[email protected]>

    VC-Dir: Let backends supply a custom mode and key binding hints
    
    * lisp/vc/vc.el (dir-extra-hints, dir-mode): Specify new backend
    methods.
    (vc-dir-mode): Declare.
    (vc-default-dir-mode, vc-default-dir-extra-hints): New
    functions.
    * lisp/vc/vc-dir.el (vc-dir-headers, vc-dir): Call the new
    backend methods.
    * lisp/cedet/ede.el (ede-turn-on-hook): Use derived-mode-p
    instead of looking at major-mode directly.
    * etc/NEWS: Document the new backend methods.
---
 etc/NEWS          | 23 ++++++++++++++---------
 lisp/cedet/ede.el |  2 +-
 lisp/vc/vc-dir.el | 12 ++++++++----
 lisp/vc/vc.el     | 19 ++++++++++++++++++-
 4 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 80bb25183bd..0a5bf6d8af6 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -119,15 +119,6 @@ are now buttonized, allowing using mouse or 'RET' to follow them.
 
 ** VC
 
-+++
-*** Improved creation of commit log entry from ChangeLog.
-When VC detects that all log entries for the current changeset come from
-the same ChangeLog file or buffer, it now inserts the entire body of the
-ChangeLog entry into the *vc-log* buffer.  If the ChangeLog entry
-contains a summary line, VC inserts it into the *vc-log* Summary header.
-If VC detects that the set of changed files listed in the ChangeLog
-entry differs from the current VC fileset, it displays a warning.
-
 +++
 *** VC-Dir outgoing revisions count is now asynchronous.
 This means it won't get in your way even if it's slow for your
@@ -139,6 +130,11 @@ obsolete.
 To hide these, you can customize the new user option
 'vc-dir-show-key-binding-hints' to nil.
 
+---
+*** Backends can supply a derived mode for VC-Dir buffers.
+Backend authors can use the new backend methods 'dir-mode' and
+'dir-extra-hints'.
+
 ---
 *** VC-Dir doesn't process very large status output by default.
 If the VCS status process used to populate the VC-Dir buffer produces a
@@ -150,6 +146,15 @@ message saying so, with a button to override it.  You can customize the
 new user option 'vc-dir-process-output-limit' to control how early to
 stop, and to disable this feature.
 
++++
+*** Improved creation of commit log entry from ChangeLog.
+When VC detects that all log entries for the current changeset come from
+the same ChangeLog file or buffer, it now inserts the entire body of the
+ChangeLog entry into the *vc-log* buffer.  If the ChangeLog entry
+contains a summary line, VC inserts it into the *vc-log* Summary header.
+If VC detects that the set of changed files listed in the ChangeLog
+entry differs from the current VC fileset, it displays a warning.
+
 ** Outline mode
 
 *** New command 'outline-show-entry-and-parents'.
diff --git a/lisp/cedet/ede.el b/lisp/cedet/ede.el
index 36864e6f3e9..478d8911c1f 100644
--- a/lisp/cedet/ede.el
+++ b/lisp/cedet/ede.el
@@ -469,7 +469,7 @@ To be used in hook functions."
 	  ;; Emacs 21 has no buffer file name for directory edits.
 	  ;; so we need to add these hacks in.
 	  (eq major-mode 'dired-mode)
-	  (eq major-mode 'vc-dir-mode))
+	  (derived-mode-p 'vc-dir-mode))
       (ede-minor-mode 1)))
 
 (define-minor-mode ede-minor-mode
diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el
index 0425f89256f..5c4727b43bd 100644
--- a/lisp/vc/vc-dir.el
+++ b/lisp/vc/vc-dir.el
@@ -1597,8 +1597,10 @@ elements to this list.")
 
 (defun vc-dir-headers (backend dir)
   "Display the headers in the *VC-Dir* buffer.
-It calls the `dir-extra-headers' backend method to display backend
-specific headers."
+It calls the `dir-extra-hints' backend method to display
+backend-specific key binding hints.
+It calls the `dir-extra-headers' backend method to display
+backend-specific headers."
   (kill-local-variable 'vc-dir-async-header-values)
   (concat
    (and
@@ -1625,7 +1627,9 @@ specific headers."
       "(\\[vc-diff]) Diff, "
       "(\\[revert-buffer]) Refresh, "
       "(\\[vc-dir-hide-up-to-date]) Hide up-to-date"
-      "\n\n")))
+      "\n"
+      (vc-call-backend backend 'dir-extra-hints)
+      "\n")))
    (propertize "VC backend : " 'face 'vc-dir-header)
    (propertize (format "%s\n" backend) 'face 'vc-dir-header-value)
    (propertize "Working dir: " 'face 'vc-dir-header)
@@ -1968,7 +1972,7 @@ These are the commands available for use in the file status buffer:
       (vc-dir-refresh)
     ;; FIXME: find a better way to pass the backend to `vc-dir-mode'.
     (let ((use-vc-backend backend))
-      (vc-dir-mode)
+      (vc-call-backend backend 'dir-mode)
       ;; Activate the backend-specific minor mode, if any.
       (when-let* ((minor-mode
                    (intern-soft (format "vc-dir-%s-mode"
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index ef957b7010a..bbc87bb0a19 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -190,7 +190,7 @@
 ;;
 ;;   To provide more backend specific functionality for `vc-dir'
 ;;   the following functions might be needed: `dir-extra-headers',
-;;   `dir-printer', and `extra-dir-menu'.
+;;   `dir-extra-hints', `dir-mode', `dir-printer', and `extra-dir-menu'.
 ;;
 ;;   NOTE: project.el includes a similar method `project-list-files'
 ;;   that has a slightly different return value and performance
@@ -203,6 +203,17 @@
 ;;
 ;;   Return a string that will be added to the *vc-dir* buffer header.
 ;;
+;; - dir-extra-hints ()
+;;
+;;   Return a string of additional key bindings hints for the *vc-dir*
+;;   buffer header, or nil.
+;;
+;; - dir-mode ()
+;;
+;;   Mode to use for the *vc-dir* buffer.  This defaults to
+;;   `vc-dir-mode' and is expected to be changed (if at all) to a
+;;   derived mode of `vc-dir-mode'.
+;;
 ;; - dir-printer (fileinfo)
 ;;
 ;;   Pretty print the `vc-dir-fileinfo' FILEINFO.
@@ -5632,6 +5643,12 @@ to provide the `find-revision' operation instead."
   (funcall update-function
            (mapcar (lambda (file) (list file 'up-to-date)) files)))
 
+(declare-function vc-dir-mode "vc-dir")
+
+(defun vc-default-dir-mode (_backend) (vc-dir-mode))
+
+(defalias 'vc-default-dir-extra-hints #'ignore)
+
 (defun vc-check-headers ()
   "Check if the current file has any headers in it."
   (interactive)