4

font-lock-mode sets font lock for the entire buffer -- normally to provide syntax highlighting. Sometimes though, when I'm preparing a tutorial, I want to call attention out to certain lines. It would be great if I could underline them (M-o u with active region), but it has no effect with font-lock-mode.

How can I use or emulate M-o (facemenu-keymap) with font-lock-mode?

2
  • Either an overlay or text properties sounds ideal.
    – lawlist
    Commented Dec 8, 2014 at 20:24
  • the font-lock-face property is used as a face if and only if font-lock-mode is active. You'll have to write your own command to apply it.
    – Malabarba
    Commented Dec 8, 2014 at 20:43

1 Answer 1

5

Instead of the hack of using font-lock-face (which also means no highlighting unless font-lock is turned on), you can just use library Highlight (highlight.el).

It lets you highlight arbitrary text in many ways, using either text properties or overlays, and its highlighting is independent of font-lock highlighting. IOW, it gives you an easy way to keep font lock's hands off of your highlighting. You can even save such highlighting persistently, if you like.

2
  • +1 Just out of curiosity, how does that package manage to work regardless of font-lock-mode? Does it just decide between font-lock-face and face depending on the situation, or is there some other trick?
    – Malabarba
    Commented Dec 9, 2014 at 13:46
  • @Malabarba: It uses property font-lock-ignore to tell font-lock: "Hands off!". Font lock should never have been allowed to, in effect, "take over" all uses of property face. See this thread on [email protected], where I proposed adding this feature to Emacs.
    – Drew
    Commented Dec 9, 2014 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.