0

In Emacs 26 I had this working macro:

(defmacro with-temp-highlights (&rest body)
  "It executes BODY, undoing, upon completion, all the highlighters
used, but leaving pre-existing highlighters unchanged."
  (declare (indent 0))
  `(unwind-protect
       (let ((font-lock-keywords font-lock-keywords)
             (hi-lock-interactive-patterns hi-lock-interactive-patterns))
         ,@body)

     ;; *DUMMY HIGHLIGHT*
     ;; I need it to re-apply the highlights stored in the
     ;; `font-lock-keywords` and `hi-lock-interactive-patterns`
     ;; variables
     (highlight-regexp "MY DUMMY REGEXP")
     (unhighlight-regexp "MY DUMMY REGEXP")))

(defun test-temp-highlights ()
  (interactive)
  (with-temp-highlights 
    (highlight-regexp "foo")
    (read-string "[ENTER]: ")))

I used it to highlight "temporarily" some regexp without the need to use unhighlight-regexp to restore the buffer highlighting state.

Now I switched to Emacs 29.1 and the macro does not work appropriately. The first time I use the macro, the regexp/match is first highlighted and then unhighlighted, but from the next time I use it, the match is not highlighted at all.

hi-lock-mode is enabled.

Could this be fixed?

1 Answer 1

0

I changed my macro:

(defmacro with-temp-highlights (&rest body)
  "Ambito: HIGHLIGHTS
Descrizione: Esegue BODY annullando, al termine dell'esecuzione, tutti gli evidenziatori utilizzati, ma mantenendo inalterati gli evidenziatori preesistenti."
  (declare (indent 0))
  `(unwind-protect
       (let ((font-lock-keywords font-lock-keywords)
         (hi-lock-interactive-patterns hi-lock-interactive-patterns)
         (hi-lock-interactive-lighters hi-lock-interactive-lighters))
     ,@body
     )

     (font-lock-flush)))

I added a let-binding for the hi-lock-interactive-lighters variable.

It seems working fine.

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.