0

When I evaluate (tooltip-show "test"), it is my expectation that the tooltip will appear right next to the current location of point. However, the tooltip instead appears in a seemingly random location far from point.

Why is this happening? Is there a way to make it appear next to point?

2
  • 2
    Did you read the docstring of the function? Do C-h f tooltip-show and note that it says "...Otherwise, the tooltip pops at offsets specified by 'tooltip-x-offset' and 'tooltip-y-offset' from the current mouse position" (emphasis added). That's because the function is not usually evaluated by hand - instead, it is called as a result of some mouse action, so it makes sens to keep the tool tip next to the mouse cursor. Commented Aug 2, 2024 at 19:09
  • that makes a lot of sense! In my mind I read "mouse" as "point" (as in, the location of point within the emacs buffer). So I guess something along the lines of my workaround is necessary if I want it positioned near "point", and not near the "mouse" position. Commented Aug 2, 2024 at 19:37

1 Answer 1

0

Here is a not great workaround:

(defun my:tooltip-by-point (msg)
   "requires fullscreen to position correctly"
   (interactive)
   (let ((left (car (window-absolute-pixel-position)))
         (top  (cdr (window-absolute-pixel-position))))
   (x-show-tip 
      msg
      (selected-frame)
      (append `((top  . ,(+ top  410))  ;; 410 found by trial and error
                (left . ,(- left 205)))
              tooltip-frame-parameters)
      tooltip-hide-delay
      nil nil))) ;; DX DY irrelevant due to PARMS containing `top` and `left`

It requires the "magic numbers" 410 and 205 to adjust for some sort of offset that is occurring. You may need to adjust these numbers.

2
  • (window-absolute-pixel-position) seems to be inconsistent across emacs sessions. maybe some other way of getting the position of point would be better Commented Aug 2, 2024 at 20:14
  • See Coordinates and Windows in the Emacs Lisp Ref manual. Commented Aug 3, 2024 at 3:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.