1

I want to highlight in multiple colors using highlight.el.

I'm trying to use:

(highlight-regexp regexp1)

followed by

hlt-next-face

But it seems to be consistently using the same face. How do I get highlight-regexp to use a different face. I'd prefer to not keep track faces myself, just get it to use a new one, which hlt-next-face claims to do.

1 Answer 1

1

highlight-regexp is not part of library Highlight (highlight.el). It's part of vanilla Emacs. Functions and variables defined by library highlight.el use prefix hlt-. Only library highlight.el lets you use hlt-next-face.

The main highlight.el command for highlighting regexp matches in the region (or the buffer) is hlt-highlight-regexp-region. Try that, instead of highlight-regexp.

Be aware too that vanilla command highlight-regexp works with hi-lock-mode, which means it works (only) with font-lock-mode turned on.

Features of library highlight.el can be used to highlight text whether or not font locking is on. To understand how to do this, see Interaction with Font Lock for using highlight.el with and without font-lock-mode being on.

4
  • Thanks, it seems like I need to specify a region. I'm using point-min and point-max for this (hlt-unhighlight-regexp-region (point-min) (point-max) 't) and (hlt-highlight-regexp-region (point-min) (point-max) "regexp") `
    – Att Righ
    Commented Dec 6, 2022 at 17:06
  • 1
    All of the args are optional. See function hlt-region-or-buffer-limits for how args START and END are defaulted.
    – Drew
    Commented Dec 6, 2022 at 18:21
  • Thanks. Presumably I need START and END if I want to specify the regular expression though?
    – Att Righ
    Commented Dec 7, 2022 at 12:42
  • 1
    Yes. But just use nil values for any such optional variables you want to have that default value.
    – Drew
    Commented Dec 7, 2022 at 17:18

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.