2

When I use mouse-over on an Link (thanks to Tobias) it shows an Image and text. When I used display-local-help the image disappeared (perhaps due to lack of space in the message area). I want to start the mouse-over with any key. Therefore I need a function name.

enter image description here

Drew
  • 75,699
  • 9
  • 109
  • 225
user19931
  • 21
  • 2
  • If you have the answer then please consider accepting it. You can accept your own answer. That takes the question off the unanswered questions list. – Drew Dec 27 '18 at 03:59

2 Answers2

0

Not a real solution, but does do some of what you want:

  (defun my/show-tooltip ()
    (interactive)
    (let
        ((tooltip-frame-parameters '((left . 100) (top . 200)))
         (text (get-text-property (point) 'help-echo)))
      (if (stringp text) (tooltip-show text))))

What's missing to be a real solution:

  • the help-echo property is not necessarily a string, it can also be a function or any expression. I expect this to be easily solvable. See the description of the help-echo property in the elisp manual.

  • I don't know how to get graphic coordinates from a buffer position (need to put them as left and top in tooltip-frame-parameters).

  • I have no idea if a display property on the string is honored by tooltip-show.

JeanPierre
  • 7,323
  • 1
  • 18
  • 37
0

Many Thanks !! It works. I had used pos-tip-show. It also works with a button with tooltip-show. Here is the code for displaying a link with image and text. I simplified the example a bit so that it works without any additional functions. I wish you all a lot of fun! Andreas

 (defun display-local-help-als-tooltip (&optional arg)
  "Display of the tooltip with the keyboard instead of the mouse.
Template was display-local-help."
  (interactive "P")
  (let ((help (help-at-pt-kbd-string)))
    (if help
      (tooltip-show
        help )
      (if (not arg) (tooltip-show
        "No indication available at this point.") ))))

(defun wikipedia-tooltip (window object position)
  "Tooltip with image and text."
    (save-excursion
      (goto-char position)
       (let ((path (org-element-property :path (org-element-context)))(beg) (end) (text)(imgfile) (img) (s))
     ;;Here the image should be inserted dynamically.
     (setq imgfile (format "x:/Temp/milk.jpg")) ; path
     ;; The text is actually determined by a function.
     (setq text "Milk is very ...")
    (if (file-exists-p imgfile)
      ;; If a picture exists, show it with the text.
      (progn
      (setq img (create-image (expand-file-name imgfile)
                  'imagemagick nil :width 300))
      (concat (propertize " "
                  'display img) (format "\n%s" text)))
      ;; No picture available, then just show the text.
      text)
      )))

(defun wikipedia-link-face (path)
    '(:foreground "red" ))

(org-link-set-parameters "wikipedia"         
         :help-echo 'wikipedia-tooltip 
         :face 'wikipedia-link-face)
user19931
  • 21
  • 2