I need to write a macro, with-temp-highlight-regexps
, that evaluates BODY
and than restores the previous highlighted regexps (created with the highlight-regexp
function). I thought I could do it by let-binding the variable in which this kind of highlights are stored. I read the hi-lock.el
file but I'm not so skilled to find the info I need.
Any suggestion?
EDIT. I tried this approach following phils' suggestion:
(defun my-temp-highlights ()
(interactive)
(highlight-regexp "STRING 1")
(let ((hi-lock-interactive-patterns hi-lock-interactive-patterns))
(highlight-regexp "STRING 2")
(read-string "\"RETURN\" TO QUIT"))
)
Running this function should keep STRING 1
highlighted but the STRING 2
highlighting should turn off, keeping the highlight only until RETURN
. The strange behaviour (for me) of this function is that the STRING 2
highlight is non turned off when I run hi-lock-mode
.
(I know I coud use unhilight-regexp
but it is not what I'm searching for.)
EDIT 2. I also the following code to understand what happens:
(defun my-temp-highlights ()
(interactive)
(highlight-regexp "STRING 1")
(princ hi-lock-interactive-patterns)
(sit-for 5)
(let ((BACKUP_VAR hi-lock-interactive-patterns))
(highlight-regexp "STRING 2")
(princ hi-lock-interactive-patterns)
(sit-for 5)
(read-string "ENTER TO QUIT")
(setq hi-lock-interactive-patterns BACKUP_VAR))
(princ hi-lock-interactive-patterns)
(sit-for 5)
)
But I'm not able to figure out why the second regexp (STRING 2
) keeps to be highlighted when the hi-lock-interactive-patterns
value is restored. (And why hi-lock-mode turn off does NOT effect it's higlighting).