2

Linux Mint 20.2

Emacs 27.1

package: highlight ver. 20210318.2248

I want to highlight specific region. So here my steps:

1. hlt-choose-default-face

enter image description here 2. Select region enter image description here

  1. M-x hlt-highlight

  2. And here result. enter image description here

Nice.

Now I kill the buffer C-x k

And again open the same file.

Here result enter image description here

As you can see the text Hello, how are you? is not highlighting.

The question is: Is it possible to restore highlighting after reopen file?

1 Answer 1

3

The answer is yes and no.

If you want highlighting that is automatically re-created in a regular way then you typically want to just use font-lock-keywords (font-lock-defaults, font-lock-add-keywords) for the mode you're interested in.

Or you can put code that does the highlighting using highlight.el in your init file (or some other file you load), to do the highlighting.

Apart from enriched-mode, highlighting is not saved with your file. Something - some code - needs to reestablish the highlighting after you reopen your file.

Anything you do interactively to highlight something is actually done by code. You can rerun such code in another session or after reopening a file. You just need to have created the code to use.

See this section of the highlight.el doc: Temporary or Permanent Highlighting.

To save highlighting permanently, do the following:

  1. M-x enriched-mode, to put your file buffer in minor mode ‘enriched-mode’. You see ‘Enriched’ in the mode line.

  2. Choose text-property highlighting, not overlay highlighting, by setting option hlt-use-overlays-flag to nil. To do this using Customize, choose menu item Highlight using text properties, not overlays.

  3. Choose the highlight face to use: M-x hlt-choose-default-face.

  4. Highlight in any way provided by library highlight.el. For example, use hlt-highlighter to drag-highlight as if using a marker pen.

  5. Save your file. Note that, although highlighting in enriched-text mode modifies the buffer, it does not appear modified to Emacs (check the beginning of the mode line), so if you make no other changes then using C-x C-s does not save your highlighting changes. To remedy this, just do something besides highlighting — e.g., add a space and delete it — so that C-x C-s saves to disk.

When you reopen your file later, it is automatically in enriched mode, and your highlighting shows. However, be aware that font-locking can interfere with enriched mode, so you might want to use it on files where you don’t use font-locking.

3
  • "enriched-mode" work for text file. After reopen text file the highlighting is restore. Nice.... but it not work for org mode file. Commented Sep 13, 2021 at 17:56
  • 1
    You can try reporting that as a bug or enhancement request: M-x report-emacs-bug. Org mode not working with Enriched mode presumably has nothing to do with library highight.el.
    – Drew
    Commented Sep 13, 2021 at 18:40
  • 1
    See this somewhat similar question. That person apparently was successful in using org-mode together with enriched-mode (persistent highlighting), since the OP accepted the answer there.
    – Drew
    Commented Sep 13, 2021 at 18:50

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.