[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
18 Mar 2014 10:05:37 GMT
> could someone please shed a light on the purpose of overlays? I`m
> wondering under what circumstances they are used, or need to be used.
> Are they a feature that has been obsoleted by font-lock, or are they
> still needed?
Well, one difference with regard to font lock is that overlays do not
depend on the textual content of the buffer. Font lock is used for
highlighting parts of the buffer that match certain regexes (optionally
in specific contexts). Overlays are Lisp objects that are attached to
specific positions in the buffer, regardless of the text in those
positions. Because of that you can use them for things that you couldn't
use font lock for.
A simple example: in a program of mine, I use an overlay to navigate a
list of (BibTeX) keys. See the screenshots here:
The selected key ("Booij2009" in the first screenshot) is highlighted
using an overlay. Since the key can be anything, there isn't really a
regexp you can come up with that highlights one single entry. Also,
overlays can be moved around the buffer by assigning new buffer
positions to them. That makes it easy to use them for navigating the
list of keys. And overlays can be made temporarily invisible, something
I use in the lower of the two buffers (where the fields of the current
entry are shown): it has an overlay as well, to highlight the current
field, but it's only visible when focus is in the buffer (i.e., when the
user is editing the fields).
All of that would be nigh impossible with font lock.
> The background is that I`ve made an extension to hi-lock.el, and hi-lock
> features alternatively using overlays or font-lock. My extension does
> not support overlays, and I`m wondering if support for overlays needs to
> be added or not.
That of course is another question. Overlays certainly do have their
uses, they're not obsoleted by font lock. But whether those uses are
relevant for you is something you'll have to decide.
Joost Kremers address@hidden
Selbst in die Unterwelt dringt durch Spalten Licht
- overlays?, lee, 2014/03/17
- Re: overlays?,
Joost Kremers <=