Skip to content

Commit

Permalink
Improve tooltip on minibuffer candidates
Browse files Browse the repository at this point in the history
This change not only introduces Emacs 29 \`KEYSEQ' highlighting, but
also makes the tooltip more customizable.  Previously, mouse-1 and
mouse-3 were hard-coded in the help-echo string, whereas they now
appear together with the summary of their default binding.

* ivy.el (ivy-mouse-1-help, ivy-mouse-3-help): New variables
replacing (and obsoleting) ivy-mouse-1-tooltip and
ivy-mouse-3-tooltip, respectively.
(ivy--help-echo): New help-echo function.
(ivy--format-minibuffer-line): Use it in place of a help-echo form.
  • Loading branch information
basil-conto committed Jan 14, 2024
1 parent 7590ea6 commit 6509f63
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions ivy.el
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,27 @@ candidate, not the prompt."
"Display alternative actions."
"The doc visible in the tooltip for mouse-3 binding in the minibuffer.")

(make-obsolete-variable 'ivy-mouse-1-tooltip 'ivy-mouse-1-help
"0.15.0 (2024-01-14)")
(make-obsolete-variable 'ivy-mouse-3-tooltip 'ivy-mouse-3-help
"0.15.0 (2024-01-14)")

(defvar ivy-mouse-1-help
(eval-when-compile
(format (if (> emacs-major-version 28) "\\`%s': %s" "%s: %s")
"mouse-1" "Exit the minibuffer with the selected candidate"))
"Tooltip doc for \\`mouse-1' binding in the minibuffer.")

(defvar ivy-mouse-3-help
(eval-when-compile
(format (if (> emacs-major-version 28) "\\`%s': %s" "%s: %s")
"mouse-3" "Display alternative actions"))
"Tooltip doc for \\`mouse-3' binding in the minibuffer.")

(defun ivy--help-echo (_win _obj _pos)
"Return a `help-echo' string for mouse bindings on minibuffer candidates."
(concat ivy-mouse-1-help (if tooltip-mode "\n" " ") ivy-mouse-3-help))

(defun ivy-mouse-offset (event)
"Compute the offset between the candidate at point and the selected one."
(if event
Expand Down Expand Up @@ -4133,17 +4154,10 @@ in this case."
(funcall ivy--highlight-function str))
str))
(olen (length str)))
(add-text-properties
0 olen
'(mouse-face
ivy-minibuffer-match-highlight
help-echo
(format
(if tooltip-mode
"mouse-1: %s\nmouse-3: %s"
"mouse-1: %s mouse-3: %s")
ivy-mouse-1-tooltip ivy-mouse-3-tooltip))
str)
(add-text-properties 0 olen
'( mouse-face ivy-minibuffer-match-highlight
help-echo ivy--help-echo)
str)
(when annot
(setq str (concat str (funcall annot str)))
(add-face-text-property
Expand Down

0 comments on commit 6509f63

Please sign in to comment.