Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get emacs to keep my isearch strings highlighted?

Tags:

emacs

How can I get emacs to highlight the phrase I'm searching for and then keep it highlighted until I search for another phrase? Can it do this transparently i.e. just by searching, not having to run another command afterwards (like isearch-highlight-regexp) ?

like image 530
MDCore Avatar asked Sep 23 '10 15:09

MDCore


3 Answers

Try this:

(setq lazy-highlight-cleanup nil)

If you want to clear out the highlight manually, do M-x lazy-highlight-cleanup

like image 174
Trey Jackson Avatar answered Nov 14 '22 13:11

Trey Jackson


Trey's answer seems to work. I thought I'd include one using advice just for the sake of completeness:

(defadvice isearch-exit (after ysph-hl-search activate compile)
  "after isearch, highlight the search term "
  (highlight-regexp (car (if isearch-regexp
                             regexp-search-ring
                           search-ring)) (find-face 'hi-pink)))
like image 38
Joseph Gay Avatar answered Nov 14 '22 13:11

Joseph Gay


This variant combines lazy-highlight with regex highlighting once you're done with the search. This resembles the hlsearch behavior of vim in emacs.

(setq lazy-highlight t                 ; highlight occurrences
      lazy-highlight-cleanup nil       ; keep search term highlighted
      lazy-highlight-max-at-a-time nil ; all occurences in file
      isearch-allow-scroll t           ; continue the search even though we're scrolling
      )

;; when exiting isearch, register the search term as regexp-highlight
(defadvice isearch-done (after ysph-hl-search activate compile)
           "highlight the search term after isearch has quit"
           (unhighlight-regexp t)
           (highlight-regexp (car (if isearch-regexp
                                      regexp-search-ring
                                      search-ring)) 'lazy-highlight))
like image 24
TheJJ Avatar answered Nov 14 '22 11:11

TheJJ