From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#11381: 23.3; isearch-search-and-update issue? Date: Sun, 20 May 2012 03:15:33 +0300 Organization: JURTA Message-ID: <87r4ufhfmi.fsf@mail.jurta.org> References: <4F9DC154.2000605@groveronline.com> <87ipgggtmw.fsf@mail.jurta.org> <878vhcc4nl.fsf@mail.jurta.org> <87vcjxdt5p.fsf@mail.jurta.org> <87vcjvwtxa.fsf@mail.jurta.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1337473962 6065 80.91.229.3 (20 May 2012 00:32:42 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 20 May 2012 00:32:42 +0000 (UTC) Cc: 11381@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun May 20 02:32:41 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SVu4f-0007sZ-0B for geb-bug-gnu-emacs@m.gmane.org; Sun, 20 May 2012 02:32:41 +0200 Original-Received: from localhost ([::1]:57586 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SVu4e-0004ku-GG for geb-bug-gnu-emacs@m.gmane.org; Sat, 19 May 2012 20:32:40 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:38839) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SVu4a-0004gc-Tk for bug-gnu-emacs@gnu.org; Sat, 19 May 2012 20:32:38 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SVu4X-0007dv-9N for bug-gnu-emacs@gnu.org; Sat, 19 May 2012 20:32:36 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:53537) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SVu4X-0007dr-6T for bug-gnu-emacs@gnu.org; Sat, 19 May 2012 20:32:33 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SVu50-0001T6-1F for bug-gnu-emacs@gnu.org; Sat, 19 May 2012 20:33:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 20 May 2012 00:33:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 11381 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 11381-submit@debbugs.gnu.org id=B11381.13374739575603 (code B ref 11381); Sun, 20 May 2012 00:33:01 +0000 Original-Received: (at 11381) by debbugs.gnu.org; 20 May 2012 00:32:37 +0000 Original-Received: from localhost ([127.0.0.1]:34849 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SVu4b-0001SK-8Z for submit@debbugs.gnu.org; Sat, 19 May 2012 20:32:37 -0400 Original-Received: from ps18281.dreamhost.com ([69.163.218.105]:48587 helo=ps18281.dreamhostps.com) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SVu4E-0001Rg-3y for 11381@debbugs.gnu.org; Sat, 19 May 2012 20:32:33 -0400 Original-Received: from localhost (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id 53F38451CA30; Sat, 19 May 2012 17:31:42 -0700 (PDT) In-Reply-To: <87vcjvwtxa.fsf@mail.jurta.org> (Juri Linkov's message of "Thu, 17 May 2012 03:08:33 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (x86_64-pc-linux-gnu) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:60231 Archived-At: > Regarding the addition of symbol search functions, I hesitate to > define 7 more functions for every search type. If now add > symbol-search-forward, symbol-search-backward, > symbol-search-forward-lax, symbol-search-backward-lax, > and two functions to activate the symbol search > isearch-forward-symbol, isearch-backward-symbol, > then later someone might ask to add a subword search type > with subword-search-forward, subword-search-backward, > subword-search-forward-lax, subword-search-backward-lax, > isearch-forward-subword, isearch-backward-subword, > and so on. This will grow isearch.el unnecessarily. > > When trying to achieve simplicity, all what is needed to define > for every regexp-based search type is just: > > 1. Define a string-to-regexp conversion function > (like `word-search-regexp'). > > 2. Define a key sequence to activate this search type. > > This is a minimal set of requirements to define a new regexp-based > search type. There are more limitations that affect the design of this feature: it would be desirable to reuse the existing search type variable `isearch-word' because it's used in too many places like: recording the search status in the `isearch-cmds' stack, lazy-highlighting, external custom search functions. And also the aim is to to reuse 4 existing functions word-search-{for,back}ward{-lax,} because they are used in `isearch-search-fun' and some other packages that override the default search function. So the minimal set of changes would be like in the following patch. It also allows adding more regexp-based search types with less changes due to `funcall'. === modified file 'lisp/isearch.el' --- lisp/isearch.el 2012-05-15 21:30:58 +0000 +++ lisp/isearch.el 2012-05-20 00:14:00 +0000 @@ -512,6 +512,7 @@ (defvar isearch-mode-map (define-key map "\M-sr" 'isearch-toggle-regexp) (define-key map "\M-sw" 'isearch-toggle-word) + (define-key map "\M-s_" 'isearch-toggle-symbol) (define-key map [?\M-%] 'isearch-query-replace) (define-key map [?\C-\M-%] 'isearch-query-replace-regexp) @@ -626,6 +627,7 @@ (define-key esc-map "\C-s" 'isearch-forw (define-key global-map "\C-r" 'isearch-backward) (define-key esc-map "\C-r" 'isearch-backward-regexp) (define-key search-map "w" 'isearch-forward-word) +(define-key search-map "_" 'isearch-forward-symbol) ;; Entry points to isearch-mode. @@ -732,6 +735,16 @@ (defun isearch-forward-word (&optional n (interactive "P\np") (isearch-mode t nil nil (not no-recursive-edit) (null not-word))) +(defun isearch-forward-symbol (&optional not-symbol no-recursive-edit) + "\ +Do incremental search forward for a symbol. +The prefix argument is currently unused. +Like ordinary incremental search except that your input is treated +as a symbol surrounded by symbol boundary constructs \\_< and \\_>. +See the command `isearch-forward' for more information." + (interactive "P\np") + (isearch-mode t nil nil (not no-recursive-edit) 'symbol-search-regexp)) + (defun isearch-backward (&optional regexp-p no-recursive-edit) "\ Do incremental search backward. @@ -1379,6 +1392,13 @@ (defun isearch-toggle-word () (setq isearch-success t isearch-adjusted t) (isearch-update)) +(defun isearch-toggle-symbol () + "Toggle symbol searching on or off." + (interactive) + (setq isearch-word (unless (eq isearch-word 'symbol-search-regexp) 'symbol-search-regexp)) + (setq isearch-success t isearch-adjusted t) + (isearch-update)) + (defun isearch-toggle-case-fold () "Toggle case folding in searching on or off." (interactive) @@ -1425,7 +1445,11 @@ (defun word-search-backward (string &opt of words in STRING to a regexp used to search words without regard to punctuation." (interactive "sWord search backward: ") - (re-search-backward (word-search-regexp string nil) bound noerror count)) + (re-search-backward + (if (functionp isearch-word) + (funcall isearch-word string nil) + (word-search-regexp string nil)) + bound noerror count)) (defun word-search-forward (string &optional bound noerror count) "Search forward from point for STRING, ignoring differences in punctuation. @@ -1440,7 +1464,11 @@ (defun word-search-forward (string &opti of words in STRING to a regexp used to search words without regard to punctuation." (interactive "sWord search: ") - (re-search-forward (word-search-regexp string nil) bound noerror count)) + (re-search-forward + (if (functionp isearch-word) + (funcall isearch-word string nil) + (word-search-regexp string nil)) + bound noerror count)) (defun word-search-backward-lax (string &optional bound noerror count) "Search backward from point for STRING, ignoring differences in punctuation. @@ -1459,7 +1487,11 @@ (defun word-search-backward-lax (string of words in STRING to a regexp used to search words without regard to punctuation." (interactive "sWord search backward: ") - (re-search-backward (word-search-regexp string t) bound noerror count)) + (re-search-backward + (if (functionp isearch-word) + (funcall isearch-word string t) + (word-search-regexp string t)) + bound noerror count)) (defun word-search-forward-lax (string &optional bound noerror count) "Search forward from point for STRING, ignoring differences in punctuation. @@ -1478,7 +1510,23 @@ (defun word-search-forward-lax (string & of words in STRING to a regexp used to search words without regard to punctuation." (interactive "sWord search: ") - (re-search-forward (word-search-regexp string t) bound noerror count)) + (re-search-forward + (if (functionp isearch-word) + (funcall isearch-word string t) + (word-search-regexp string t)) + bound noerror count)) + +;; Symbol search + +(defun symbol-search-regexp (string &optional lax) + "Return a regexp which matches STRING as a symbol. +Creates a regexp where STRING is surrounded by symbol delimiters \\_< and \\_>. +If LAX is non-nil, the end of the string need not match a symbol +boundary unless it ends in whitespace." + (concat + "\\_<" + (regexp-quote string) + (if (or (not lax) (string-match-p "\\W$" string)) "\\_>"))) (defun isearch-query-replace (&optional delimited regexp-flag) @@ -1546,6 +1594,8 @@ (defun isearch-occur (regexp &optional n (interactive (let* ((perform-collect (consp current-prefix-arg)) (regexp (cond + ((functionp isearch-word) + (funcall isearch-word isearch-string)) (isearch-word (word-search-regexp isearch-string)) (isearch-regexp isearch-string) (t (regexp-quote isearch-string))))) @@ -1763,6 +1813,8 @@ (defun isearch-search-and-update () (setq case-fold-search (isearch-no-upper-case-p isearch-string isearch-regexp))) (looking-at (cond + ((functionp isearch-word) + (funcall isearch-word isearch-string t)) (isearch-word (word-search-regexp isearch-string t)) (isearch-regexp isearch-string) (t (regexp-quote isearch-string))))) @@ -2348,7 +2400,9 @@ (defun isearch-message-prefix (&optional (< (point) isearch-opoint))) "over") (if isearch-wrapped "wrapped ") - (if isearch-word "word " "") + (if (eq isearch-word 'symbol-search-regexp) + "symbol " + (if isearch-word "word " "")) (if isearch-regexp "regexp " "") (if multi-isearch-next-buffer-current-function "multi " "") (or isearch-message-prefix-add "")