emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/transient 52679f9853 22/23: transient-toggle-docstrings


From: Jonas Bernoulli
Subject: [elpa] externals/transient 52679f9853 22/23: transient-toggle-docstrings: New command
Date: Sun, 22 Dec 2024 08:44:41 -0500 (EST)

branch: externals/transient
commit 52679f9853fd56358dd57e9bfcd8ff6533400cf2
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>

    transient-toggle-docstrings: New command
---
 docs/transient.org  |  9 +++++++++
 docs/transient.texi |  9 +++++++++
 lisp/transient.el   | 25 ++++++++++++++++++++-----
 3 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/docs/transient.org b/docs/transient.org
index 907d268d3b..c62b12d260 100644
--- a/docs/transient.org
+++ b/docs/transient.org
@@ -436,6 +436,15 @@ like to use them for all menus, bind them in 
~transient-map~.
   This command copies the contents of the menu buffer to the kill
   ring.
 
+- Command: transient-toggle-docstrings ::
+
+  This command toggle between showing suffix descriptions in the menu
+  (as usual) or showing the first lines of the respective docstrings
+  in their place.  For commands that do not have a docstring, always
+  display the suffix description.  Because there likely isn't enough
+  room to display multiple docstrings side-by-side, a single column
+  is used when displaying docstrings.
+
 ** Configuration
 
 More options are described in [[* Common Suffix Commands]], in [[* Saving
diff --git a/docs/transient.texi b/docs/transient.texi
index 52259d1cc7..1ff4d6f92b 100644
--- a/docs/transient.texi
+++ b/docs/transient.texi
@@ -594,6 +594,15 @@ This command copies the contents of the menu buffer to the 
kill
 ring.
 @end deffn
 
+@deffn Command transient-toggle-docstrings
+This command toggle between showing suffix descriptions in the menu
+(as usual) or showing the first lines of the respective docstrings
+in their place.  For commands that do not have a docstring, always
+display the suffix description.  Because there likely isn't enough
+room to display multiple docstrings side-by-side, a single column
+is used when displaying docstrings.
+@end deffn
+
 @node Configuration
 @section Configuration
 
diff --git a/lisp/transient.el b/lisp/transient.el
index 45b5f2b04c..1147c144ae 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -1604,6 +1604,7 @@ That buffer is current and empty when this hook runs.")
 (defvar transient--exitp nil "Whether to exit the transient.")
 (defvar transient--showp nil "Whether to show the transient popup buffer.")
 (defvar transient--helpp nil "Whether help-mode is active.")
+(defvar transient--docsp nil "Whether docstring-mode is active.")
 (defvar transient--editp nil "Whether edit-mode is active.")
 
 (defvar transient--refreshp nil
@@ -1972,6 +1973,7 @@ of the corresponding object."
   "<transient-isearch-backward>"  #'transient--do-move
   "<transient-isearch-forward>"   #'transient--do-move
   "<transient-copy-menu-text>"    #'transient--do-stay
+  "<transient-toggle-docstrings>" #'transient--do-stay
   ;; If a valid but incomplete prefix sequence is followed by
   ;; an unbound key, then Emacs calls the `undefined' command
   ;; but does not set `this-command', `this-original-command'
@@ -3267,6 +3269,13 @@ transient is active."
   (interactive)
   (setq transient-show-common-commands (not transient-show-common-commands)))
 
+(transient-define-suffix transient-toggle-docstrings ()
+  "Toggle whether to show docstrings instead of suffix descriptions.
+To make this available in all menus, bind it in `transient-map'."
+  :transient t
+  (interactive)
+  (setq transient--docsp (not transient--docsp)))
+
 (defun transient-toggle-debug ()
   "Toggle debugging statements for transient commands."
   (interactive)
@@ -4100,7 +4109,7 @@ have a history of their own.")
           (insert ?\n))))))
 
 (cl-defmethod transient--insert-group ((group transient-columns))
-  (if transient-force-single-column
+  (if (or transient-force-single-column transient--docsp)
       (dolist (group (oref group suffixes))
         (transient--insert-group group t))
     (let* ((columns
@@ -4295,10 +4304,16 @@ face `transient-heading' to the complete string."
 If the result is nil, then use \"(BUG: no description)\" as the
 description.  If the OBJ's `key' is currently unreachable, then
 apply the face `transient-unreachable' to the complete string."
-  (let ((desc (or (cl-call-next-method obj)
-                  (and (slot-boundp transient--prefix 'suffix-description)
-                       (funcall (oref transient--prefix suffix-description)
-                                obj)))))
+  (let ((desc (if-let ((transient--docsp)
+                       (cmd (oref obj command))
+                       (doc (ignore-errors (documentation cmd)))
+                       ((not (equal doc (documentation
+                                         'transient--default-infix-command)))))
+                  (substring doc 0 (string-match "\\.?\n" doc))
+                (or (cl-call-next-method obj)
+                    (and (slot-boundp transient--prefix 'suffix-description)
+                         (funcall (oref transient--prefix suffix-description)
+                                  obj))))))
     (if desc
         (when-let ((face (transient--get-face obj 'face)))
           (setq desc (transient--add-face desc face t)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]