Emacs Lisp: Overlay Highlighting
Here's example of using overlay mechanism to highlight text.
(defun xah-make-overlay-bold-region (*begin *end) "make the region bold, using overlay. Version 2016-11-01" (interactive "r") (progn (overlay-put (make-overlay *begin *end) 'face 'bold) (setq mark-active nil ))) (defun xah-remove-overlays-region (*begin *end) "Remove overlays. Version 2016-11-01" (interactive "r") (remove-overlays *begin *end))
Emacs has 2 mechanisms for coloring:
- text property: a region of text can have a property list, and this properly list specifies the color, font, size, etc.
- text overlay: create an “overlay” object, and this overlay can be placed on a region of text. You can think of it as a covering layer.
Vast majority of coloring in emacs are done with text properties. This is faster, and suitable for lots of coloring, such as syntax coloring of a programing language. When text are copied by user or in elisp, the text properties come with it by default. Font Lock mode stores coloring info in text properties, and vast majority of programing language modes use font lock mode to color text.
〔►see Emacs Lisp: Text Properties〕
Overlay is useful for smaller number of coloring, or on and off coloring, such as temporary highlight of words.
Writing Major Mode Topics
- How to Write a Emacs Major Mode for Syntax Coloring
- Emacs Lisp: html6-mode
- Emacs Lisp: Font Lock Mode Basics
- Emacs Lisp: How to Define Face
- Emacs Lisp: How to Color Comment in Major Mode
- Emacs Lisp: How to Write Comment Command in Major Mode
- Emacs Lisp: How to Write Your Own Comment Command from Scratch
- Emacs Lisp: How to Write Keyword Completion Command
- Emacs Lisp: How to Create Keymap for Major Mode
- Emacs Lisp: Create Abbrev and Templates for Major Mode
- Emacs Lisp: Text Properties
- Emacs Lisp: Overlay Highlighting
- Emacs: Lookup Google, Dictionary, Documentation
- Emacs Lisp: How to Name Your Major Mode
- Emacs Lisp: What's “feature”?
- Emacs Lisp: require, load, load-file, autoload, feature, Explained