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

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

[elpa] externals/transient 7502390bbd 190/366: transient-column{, s}: Op


From: Jonas Bernoulli
Subject: [elpa] externals/transient 7502390bbd 190/366: transient-column{, s}: Optionally pad keys
Date: Tue, 25 Jan 2022 18:54:40 -0500 (EST)

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

    transient-column{,s}: Optionally pad keys
---
 docs/transient.org  |  9 +++++++--
 docs/transient.texi | 11 +++++++++--
 lisp/transient.el   | 23 +++++++++++++++++++++--
 3 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/docs/transient.org b/docs/transient.org
index cf55360ff8..9af1ab2987 100644
--- a/docs/transient.org
+++ b/docs/transient.org
@@ -8,7 +8,7 @@
 #+TEXINFO_DIR_CATEGORY: Emacs
 #+TEXINFO_DIR_TITLE: Transient: (transient).
 #+TEXINFO_DIR_DESC: Transient Commands
-#+SUBTITLE: for version 0.2.0 (v0.2.0-37-gf2252d53+1)
+#+SUBTITLE: for version 0.2.0 (v0.2.0-38-ga3e53633+1)
 
 #+TEXINFO_DEFFN: t
 #+OPTIONS: H:4 num:4 toc:2
@@ -37,7 +37,7 @@ Calling a suffix command usually causes the transient to be 
exited
 but suffix commands can also be configured to not exit the transient.
 
 #+TEXINFO: @noindent
-This manual is for Transient version 0.2.0 (v0.2.0-37-gf2252d53+1).
+This manual is for Transient version 0.2.0 (v0.2.0-38-ga3e53633+1).
 
 #+BEGIN_QUOTE
 Copyright (C) 2018-2020 Jonas Bernoulli <jonas@bernoul.li>
@@ -840,6 +840,11 @@ constructor of that class.
   changes to the children including constructing new children from
   scratch.  Also see ~transient-setup-children~.
 
+- The constructors of ~transient-column~ and ~transient-columns~ accept an
+  additional keyword argument ~:pad-keys~.  If non-nil, then keys of all
+  contained suffixes are right padded, effectively aligning the
+  descriptions.
+
 The ELEMENTs are either all subgroups (vectors), or all suffixes
 (lists) and strings.  (At least currently no group type exists that
 would allow mixing subgroups with commands at the same level, though
diff --git a/docs/transient.texi b/docs/transient.texi
index 7eaecfdfe9..b1ba06a3b6 100644
--- a/docs/transient.texi
+++ b/docs/transient.texi
@@ -31,7 +31,7 @@ General Public License for more details.
 @finalout
 @titlepage
 @title Transient User and Developer Manual
-@subtitle for version 0.2.0 (v0.2.0-37-gf2252d53+1)
+@subtitle for version 0.2.0 (v0.2.0-38-ga3e53633+1)
 @author Jonas Bernoulli
 @page
 @vskip 0pt plus 1filll
@@ -65,7 +65,7 @@ Calling a suffix command usually causes the transient to be 
exited
 but suffix commands can also be configured to not exit the transient.
 
 @noindent
-This manual is for Transient version 0.2.0 (v0.2.0-37-gf2252d53+1).
+This manual is for Transient version 0.2.0 (v0.2.0-38-ga3e53633+1).
 
 @quotation
 Copyright (C) 2018-2020 Jonas Bernoulli <jonas@@bernoul.li>
@@ -1069,6 +1069,13 @@ The children are given as a, potentially empty, list 
consisting
 of either group or suffix specifications.  It can make arbitrary
 changes to the children including constructing new children from
 scratch.  Also see @code{transient-setup-children}.
+
+
+@item
+The constructors of @code{transient-column} and @code{transient-columns} 
accept an
+additional keyword argument @code{:pad-keys}.  If non-nil, then keys of all
+contained suffixes are right padded, effectively aligning the
+descriptions.
 @end itemize
 
 The ELEMENTs are either all subgroups (vectors), or all suffixes
diff --git a/lisp/transient.el b/lisp/transient.el
index 758a3daaf0..d7be4af4ac 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -697,13 +697,15 @@ They become the value of this this argument.")
   "Abstract superclass of all group classes."
   :abstract t)
 
-(defclass transient-column (transient-group) ()
+(defclass transient-column (transient-group)
+  ((pad-keys :initarg :pad-keys))
   "Group class that displays each element on a separate line.")
 
 (defclass transient-row (transient-group) ()
   "Group class that displays all elements on a single line.")
 
-(defclass transient-columns (transient-group) ()
+(defclass transient-columns (transient-group)
+  ((pad-keys :initarg :pad-keys))
   "Group class that displays elements organized in columns.
 Direct elements have to be groups whose elements have to be
 commands or string.  Each subgroup represents a column.  This
@@ -2793,6 +2795,7 @@ have a history of their own.")
   (insert ?\n))
 
 (cl-defmethod transient--insert-group ((group transient-column))
+  (transient--maybe-pad-keys group)
   (dolist (suffix (oref group suffixes))
     (let ((str (transient-format suffix)))
       (insert str)
@@ -2803,6 +2806,7 @@ have a history of their own.")
   (let* ((columns
           (mapcar
            (lambda (column)
+             (transient--maybe-pad-keys column group)
              (let ((rows (mapcar 'transient-format (oref column suffixes))))
                (when-let ((desc (transient-format-description column)))
                  (push desc rows))
@@ -3045,6 +3049,21 @@ If the OBJ's `key' is currently unreachable, then apply 
the face
   (let ((val (lookup-key keymap key)))
     (and val (not (integerp val)) val)))
 
+(defun transient--maybe-pad-keys (group &optional parent)
+  (when-let ((pad (if (slot-boundp group 'pad-keys)
+                      (oref group pad-keys)
+                    (and parent
+                         (slot-boundp parent 'pad-keys)
+                         (oref parent pad-keys)))))
+    (let ((width (apply #'max
+                        (cons (if (integerp pad) pad 0)
+                              (mapcar (lambda (suffix)
+                                        (length (oref suffix key)))
+                                      (oref group suffixes))))))
+      (dolist (suffix (oref group suffixes))
+        (oset suffix key
+              (truncate-string-to-width (oref suffix key) width nil ?\s))))))
+
 ;;; Help
 
 (cl-defgeneric transient-show-help (obj)



reply via email to

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