Skip to main content
2 of 4
added 332 characters in body
Drew
  • 79.1k
  • 10
  • 123
  • 257

Yes. Set variable isearch-filter-predicate to a function that returns nil for the text that you want to ignore for search and query-replace.

(Set it back to its default value of isearch-filter-visible when you're done. Alternatively, define your own search or query-replace function that binds the variable and then invokes regular Isearch or query-replace. That way it will be restored when your function is done.)

For example, you can put a text property my-ignore on some text, giving it a non-nil value. Then this function returns nil for what would normally be search hits on such text, so they are ignored for search and query-replace:

(defun skip-if-my-ignore (beg end)
  "Return nil iff some text BEG to END has non-`nil' property `my-ignore'."
  (catch 'skip-if-my-ignore
    (let ((pos  beg))
      (while (< pos end)
        (when (get-text-property pos 'my-ignore) (throw 'skip-if-my-ignore nil))
        (setq pos  (1+ pos))))
    t))

;; Make Isearch and query-replace ignore text with non-`nil' property `my-ignore'.
(setq isearch-filter-predicate  'skip-if-my-ignore)

But if you know how to identify the text you want to ignore, in order to put a text property on those parts, then you could just put that identification code into the filter predicate and not bother adding the text property. IOW, you can let the predicate check directly whether the text from BEG to END should be ignored.

Drew
  • 79.1k
  • 10
  • 123
  • 257