unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Adding a tooltip to text that matches a regexp?
@ 2014-11-20 18:29 Raffaele Ricciardi
  2014-11-21  7:38 ` Tassilo Horn
  0 siblings, 1 reply; 6+ messages in thread
From: Raffaele Ricciardi @ 2014-11-20 18:29 UTC (permalink / raw)
  To: help-gnu-emacs

I would like to add a tooltip to any text that matches a regexp.  The 
buffer content is going to change, thus I can't do it once for all. 
Since such text is going to be highlighted by Font Lock, it seems that 
adding the tooltip in `font-lock-add-keywords` could be a solution.  I 
know that I must set the `help-echo` property of the matching text, like 
this:

     (set-text-properties  (match-beginning 0) (match-end 0)
                           '(help-echo "Tooltip text"
                                       font-lock-face 'my-custom-face))

Can I do this in `font-lock-add-keywords`?  If so, how?  If not, are 
there alternative solutions?

Thank you.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Adding a tooltip to text that matches a regexp?
  2014-11-20 18:29 Adding a tooltip to text that matches a regexp? Raffaele Ricciardi
@ 2014-11-21  7:38 ` Tassilo Horn
  2014-11-21  8:30   ` Tassilo Horn
       [not found]   ` <mailman.14226.1416558662.1147.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 6+ messages in thread
From: Tassilo Horn @ 2014-11-21  7:38 UTC (permalink / raw)
  To: Raffaele Ricciardi; +Cc: help-gnu-emacs

Raffaele Ricciardi <rfflrccrd@gmail.com> writes:

Hi Raffaele,

>     (set-text-properties  (match-beginning 0) (match-end 0)
>                           '(help-echo "Tooltip text"
>                                       font-lock-face 'my-custom-face))
>
> Can I do this in `font-lock-add-keywords`?

Yes, you can.

> If so, how?

This adds a "Foo or Bar" tooltip to any occurences of the words foo or
bar in the current buffer.

  (font-lock-add-keywords nil
    '(("\\<\\(foo\\|bar\\)\\>" 1 '(face nil help-echo "Foo or Bar"))))

HTH,
Tassilo



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Adding a tooltip to text that matches a regexp?
  2014-11-21  7:38 ` Tassilo Horn
@ 2014-11-21  8:30   ` Tassilo Horn
       [not found]   ` <mailman.14226.1416558662.1147.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 6+ messages in thread
From: Tassilo Horn @ 2014-11-21  8:30 UTC (permalink / raw)
  To: Raffaele Ricciardi; +Cc: help-gnu-emacs

Tassilo Horn <tsdh@gnu.org> writes:

>>     (set-text-properties  (match-beginning 0) (match-end 0)
>>                           '(help-echo "Tooltip text"
>>                                       font-lock-face 'my-custom-face))
>>
>> Can I do this in `font-lock-add-keywords`?
>
> Yes, you can.
>
>> If so, how?
>
> This adds a "Foo or Bar" tooltip to any occurences of the words foo or
> bar in the current buffer.
>
>   (font-lock-add-keywords nil
>     '(("\\<\\(foo\\|bar\\)\\>" 1 '(face nil help-echo "Foo or Bar"))))

And I think you will want to add help-echo to
`font-lock-extra-managed-props'.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Adding a tooltip to text that matches a regexp?
       [not found]   ` <mailman.14226.1416558662.1147.help-gnu-emacs@gnu.org>
@ 2014-11-22 12:48     ` Raffaele Ricciardi
  2014-11-22 13:47       ` Tassilo Horn
  2014-11-22 14:34       ` Stefan Monnier
  0 siblings, 2 replies; 6+ messages in thread
From: Raffaele Ricciardi @ 2014-11-22 12:48 UTC (permalink / raw)
  To: help-gnu-emacs

On 21/11/14 09:30, Tassilo Horn wrote:
> Tassilo Horn <tsdh@gnu.org> writes:
>
>>>      (set-text-properties  (match-beginning 0) (match-end 0)
>>>                            '(help-echo "Tooltip text"
>>>                                        font-lock-face 'my-custom-face))
>>>
>>> Can I do this in `font-lock-add-keywords`?
>>
>> Yes, you can.
>>
>>> If so, how?
>>
>> This adds a "Foo or Bar" tooltip to any occurences of the words foo or
>> bar in the current buffer.
>>
>>    (font-lock-add-keywords nil
>>      '(("\\<\\(foo\\|bar\\)\\>" 1 '(face nil help-echo "Foo or Bar"))))
>
> And I think you will want to add help-echo to
> `font-lock-extra-managed-props'.
>
> Bye,
> Tassilo
>

Thank you.

Should I make `font-lock-extra-managed-props' buffer local?


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Adding a tooltip to text that matches a regexp?
  2014-11-22 12:48     ` Raffaele Ricciardi
@ 2014-11-22 13:47       ` Tassilo Horn
  2014-11-22 14:34       ` Stefan Monnier
  1 sibling, 0 replies; 6+ messages in thread
From: Tassilo Horn @ 2014-11-22 13:47 UTC (permalink / raw)
  To: Raffaele Ricciardi; +Cc: help-gnu-emacs

Raffaele Ricciardi <rfflrccrd@gmail.com> writes:

>>> This adds a "Foo or Bar" tooltip to any occurences of the words foo
>>> or bar in the current buffer.
>>>
>>>    (font-lock-add-keywords nil
>>>      '(("\\<\\(foo\\|bar\\)\\>" 1 '(face nil help-echo "Foo or Bar"))))
>>
>> And I think you will want to add help-echo to
>> `font-lock-extra-managed-props'.
>
> Thank you.
>
> Should I make `font-lock-extra-managed-props' buffer local?

I'd say yes.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Adding a tooltip to text that matches a regexp?
  2014-11-22 12:48     ` Raffaele Ricciardi
  2014-11-22 13:47       ` Tassilo Horn
@ 2014-11-22 14:34       ` Stefan Monnier
  1 sibling, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2014-11-22 14:34 UTC (permalink / raw)
  To: help-gnu-emacs

> Should I make `font-lock-extra-managed-props' buffer local?

To find the answer, it's usually better to ask the reverse:
"do I want this change to affect *all* buffers?"


        Stefan




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-11-22 14:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-20 18:29 Adding a tooltip to text that matches a regexp? Raffaele Ricciardi
2014-11-21  7:38 ` Tassilo Horn
2014-11-21  8:30   ` Tassilo Horn
     [not found]   ` <mailman.14226.1416558662.1147.help-gnu-emacs@gnu.org>
2014-11-22 12:48     ` Raffaele Ricciardi
2014-11-22 13:47       ` Tassilo Horn
2014-11-22 14:34       ` Stefan Monnier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).