all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-pretest-bug@gnu.org, 1352@emacsbugs.donarmstrong.com
Subject: bug#1352: 23.0.60; isearch-success-function
Date: Sun, 16 Nov 2008 23:16:17 +0200	[thread overview]
Message-ID: <87fxlrid7i.fsf@jurta.org> (raw)
In-Reply-To: <jwvskpseasv.fsf-monnier+emacsbugreports@gnu.org> (Stefan Monnier's message of "Sat, 15 Nov 2008 20:10:46 -0500")

>> 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/






  parent reply	other threads:[~2008-11-16 21:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87tza7kwmt.fsf@jurta.org>
2008-11-15 23:39 ` bug#1352: 23.0.60; isearch-success-function Drew Adams
2008-11-16  1:10   ` Stefan Monnier
2008-11-16  1:22     ` Drew Adams
2008-11-16 21:16     ` Juri Linkov [this message]
2008-11-16 23:07       ` Stefan Monnier
2008-11-17  0:45       ` Drew Adams
2008-12-20 21:45         ` Juri Linkov
2008-12-20 22:33           ` Drew Adams
2008-12-22  1:23             ` Juri Linkov
2008-12-22  1:57               ` Drew Adams
2008-12-22 12:32               ` Stefan Monnier
2008-11-17  0:55   ` bug#1352: marked as done (23.0.60; isearch-success-function) Emacs bug Tracking System

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fxlrid7i.fsf@jurta.org \
    --to=juri@jurta.org \
    --cc=1352@emacsbugs.donarmstrong.com \
    --cc=emacs-pretest-bug@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.