Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining new tooltips in Emacs

Tags:

emacs

I would like to add custom tooltips to emacs. More specifically, whenever I hover on a symbol (function/variable) name with my mouse of I would like to see a tooltip with the symbol's definition. I know that I can find this kind of info with a tool like cscope but I have no idea how to attach the output of cscope to a tooltip. does anyone have a partial (how to link a callback to a tooltip in emacs in general) or a full (how do I actually link the output of cscope to a tooltip) solution to this?

Thanks, Nir

like image 376
Nir Avatar asked Nov 16 '08 13:11

Nir


2 Answers

Your Emacs installation should include the Elisp reference manual (if not, download it now - you're going to need it when developing your mode). To access it, go to Info (C-h i) and look for a node labeled "Elisp", sometimes in a separate "Emacs" menu. Type i for index and tooltip to look for information on tooltips. You should find node 32.19.4 Properties with Special Meanings, which tells you that the content of the help-echo property is a string that is the tooltip content, or a function that can construct the tooltip dynamically. Explore the manual around that node to find out more about text properties and how to set them.

Here's a simple example:

(insert (propertize "foo\n" 'help-echo "Tooltip!"))

Type this into your *scratch* buffer and press C-j to run the code. Then point your mouse at the word "foo" and you should see the tooltip.

like image 58
Jouni K. Seppänen Avatar answered Nov 10 '22 22:11

Jouni K. Seppänen


There is an AutoOverlay package that can automatically add overlays, and tooltips associated with those overlays, based on a regex match of the buffer text.

like image 2
Cheeso Avatar answered Nov 10 '22 22:11

Cheeso