Skip to content

Commit

Permalink
transient--key-face: Take key into account
Browse files Browse the repository at this point in the history
[1: fe71a7e] only did so when determining the transient behavior.
This commit takes care of also properly visualizing that behavior.

- Take an additional KEY argument and pass it along to
  `transient--get-pre-command'.  The previous commit [2: db9603be]
  added that argument to that function.

- No longer prefer the command's `transient-face' symbol property,
  which we did since the very first implementation of this feature,
  added in [3: 248862c].  Overriding the automatically determined
  face is counterproductive as it would counter binding-specific
  changes to the transient behavior and inapt predicate.  We don't
  actually do this for any commands, so in practice this did not
  matter.

- No longer define an around method, the primary method handles it
  all.  It already did that before this commit.

1: 2024-12-15 fe71a7e
   Account for duplicated commands with different transient behavior

2: 2024-12-16 db9603bef9afc23b7c6df2483cf2295cd3ff34ab
   transient--get-pre-command: Change argument order

3: 2020-06-21 248862c
   Add experimental support for semantic coloring
  • Loading branch information
tarsius committed Dec 17, 2024
1 parent 54d116b commit a99dcda
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions lisp/transient.el
Original file line number Diff line number Diff line change
Expand Up @@ -4009,7 +4009,8 @@ have a history of their own.")
(propertize "\n" 'face face 'line-height t))))

(defun transient--prefix-color ()
(or (face-foreground (transient--key-face nil 'non-suffix) nil t) "#gray60"))
(or (face-foreground (transient--key-face nil nil 'non-suffix) nil t)
"#gray60"))

(defmacro transient-with-shadowed-buffer (&rest body)
"While in the transient buffer, temporarily make the shadowed buffer current."
Expand Down Expand Up @@ -4161,13 +4162,6 @@ as a button."
(cl-defgeneric transient-format-key (obj)
"Format OBJ's `key' for display and return the result.")

(cl-defmethod transient-format-key :around ((obj transient-suffix))
"Add `transient-inapt-suffix' face if suffix is inapt."
(let ((str (cl-call-next-method)))
(if (oref obj inapt)
(transient--add-face str 'transient-inapt-suffix)
str)))

(cl-defmethod transient-format-key ((obj transient-suffix))
"Format OBJ's `key' for display and return the result."
(let ((key (if (slot-boundp obj 'key) (oref obj key) ""))
Expand Down Expand Up @@ -4200,16 +4194,16 @@ as a button."
(setq suf (string-replace " " "" suf)))
(concat (propertize pre 'face 'transient-unreachable-key)
(and (string-prefix-p (concat pre " ") key) " ")
(propertize suf 'face (transient--key-face cmd))
(propertize suf 'face (transient--key-face cmd key))
(save-excursion
(and (string-match " +\\'" key)
(propertize (match-string 0 key)
'face 'fixed-pitch))))))
((transient--lookup-key transient-sticky-map (kbd key))
(propertize key 'face (transient--key-face cmd)))
(propertize key 'face (transient--key-face cmd key)))
(t
(propertize key 'face 'transient-unreachable-key))))
(propertize key 'face (transient--key-face cmd)))))
(propertize key 'face (transient--key-face cmd key)))))

(cl-defmethod transient-format-key :around ((obj transient-argument))
"Handle `transient-highlight-mismatched-keys'."
Expand Down Expand Up @@ -4358,13 +4352,12 @@ apply the face `transient-unreachable' to the complete string."
(add-face-text-property (or beg 0) (or end (length str)) face append str)
str))

(defun transient--key-face (&optional cmd enforce-type)
(defun transient--key-face (cmd key &optional enforce-type)
(or (and transient-semantic-coloring
(not transient--helpp)
(not transient--editp)
(or (and cmd (get cmd 'transient-face))
(get (transient--get-pre-command cmd nil enforce-type)
'transient-face)))
(get (transient--get-pre-command cmd key enforce-type)
'transient-face))
(if cmd 'transient-key 'transient-key-noop)))

(defun transient--key-unreachable-p (obj)
Expand Down

0 comments on commit a99dcda

Please sign in to comment.