Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement more suffix classes, esp. for lisp variables/options #116

Open
tarsius opened this issue Apr 19, 2021 · 4 comments
Open

Implement more suffix classes, esp. for lisp variables/options #116

tarsius opened this issue Apr 19, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@tarsius
Copy link
Member

tarsius commented Apr 19, 2021

No description provided.

@vifon
Copy link

vifon commented Apr 25, 2021

A suffix class for minor-mode toggles with the current state indicator would be very welcome too.

@tarsius tarsius added the enhancement New feature or request label Sep 14, 2022
@tarsius
Copy link
Member Author

tarsius commented Oct 30, 2023

A suffix class for minor-mode toggles with the current state indicator would be very welcome too.

A simple implementation of that:

(defun demo-minor-mode-description (obj)
  (let* ((mode (oref obj command))
         (lighter (cadr (assq mode minor-mode-alist))))
    (when (and lighter (symbolp lighter))
      (setq lighter (symbol-value lighter)))
    (format
     ;; Personally I would just use the mode name, even if there is a lighter.
     ;; Other users might want to see the mode docstring instead/also.
     (if lighter "%s %s (%s)" "%s %s")
     (or lighter mode)
     (cond ((symbol-value mode)
            (format
             (propertize "[%s|%s]" 'face 'transient-delimiter)
             (propertize "on"  'face 'transient-value)
             (propertize "off" 'face 'transient-infix-value)))
           ((format
             (propertize "[%s|%s]" 'face 'transient-delimiter)
             (propertize "on"  'face 'transient-infix-value)
             (propertize "off" 'face '((:foreground "red") transient-value)))))
     mode)))

(transient-define-prefix demo ()
  :transient-suffix 'transient--do-stay
  [("a" outline-minor-mode :description demo-minor-mode-description)])

;; (demo)

It seems to me that the main complication is having to decide how to present the information. And that different users will have different opinions on what would be best, which makes it unappealing to add this to Transient itself.

One problem with the above is that one has to add :description demo-minor-mode-description explicitly for each mode command, but adding a class does not actually help:

(defclass transient-minor-mode-command (transient-suffix)
  ())

(cl-defmethod transient-format-description ((obj transient-minor-mode-command))
  (with-current-buffer transient--current-buffer
    ... as above...))

(transient-define-prefix demo ()
  :transient-suffix 'transient--do-stay
  ;; Hurray! We don't have to specify :description. Oh no! We have to specify :class.
  [("a" outline-minor-mode :class transient-minor-mode-command)])

@tarsius
Copy link
Member Author

tarsius commented Oct 30, 2023

An idea that might be worth considering, is adding a :suffix-class slot to transient-prefix:

(transient-define-prefix demo ()
  :transient-suffix 'transient--do-stay
  :suffix-class 'transient-minor-mode-command
  [("a" outline-minor-mode)
   ("b" another-minor-mode)])

Then again, we might want to generate the list of minor-mode suffixes, instead of hardcoding them, at which point having to specify the :class or :description slot for each suffix doesn't matter anymore.

I might something like this to my minions package eventually. It already dynamically generates a drop-down menu, and might as well support generating a transient menu too.

@tarsius
Copy link
Member Author

tarsius commented Oct 22, 2024

When tackling this issue, also consider whether adding something like transient-defvar would make sense, as suggested in #262.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants