Define a group for reuse? #299
-
Is there a way to define a group so that it can be reused? For example, given the prefix definition below, can it be refactored so that the sub-groups are defined outside of it? (transient-define-prefix casual-calc-rounding-tmenu ()
"Casual rounding functions menu."
[["Rounding Functions"
("r" "Round" calc-round :transient t)
("f" "Floor" calc-floor :transient t)
("c" "Ceiling" calc-ceiling :transient t)
("t" "Truncate" calc-trunc :transient t)]
["Operators"
("+" "add" calc-plus :transient t)
("-" "sub" calc-minus :transient t)
("*" "mul" calc-times :transient t)
("/" "div" calc-divide :transient t)
("%" "mod" calc-mod :transient t)]]
[:class transient-row
(casual-lib-quit-one)
(casual-calc-algebraic-entry)
(casual-calc-pop)
(casual-calc-undo-suffix)
(casual-lib-quit-all)]) For example, if a hypothetical function (transient-define-group casual-calc-operators ()
["Operators"
("+" "add" calc-plus :transient t)
("-" "sub" calc-minus :transient t)
("*" "mul" calc-times :transient t)
("/" "div" calc-divide :transient t)
("%" "mod" calc-mod :transient t)])
(transient-define-group casual-calc-navigation ()
[:class transient-row
(casual-lib-quit-one)
(casual-calc-algebraic-entry)
(casual-calc-pop)
(casual-calc-undo-suffix)
(casual-lib-quit-all)])
(transient-define-prefix casual-calc-rounding-tmenu ()
"Casual rounding functions menu."
[["Rounding Functions"
("r" "Round" calc-round :transient t)
("f" "Floor" calc-floor :transient t)
("c" "Ceiling" calc-ceiling :transient t)
("t" "Truncate" calc-trunc :transient t)]
(casual-calc-operators)]
(casual-calc-navigation)) Asking for guidance in achieving this, either with existing Transient functions or perhaps by defining a new macro? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Use this: (defconst casual-calc-operators-group
["Operators"
("+" "add" calc-plus :transient t)
("-" "sub" calc-minus :transient t)
("*" "mul" calc-times :transient t)
("/" "div" calc-divide :transient t)
("%" "mod" calc-mod :transient t)])
(defconst casual-calc-navigation-group
[:class transient-row
(casual-lib-quit-one)
(casual-calc-algebraic-entry)
(casual-calc-pop)
(casual-calc-undo-suffix)
(casual-lib-quit-all)])
(transient-define-prefix casual-calc-rounding-tmenu ()
"Casual rounding functions menu."
[["Rounding Functions"
("r" "Round" calc-round :transient t)
("f" "Floor" calc-floor :transient t)
("c" "Ceiling" calc-ceiling :transient t)
("t" "Truncate" calc-trunc :transient t)]
casual-calc-operators-group]
[casual-calc-navigation-group]) It appears this isn't documented yet, but you can look at |
Beta Was this translation helpful? Give feedback.
-
Thanks much! This works out great. |
Beta Was this translation helpful? Give feedback.
-
I recommend you prevent that (in your personal configuration) using ;; Adaption of `emacsql-fix-vector-indentation' from `emacsql.el'.
(define-advice calculate-lisp-indent (:around (fn &optional parse-start)
fix-vector-indentation)
"Don't indent vectors in `emacs-lisp-mode' like lists."
(if (save-excursion
(beginning-of-line)
(let ((beg (point)))
(save-excursion
(beginning-of-defun)
(when-let ((outer-sexp (elt (parse-partial-sexp (point) beg) 1)))
(goto-char outer-sexp)
(looking-at "\\[")))))
(let ((lisp-indent-offset 1))
(funcall fn parse-start))
(funcall fn parse-start))) There is no "function position" in vectors, so it makes little sense to indent vectors as if they are function calls. |
Beta Was this translation helpful? Give feedback.
-
Apparently closing a discussion hides it. Re-opening for visibility. |
Beta Was this translation helpful? Give feedback.
-
Thank you Tarsius, came here looking for exactly this. |
Beta Was this translation helpful? Give feedback.
Use this: