Skip to content

Commit

Permalink
transient-prefix: Add mode-line-format slot
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmturner authored and tarsius committed Dec 1, 2024
1 parent e270654 commit e516683
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
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
6 changes: 6 additions & 0 deletions docs/transient.org
Original file line number Diff line number Diff line change
Expand Up @@ -563,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 @@ -1957,6 +1960,9 @@ functions use ~describe-function~.
- ~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
7 changes: 7 additions & 0 deletions docs/transient.texi
Original file line number Diff line number Diff line change
Expand Up @@ -722,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 @@ -2221,6 +2224,10 @@ for example, @code{--option=one}.
@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
20 changes: 12 additions & 8 deletions lisp/transient.el
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ If `transient-save-history' is nil, then do nothing."
(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 @@ -3896,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 Down Expand Up @@ -3947,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

0 comments on commit e516683

Please sign in to comment.