(defvar isearch-overlay nil)
+(defsubst isearch-set-lazy-highlight-faces-at (pos face)
+ "Set the face property of isearch lazy highlight overlays at POS to FACE.
+If POS is nil, nothing is done."
+ (unless (null pos)
+ (dolist (ov (overlays-at pos))
+ (when (and (not (eq ov isearch-overlay))
+ (memq ov isearch-lazy-highlight-overlays)
+ (not (eq (overlay-get ov 'face) face)))
+ (overlay-put ov 'face face)))))
+
(defun isearch-highlight (beg end)
- (if (or (null search-highlight) (null (display-color-p)))
- nil
- (or isearch-overlay (setq isearch-overlay (make-overlay beg end)))
- (move-overlay isearch-overlay beg end (current-buffer))
- (overlay-put isearch-overlay 'face
- (if (facep 'isearch)
- 'isearch 'region))))
+ (unless (or (null search-highlight) (null (display-color-p)))
+ (cond (isearch-overlay
+ ;; Overlay already exists, just move it.
+
+ ;; Check to see if there are any lazy-isearch overlays at
+ ;; the same position with their face property suppressed
+ ;; (to avoid face clashes), and if so, give them their face
+ ;; back.
+ (isearch-set-lazy-highlight-faces-at (overlay-start isearch-overlay)
+ isearch-lazy-highlight-face)
+
+ (move-overlay isearch-overlay beg end (current-buffer)))
+
+ (t
+ ;; Overlay doesn't exist, create it.
+ (setq isearch-overlay (make-overlay beg end))
+ (overlay-put isearch-overlay 'face isearch)))
+
+ ;; Suppress the faces of any lazy-isearch overlays at the new position
+ (isearch-set-lazy-highlight-faces-at beg nil)))
(defun isearch-dehighlight (totally)
- (if isearch-overlay
- (delete-overlay isearch-overlay)))
+ (when isearch-overlay
+ ;; Check to see if there are any lazy-isearch overlays at the same
+ ;; position with their face property suppressed (to avoid face
+ ;; clashes), and if so, give them their face back.
+ (isearch-set-lazy-highlight-faces-at (overlay-start isearch-overlay)
+ isearch-lazy-highlight-face)
+ (delete-overlay isearch-overlay)))
+
;;; General utilities
:type 'number
:group 'isearch-lazy-highlight)
-(defcustom isearch-lazy-highlight-face 'secondary-selection
- "*Face to use for lazily highlighting all matches."
- :type 'face
- :group 'isearch-lazy-highlight)
+(defgroup isearch-faces nil
+ "Lazy highlighting feature for incremental search."
+ :version "21.1"
+ :group 'isearch)
+
+(defface isearch
+ '((t (:inherit region)))
+ "Face for highlighting matches."
+ :group 'isearch-faces)
+(defvar isearch 'isearch)
+
+(defface isearch-lazy-highlight-face
+ '((t (:inherit secondary-selection)))
+ "Face for lazy highlighting of matches."
+ :group 'isearch-faces)
+(defvar isearch-lazy-highlight-face 'isearch-lazy-highlight-face)
(defvar isearch-lazy-highlight-overlays nil)
(defvar isearch-lazy-highlight-wrapped nil)
isearch-lazy-highlight-start))
(let ((found (isearch-lazy-highlight-search))) ;do search
(if found
- ;; found the next match
- (let ((ov (make-overlay (match-beginning 0)
- (match-end 0))))
- (overlay-put ov 'face isearch-lazy-highlight-face)
- (overlay-put ov 'priority 0)
- (setq isearch-lazy-highlight-overlays
- (cons ov isearch-lazy-highlight-overlays))
- (setq isearch-lazy-highlight-timer
- (run-at-time isearch-lazy-highlight-interval nil
- 'isearch-lazy-highlight-update))
- (if isearch-forward
- (setq isearch-lazy-highlight-end (point))
- (setq isearch-lazy-highlight-start (point))))
+ ;; found the next match
+ (let ((ov (make-overlay (match-beginning 0)
+ (match-end 0))))
+ ;; If OV overlaps the current isearch overlay, suppress
+ ;; its face property; otherwise, we sometimes get odd
+ ;; looking face combinations.
+ (unless (memq isearch-overlay
+ (overlays-at (match-beginning 0)))
+ (overlay-put ov 'face isearch-lazy-highlight-face))
+
+ (overlay-put ov 'priority 0)
+
+ (push ov isearch-lazy-highlight-overlays)
+
+ (setq isearch-lazy-highlight-timer
+ (run-at-time isearch-lazy-highlight-interval nil
+ 'isearch-lazy-highlight-update))
+ (if isearch-forward
+ (setq isearch-lazy-highlight-end (point))
+ (setq isearch-lazy-highlight-start (point))))
+
;; found no next match
(when (not isearch-lazy-highlight-wrapped)
;; let's try wrapping around the end of the buffer