emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Lazy Isearch in dired


From: Juri Linkov
Subject: Lazy Isearch in dired
Date: Sat, 08 Nov 2008 23:57:34 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu)

There is a bug in Isearch in dired.  When Isearch is narrowed to only
file names, Lazy Isearch highlights matches outside of the Isearch scope.
This is very confusing since C-s and C-r will never visit them.

The following patch fixes this by using a loop like the loop in the
function `isearch-search'.  The docstring of isearch-lazy-highlight-search
says: "Attempt to do the search exactly the way the pending isearch would.",
so no changes in the docstring are needed, because this patch makes it
more similar to the main search function.  It also calls 
isearch-success-function
to skip the matches outside the current Isearch scope.  By default this
function skips invisible matches that are useless for lazy highlighting.
This also requires setting search-invisible to nil to not match
invisible text.

Index: lisp/isearch.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/isearch.el,v
retrieving revision 1.331
diff -c -r1.331 isearch.el
*** lisp/isearch.el     19 Oct 2008 22:33:17 -0000      1.331
--- lisp/isearch.el     8 Nov 2008 21:55:38 -0000
***************
*** 2598,2620 ****
  (defun isearch-lazy-highlight-search ()
    "Search ahead for the next or previous match, for lazy highlighting.
  Attempt to do the search exactly the way the pending isearch would."
!   (let ((case-fold-search isearch-lazy-highlight-case-fold-search)
!       (isearch-regexp isearch-lazy-highlight-regexp)
!       (search-spaces-regexp isearch-lazy-highlight-space-regexp))
!     (condition-case nil
!       (isearch-search-string
!                isearch-lazy-highlight-last-string
!                (if isearch-forward
!                    (min (or isearch-lazy-highlight-end-limit (point-max))
                          (if isearch-lazy-highlight-wrapped
!                             isearch-lazy-highlight-start
!                           (window-end)))
!                  (max (or isearch-lazy-highlight-start-limit (point-min))
!                       (if isearch-lazy-highlight-wrapped
!                           isearch-lazy-highlight-end
!                         (window-start))))
!                t)
!       (error nil))))
  
  (defun isearch-lazy-highlight-update ()
    "Update highlighting of other matches for current search."
--- 2608,2639 ----
  (defun isearch-lazy-highlight-search ()
    "Search ahead for the next or previous match, for lazy highlighting.
  Attempt to do the search exactly the way the pending isearch would."
!   (condition-case nil
!       (let ((case-fold-search isearch-lazy-highlight-case-fold-search)
!           (isearch-regexp isearch-lazy-highlight-regexp)
!           (search-spaces-regexp isearch-lazy-highlight-space-regexp)
!           (search-invisible nil)      ; don't match invisible text
!           (retry t)
!           (success nil)
!           (bound (if isearch-forward
!                      (min (or isearch-lazy-highlight-end-limit (point-max))
!                           (if isearch-lazy-highlight-wrapped
!                               isearch-lazy-highlight-start
!                             (window-end)))
!                    (max (or isearch-lazy-highlight-start-limit (point-min))
                          (if isearch-lazy-highlight-wrapped
!                             isearch-lazy-highlight-end
!                           (window-start))))))
!       ;; Use a loop similar to the loop in `isearch-search'
!       (while retry
!         (setq success (isearch-search-string
!                        isearch-lazy-highlight-last-string bound t))
!         (if (or (not success)
!                 (funcall isearch-success-function
!                          (match-beginning 0) (match-end 0)))
!             (setq retry nil)))
!       success)
!     (error nil)))
  
  (defun isearch-lazy-highlight-update ()
    "Update highlighting of other matches for current search."

-- 
Juri Linkov
http://www.jurta.org/emacs/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]