Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlighting text/regions from an elisp script

Tags:

emacs

elisp

I'm currently working on a special macro to help me edit LaTeX code. In it the macro identify up to four regions, then ask for user input, and acts upon these regions.

At the time where I ask for user input, I'd like the macro to highlight the four regions, preferably using two different colors (the regions come in two distinct categories) such that the user know what the macro have identified (better safe than sorry)

Any pointers towards good tutorials on how to do this?

like image 738
daleif Avatar asked Feb 13 '12 11:02

daleif


1 Answers

See Elisp Manual 38.9 Overlays. For example,

(let ((x (make-overlay start end)))
  (overlay-put x 'face '(:background "grey20")))

where the two points start and end define the region you wish to highlight.

Another possibility is using text-properties; but that may interfere with font-lock-mode which also uses them, so usually the former is more straightforward.

like image 137
huaiyuan Avatar answered Sep 29 '22 07:09

huaiyuan