0

I've rebound some keys in god-mode so that S and R start a forward and backward incremental search and s and r repeat but never start incremental searches. This is the approximate division of labor between Vim's //? and n/N .

This has some behavior I like, namely that the previous incremental search query is available until I specifically replace it with a new one via S or R .

But, it leaves "stray highlighting" when I'm moving around via s and r. The stray highlighting seems to last indefinitely.

To reproduce the problem, run the .emacs file below, it will drop you into the scratch buffer with scratch-mode already activated.

  1. hit g < to navigate to the top of the buffer
  2. hit S + s + RET to start a forward incremental search. The cursor should now be immediately after This.
  3. hit s + s + s, then r + r + r moving forward three matches and then backward three matches.
  4. wait one second
  5. All of the s characters in the buffer are now highlighted with a greenish color behind them.

How do I clear the greenish color behind all the s characters without replacing the "current default isearch query"?

;; minimal init.el to represent problem.
(progn

      (defun isearch-repeat-forward-command ()
        (interactive)
        (isearch-repeat-forward))


      (defun isearch-repeat-backward-command ()
        (interactive)
        (isearch-repeat-backward))

      (package-initialize)
      (require 'god-mode)

      (god-mode-all)
      (global-set-key (kbd "s-g") #'god-mode-all)

      (define-key god-local-mode-map (kbd "i") #'god-local-mode)
      (define-key god-local-mode-map (kbd "s") #'isearch-repeat-forward-command)
      (define-key god-local-mode-map (kbd "r") #'isearch-repeat-backward-command)
      (define-key god-local-mode-map (kbd "S") #'isearch-forward-regexp)
      (define-key god-local-mode-map (kbd "R") #'isearch-backward-regexp)

      (identity 1))

1 Answer 1

3

Didn't bother to follow your recipe, but you should be able to use M-: (lazy-highlight-cleanup) to remove all such highlighting. You can use M-: (lazy-highlight-cleanup t) to force removal, if necessary.

You can put that code in a command, if you like, and bind that to a key in isearch-mode-map or wherever.


Just to be sure you're aware of it: In Isearch you can use M-p and M-n, repeating as needed, to retrieve a previously used search string. That's what I do, instead of using multiple keys to initiate vs resume search, such as you're doing.

And if you use Isearch+ then you can also use M-TAB, C-M-i, or C-M-TAB to choose a previous search string using completion. This makes it easy and quick to pick up a particular search string among many that you've used.

(Isearch+ also lets you use M-= l during Isearch to toggle option `lazy-highlight-cleanup.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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