Tuesday, March 1, 2011

defining new tooltips in emacs

Hello, 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

From stackoverflow
  • 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.

    sverrejoh : Can you explain the advantages/disadvantages in using text properties instead of overlays?
  • 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.

0 comments:

Post a Comment