[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#1352: 23.0.60; isearch-success-function
From: |
Juri Linkov |
Subject: |
bug#1352: 23.0.60; isearch-success-function |
Date: |
Sun, 16 Nov 2008 23:16:17 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu) |
>> The name of `isearch-success-function' seems wrong, if we believe the
>> doc string. The doc string suggests that it is a predicate that
>> filters the search hits that would otherwise be available. That's very
>> general. If that's true, then the name should reflect this meaning -
>> perhaps `isearch-predicate'.
>
> Actually, based on your description, I'd name it `isearch-filter-predicate'.
The name `isearch-success-function' was created to be consistent
with other *-function variables and with `isearch-success',
but I agree that more clear names are better. So the patch below
renames it to `isearch-filter-predicate' and also renames
`isearch-success-function-default' to `isearch-filter-invisible',
plus renames in Dired and Info, and doc fixes:
Index: lisp/isearch.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/isearch.el,v
retrieving revision 1.335
diff -c -r1.335 isearch.el
*** lisp/isearch.el 11 Nov 2008 20:11:34 -0000 1.335
--- lisp/isearch.el 16 Nov 2008 21:07:27 -0000
***************
*** 176,186 ****
"Function to save a function restoring the mode-specific isearch state
to the search status stack.")
! (defvar isearch-success-function 'isearch-success-function-default
! "Function to report whether the new search match is considered successful.
! The function has two arguments: the positions of start and end of text
! matched by the search. If this function returns nil, continue
! searching without stopping at this match.")
;; Search ring.
--- 176,187 ----
"Function to save a function restoring the mode-specific isearch state
to the search status stack.")
! (defvar isearch-filter-predicate 'isearch-filter-invisible
! "Predicate that filters the search hits that would normally be available.
! Search hits that dissatisfy the predicate are skipped. The function
! has two arguments: the positions of start and end of text matched by
! the search. If this function returns nil, continue searching without
! stopping at this match.")
;; Search ring.
***************
*** 2257,2263 ****
(isearch-no-upper-case-p isearch-string isearch-regexp)))
(condition-case lossage
(let ((inhibit-point-motion-hooks
! (and (eq isearch-success-function
'isearch-success-function-default)
search-invisible))
(inhibit-quit nil)
(case-fold-search isearch-case-fold-search)
--- 2258,2264 ----
(isearch-no-upper-case-p isearch-string isearch-regexp)))
(condition-case lossage
(let ((inhibit-point-motion-hooks
! (and (eq isearch-filter-predicate 'isearch-filter-invisible)
search-invisible))
(inhibit-quit nil)
(case-fold-search isearch-case-fold-search)
***************
*** 2267,2278 ****
(while retry
(setq isearch-success
(isearch-search-string isearch-string nil t))
! ;; Clear RETRY unless we matched some invisible text
! ;; and we aren't supposed to do that.
(if (or (not isearch-success)
(bobp) (eobp)
(= (match-beginning 0) (match-end 0))
! (funcall isearch-success-function
(match-beginning 0) (match-end 0)))
(setq retry nil)))
(setq isearch-just-started nil)
--- 2268,2279 ----
(while retry
(setq isearch-success
(isearch-search-string isearch-string nil t))
! ;; Clear RETRY unless the search predicate says
! ;; to skip this search hit.
(if (or (not isearch-success)
(bobp) (eobp)
(= (match-beginning 0) (match-end 0))
! (funcall isearch-filter-predicate
(match-beginning 0) (match-end 0)))
(setq retry nil)))
(setq isearch-just-started nil)
***************
*** 2451,2460 ****
nil)
(setq isearch-hidden t)))))))
! (defun isearch-success-function-default (beg end)
! "Default function to report if the new search match is successful.
! Returns t if search can match hidden text, or otherwise checks if some
! text from BEG to END is visible."
(or (eq search-invisible t)
(not (isearch-range-invisible beg end))))
--- 2452,2461 ----
nil)
(setq isearch-hidden t)))))))
! (defun isearch-filter-invisible (beg end)
! "Default predicate to filter out invisible text.
! It filters search hits to those that are visible (at least partially),
! unless invisible text too can be searched."
(or (eq search-invisible t)
(not (isearch-range-invisible beg end))))
***************
*** 2640,2651 ****
(if isearch-lazy-highlight-wrapped
isearch-lazy-highlight-end
(window-start))))))
! ;; Use a loop like 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)
--- 2642,2655 ----
(if isearch-lazy-highlight-wrapped
isearch-lazy-highlight-end
(window-start))))))
! ;; Use a loop like in `isearch-search'.
(while retry
(setq success (isearch-search-string
isearch-lazy-highlight-last-string bound t))
+ ;; Clear RETRY unless the search predicate says
+ ;; to skip this search hit.
(if (or (not success)
! (funcall isearch-filter-predicate
(match-beginning 0) (match-end 0)))
(setq retry nil)))
success)
Index: lisp/dired-aux.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/dired-aux.el,v
retrieving revision 1.181
diff -c -r1.181 dired-aux.el
*** lisp/dired-aux.el 11 Nov 2008 20:12:44 -0000 1.181
--- lisp/dired-aux.el 16 Nov 2008 21:12:49 -0000
***************
*** 2303,2328 ****
:group 'dired
:version "23.1")
! (defvar dired-isearch-orig-success-function nil)
(defun dired-isearch-filenames-toggle ()
"Toggle file names searching on or off.
! When on, Isearch checks the success of the current matching point
! using the function `dired-isearch-success-function' that matches only
! at file names. When off, it uses the default function
! `isearch-success-function-default'."
(interactive)
! (setq isearch-success-function
! (if (eq isearch-success-function 'dired-isearch-success-function)
! 'isearch-success-function-default
! 'dired-isearch-success-function))
(setq isearch-success t isearch-adjusted t)
(isearch-update))
--- 2303,2328 ----
:group 'dired
:version "23.1")
! (defvar dired-isearch-filter-predicate-orig nil)
(defun dired-isearch-filenames-toggle ()
"Toggle file names searching on or off.
! When on, Isearch skips matches outside file names using the predicate
! `dired-isearch-filter-filenames' that matches only at file names.
! When off, it uses the default predicate `isearch-filter-invisible'."
(interactive)
! (setq isearch-filter-predicate
! (if (eq isearch-filter-predicate 'dired-isearch-filter-filenames)
! 'isearch-filter-invisible
! 'dired-isearch-filter-filenames))
(setq isearch-success t isearch-adjusted t)
(isearch-update))
***************
*** 2330,2351 ****
(defun dired-isearch-filenames-setup ()
"Set up isearch to search in Dired file names.
Intended to be added to `isearch-mode-hook'."
! (when dired-isearch-filenames
(define-key isearch-mode-map "\M-sf" 'dired-isearch-filenames-toggle)
! (setq dired-isearch-orig-success-function
! (default-value 'isearch-success-function))
! (setq-default isearch-success-function 'dired-isearch-success-function)
(add-hook 'isearch-mode-end-hook 'dired-isearch-filenames-end nil t)))
(defun dired-isearch-filenames-end ()
"Clean up the Dired file name search after terminating isearch."
(define-key isearch-mode-map "\M-sf" nil)
! (setq-default isearch-success-function dired-isearch-orig-success-function)
(remove-hook 'isearch-mode-end-hook 'dired-isearch-filenames-end t))
! (defun dired-isearch-success-function (beg end)
"Match only at visible regions with the text property `dired-filename'."
! (and (isearch-success-function-default beg end)
(if dired-isearch-filenames
(text-property-not-all (min beg end) (max beg end)
'dired-filename nil)
--- 2330,2355 ----
(defun dired-isearch-filenames-setup ()
"Set up isearch to search in Dired file names.
Intended to be added to `isearch-mode-hook'."
! (when (or (eq dired-isearch-filenames 'dired-filename)
(define-key isearch-mode-map "\M-sf" 'dired-isearch-filenames-toggle)
! (setq dired-isearch-filter-predicate-orig
! (default-value 'isearch-filter-predicate))
! (setq-default isearch-filter-predicate 'dired-isearch-filter-filenames)
(add-hook 'isearch-mode-end-hook 'dired-isearch-filenames-end nil t)))
(defun dired-isearch-filenames-end ()
"Clean up the Dired file name search after terminating isearch."
(define-key isearch-mode-map "\M-sf" nil)
! (setq-default isearch-filter-predicate dired-isearch-filter-predicate-orig)
(remove-hook 'isearch-mode-end-hook 'dired-isearch-filenames-end t))
! (defun dired-isearch-filter-filenames (beg end)
"Match only at visible regions with the text property `dired-filename'."
! (and (isearch-filter-invisible beg end)
(if dired-isearch-filenames
(text-property-not-all (min beg end) (max beg end)
'dired-filename nil)
Index: lisp/info.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/info.el,v
retrieving revision 1.551
diff -u -r1.551 info.el
--- lisp/info.el 20 Oct 2008 02:23:01 -0000 1.551
+++ lisp/info.el 16 Nov 2008 21:10:12 -0000
@@ -1660,7 +1660,7 @@
(point-max)))
(while (and (not give-up)
(or (null found)
- (not (funcall isearch-success-function beg-found
found))))
+ (not (funcall isearch-filter-predicate beg-found
found))))
(let ((search-spaces-regexp
(if (or (not isearch-mode) isearch-regexp)
Info-search-whitespace-regexp)))
@@ -1740,7 +1740,7 @@
(setq give-up nil found nil)
(while (and (not give-up)
(or (null found)
- (not (funcall isearch-success-function
beg-found found))))
+ (not (funcall isearch-filter-predicate
beg-found found))))
(let ((search-spaces-regexp
(if (or (not isearch-mode) isearch-regexp)
Info-search-whitespace-regexp)))
@@ -1847,7 +1847,7 @@
(defun Info-isearch-start ()
(setq Info-isearch-initial-node nil))
-(defun Info-search-success-function (beg-found found)
+(defun Info-isearch-filter-predicate (beg-found found)
"Skip invisible text, node header line and Tag Table node."
(save-match-data
(let ((backward (< found beg-found)))
@@ -3533,8 +3533,8 @@
'Info-isearch-wrap)
(set (make-local-variable 'isearch-push-state-function)
'Info-isearch-push-state)
- (set (make-local-variable 'isearch-success-function)
- 'Info-search-success-function)
+ (set (make-local-variable 'isearch-filter-predicate)
+ 'Info-isearch-filter-predicate)
(set (make-local-variable 'search-whitespace-regexp)
Info-search-whitespace-regexp)
(set (make-local-variable 'revert-buffer-function)
--
Juri Linkov
http://www.jurta.org/emacs/