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

transient-prefix: Add display-action slot #332

Merged
merged 2 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
- ~transient-setup-buffer-hook~ is now run later to allow overriding
more default settings.

- The new prefix slots ~display-action~ and ~mode-line-format~, can be
used to override ~transient-display-buffer-action~ and
~transient-mode-line-format~ for individual prefix menus. #332

Bug fixes:

- Fixes some menu navigation edge-cases.
Expand Down
16 changes: 15 additions & 1 deletion docs/transient.org
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@ Also see [[* Common Suffix Commands]].
If you change the value of this option, then you might also
want to change the value of ~transient-mode-line-format~.

This user option may be overridden if ~:display-action~ is passed
when creating a new prefix with ~transient-define-prefix~.

*** Accessibility Options
:PROPERTIES:
:UNNUMBERED: notoc
Expand Down Expand Up @@ -560,6 +563,9 @@ Also see [[* Common Suffix Commands]].
~transient-key-exit~ (if allowed and they exit the transient) is
used to draw the line.

This user option may be overridden if ~:mode-line-format~ is passed
when creating a new prefix with ~transient-define-prefix~.

Otherwise this can be any mode-line format. See [[info:elisp#Mode
Line Format]], for details.

Expand Down Expand Up @@ -1951,6 +1957,12 @@ functions use ~describe-function~.
against a specific value, as returned by ~transient-infix-value~,
for example, ~--option=one~.

- ~display-action~ determines how this prefix is displayed, overriding
~transient-display-buffer-action~. It should have the same type.

- ~mode-line-format~ is this prefix's mode line format, overriding
~transient-mode-line-format~. It should have the same type.

- ~scope~ For some transients it might be necessary to have a sort of
secondary value, called a “scope”. See ~transient-define-prefix~.

Expand Down Expand Up @@ -2170,7 +2182,9 @@ See [[*Enabling and Disabling Suffixes]].
:UNNUMBERED: notoc
:END:

Yes, see ~transient-display-buffer-action~ in [[*Configuration]].
Yes, see ~transient-display-buffer-action~ in [[*Configuration]]. You can
also control how the popup buffer is displayed on a case-by-case basis
by passing ~:display-action~ to ~transient-define-prefix~.

** How can I copy text from the popup buffer?
:PROPERTIES:
Expand Down
18 changes: 17 additions & 1 deletion docs/transient.texi
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,9 @@ then that unfortunately changes which buffer is current.

If you change the value of this option, then you might also
want to change the value of @code{transient-mode-line-format}.

This user option may be overridden if @code{:display-action} is passed
when creating a new prefix with @code{transient-define-prefix}.
@end defopt

@anchor{Accessibility Options}
Expand Down Expand Up @@ -719,6 +722,9 @@ color of @code{transient-key-noop} (if non-suffixes are disallowed),
@code{transient-key-exit} (if allowed and they exit the transient) is
used to draw the line.

This user option may be overridden if @code{:mode-line-format} is passed
when creating a new prefix with @code{transient-define-prefix}.

Otherwise this can be any mode-line format. See @ref{Mode Line Format,,,elisp,}, for details.
@end defopt

Expand Down Expand Up @@ -2214,6 +2220,14 @@ options and @code{transient-switches} suffixes it is also possible to match
against a specific value, as returned by @code{transient-infix-value},
for example, @code{--option=one}.

@item
@code{display-action} determines how this prefix is displayed, overriding
@code{transient-display-buffer-action}. It should have the same type.

@item
@code{mode-line-format} is this prefix's mode line format, overriding
@code{transient-mode-line-format}. It should have the same type.

@item
@code{scope} For some transients it might be necessary to have a sort of
secondary value, called a ``scope''. See @code{transient-define-prefix}.
Expand Down Expand Up @@ -2489,7 +2503,9 @@ See @ref{Enabling and Disabling Suffixes}.
@anchor{Can I control how the popup buffer is displayed?}
@appendixsec Can I control how the popup buffer is displayed?

Yes, see @code{transient-display-buffer-action} in @ref{Configuration}.
Yes, see @code{transient-display-buffer-action} in @ref{Configuration}. You can
also control how the popup buffer is displayed on a case-by-case basis
by passing @code{:display-action} to @code{transient-define-prefix}.

@anchor{How can I copy text from the popup buffer?}
@appendixsec How can I copy text from the popup buffer?
Expand Down
33 changes: 21 additions & 12 deletions lisp/transient.el
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,8 @@ If `transient-save-history' is nil, then do nothing."
(environment :initarg :environment :initform nil)
(incompatible :initarg :incompatible :initform nil)
(suffix-description :initarg :suffix-description)
(display-action :initarg :display-action :initform nil)
(mode-line-format :initarg :mode-line-format)
(variable-pitch :initarg :variable-pitch :initform nil)
(column-widths :initarg :column-widths :initform nil)
(unwind-suffix :documentation "Internal use." :initform nil))
Expand Down Expand Up @@ -3895,10 +3897,8 @@ have a history of their own.")
(setq tab-line-format nil))
(setq header-line-format nil)
(setq mode-line-format
(if (or (natnump transient-mode-line-format)
(eq transient-mode-line-format 'line))
nil
transient-mode-line-format))
(let ((format (transient--mode-line-format)))
(if (or (natnump format) (eq format 'line)) nil format)))
(setq mode-line-buffer-identification
(symbol-name (oref transient--prefix command)))
(if transient-enable-popup-navigation
Expand All @@ -3913,12 +3913,9 @@ have a history of their own.")
(when-let ((line (transient--separator-line)))
(insert line)))
(unless (window-live-p transient--window)
(when (eq (car transient-display-buffer-action)
'display-buffer-full-frame)
(user-error "Invalid value for `transient-display-buffer-action'"))
(setq transient--window
(display-buffer transient--buffer
transient-display-buffer-action)))
(transient--display-action))))
(when (window-live-p transient--window)
(with-selected-window transient--window
(set-window-parameter nil 'prev--no-other-window
Expand All @@ -3929,6 +3926,13 @@ have a history of their own.")
(transient--goto-button focus))
(transient--fit-window-to-buffer transient--window)))))

(defun transient--display-action ()
(let ((action (or (oref transient--prefix display-action)
transient-display-buffer-action)))
(when (eq (car action) 'display-buffer-full-frame)
(user-error "Invalid value for `transient-display-buffer-action'"))
action))

(defun transient--fit-window-to-buffer (window)
(let ((window-resize-pixelwise t)
(window-size-fixed nil))
Expand All @@ -3942,11 +3946,16 @@ have a history of their own.")
(window-body-width window t)
(window-body-height window t))))

(defun transient--mode-line-format ()
(if (slot-boundp transient--prefix 'mode-line-format)
(oref transient--prefix mode-line-format)
transient-mode-line-format))

(defun transient--separator-line ()
(and-let* ((height (cond ((not window-system) nil)
((natnump transient-mode-line-format)
transient-mode-line-format)
((eq transient-mode-line-format 'line) 1)))
(and-let* ((format (transient--mode-line-format))
(height (cond ((not window-system) nil)
((natnump format) format)
((eq format 'line) 1)))
(face `(,@(and (>= emacs-major-version 27) '(:extend t))
:background
,(or (face-foreground (transient--key-face nil 'non-suffix)
Expand Down