dired-do-search does not use isearch-face

165 Views Asked by At

How can one have dired-do-search use the more visible isearch-face, or at least highlight the entire token found?

A blinking cursor would be an alternative, if it weren't so distracting while editing.

Restatement

If I run isearch-forward on the string "hello", that string is highlighted during the search, as you see in the image below.

image1

If I am instead in dired(-x) mode, mark the file, as shown in the next figure,

image2

then run dired-do-search on the string "hello", the string is found, but it is not highlighted, as you see below.

image3

How can I make dired-do-search use the same face as isearch-forward? In this example it is easy to spot the cursor, but on a larger display with heavy use of font-lock, and after opting for a milder, non-obtrusive face for the cursor, it is rather difficult to spot the location of the search string.

Update

Is the answer below the briefest way to solve this problem?

1

There are 1 best solutions below

4
On

Perhaps you're looking for dired-do-isearch or dired-do-isearch-regexp

If you want the same feel of dired-do-search, it looks like you could also make a defun that invokes tags-loop-continue with custom tags-loop-operate and tags-loop-scan operations.

Here's what I came up with:

(defvar dired-do-search-overlay nil)
(defvar dired-do-search-region nil)
(defun dired-do-search (regexp)
  "Search through all marked files for a match for REGEXP.
Stops when a match is found.
To continue searching for next match, use command \\[tags-loop-continue]."
  (interactive "sSearch marked files (regexp): ")
  (setq 
   tags-loop-operate `(progn 
            (if dired-do-search-overlay
                (delete-overlay dired-do-search-overlay))
            (setq dired-do-search-overlay 
                  (make-overlay (car dired-do-search-region)
                        (cadr dired-do-search-region)))
            (overlay-put dired-do-search-overlay
                     'face isearch-face)
            (overlay-put dired-do-search-overlay
                     'priority 1001)    
            nil)
   tags-loop-scan `(progn
             (if (re-search-forward ',regexp nil t)
             (setq dired-do-search-region 
                   (list (match-beginning 0)
                     (match-end 0)))
               (if dired-do-search-overlay 
               (delete-overlay dired-do-search-overlay))
               nil)))
  (tags-loop-continue 
   (or '(dired-get-marked-files nil nil 'dired-nondirectory-p) t)))