0

Run in *scratch*:

(progn (fundamental-mode) (hi-lock-mode 1) (highlight-regexp "." 'hi-pink))

Result:

Screenshot showing all current text highlighted

If I add text it is not highlighted depending on where I add it:

Screenshot with some text not highlighted

How can I make all newly added text be highlighted?

Note that it is OK for me to use something other than hi-lock-mode, as long as I can quickly toggle highlighting / the face of all characters.

I am using: GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30) of 2018-07-05

  • 1
    I'm trying to understand the use case here. Do you just want to highlight all text or just text added within a certain time from now? – stsquad Feb 25 at 14:37
  • Depending on what you want: 1. C-mouse-2 and pick a face will make inserted text use that face. 2. See the Emacs manual, node Enriched Text. – Drew Feb 25 at 15:25
4

The problem is that you're trying it out in fundamental-mode. As explained in the docstring of hi-lock-mode:

[...] In buffers where Font Lock mode is
disabled, patterns are applied using overlays; in this case, the
highlighting will not be updated as you type.

so in order for the matching to be done as you type, you need to be using font-lock in that buffer and that is disabled in fundamental-mode.

  • Thanks for finding that out! Indeed I forgot to mention that with the default lisp-interaction-mode in *scratch*, the issue does not appear. Only now I wonder why enabling font-lock-mode in fundamental-mode (which I want) still doesn't resolve the issue: (progn (fundamental-mode) (font-lock-mode) (hi-lock-mode 1) (highlight-regexp "." 'hi-pink)) – feklee Feb 26 at 10:01
  • 1
    @feklee: font-lock-mode doesn't really turn on in buffers that aren't setup explicitly for this (usually by the major mode) :-( – Stefan Feb 26 at 13:44
  • Thanks for pointing that out, and the solution is hacky. – feklee Feb 26 at 14:02
0

Is M-x highlight-changes-mode what you are looking for? While it is enabled all newly added/changed text will be highlighted with the highlight-changes face.

  • Interesting mode, but in this case I want all characters be highlighted equally, and I want it to be possible to toggle highlighting on and off. It's actually for hiding passwords using the Xecret font. Changing the face for the entire buffer could be an option, and I decided against that, but I forgot why. – feklee Feb 26 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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