From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: word search (Re: isearch in Dired) Date: Thu, 31 Jul 2008 15:35:59 +0300 Organization: JURTA Message-ID: <878wvicjtk.fsf@jurta.org> References: <874pjaiv45.fsf@gmail.com> <87lkclekep.fsf@jurta.org> <87r69k2vcw.fsf_-_@jurta.org> <87abg6ajlr.fsf@jurta.org> <48892105.7000504@gmail.com> <87abg0ohx6.fsf_-_@jurta.org> <87zlo0oba0.fsf@stupidchicken.com> <87myjz8ggy.fsf@jurta.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1217507934 4105 80.91.229.12 (31 Jul 2008 12:38:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 31 Jul 2008 12:38:54 +0000 (UTC) Cc: Stefan Monnier , emacs-devel@gnu.org To: Chong Yidong Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jul 31 14:39:43 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KOXRW-0000CU-6d for ged-emacs-devel@m.gmane.org; Thu, 31 Jul 2008 14:39:42 +0200 Original-Received: from localhost ([127.0.0.1]:48628 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KOXQb-0003Ak-Br for ged-emacs-devel@m.gmane.org; Thu, 31 Jul 2008 08:38:45 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KOXQW-0003AH-HF for emacs-devel@gnu.org; Thu, 31 Jul 2008 08:38:40 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KOXQV-00039y-T0 for emacs-devel@gnu.org; Thu, 31 Jul 2008 08:38:40 -0400 Original-Received: from [199.232.76.173] (port=44993 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KOXQV-00039v-NS for emacs-devel@gnu.org; Thu, 31 Jul 2008 08:38:39 -0400 Original-Received: from smtp-out.neti.ee ([194.126.126.37]:33278) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KOXQV-0000Ql-55 for emacs-devel@gnu.org; Thu, 31 Jul 2008 08:38:39 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by MXR-5.estpak.ee (Postfix) with ESMTP id E696B1DEF0C; Thu, 31 Jul 2008 15:38:37 +0300 (EEST) X-Virus-Scanned: Debian amavisd-new at estpak.ee Original-Received: from smtp-out.neti.ee ([127.0.0.1]) by localhost (MXR-5.estpak.ee [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pV9r+1Yzn9WA; Thu, 31 Jul 2008 15:38:34 +0300 (EEST) Original-Received: from Relayhost2.neti.ee (Relayhost2 [88.196.174.142]) by MXR-5.estpak.ee (Postfix) with ESMTP id 5FB341DE519; Thu, 31 Jul 2008 15:38:34 +0300 (EEST) Original-Received: from mail.estpak.ee (66.132.191.90.dyn.estpak.ee [90.191.132.66]) by Relayhost2.neti.ee (Postfix) with ESMTP id B93C31FB1DC; Thu, 31 Jul 2008 15:38:33 +0300 (EEST) In-Reply-To: <87myjz8ggy.fsf@jurta.org> (Juri Linkov's message of "Wed, 30 Jul 2008 19:50:33 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu) X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:101790 Archived-At: >> Looks OK to me. Please check it in ASAP, and don't forget to write a >> NEWS entry, and to document the keybinding in the docstring of >> `isearch'. > > Done. Actually incremental word search is useless. While typing a sequence of words, incremental word search advances forward through false positives and failures because it tries to match on all incomplete word boundaries. When the user finishes typing a complete sequence of words, the current match may skip some matches from the starting point. So this behavior makes more harm! What is necessary instead is reading a sequence of words in the minibuffer, starting Isearch on the entered words, and using C-s or C-r to find next or previous word occurrences. This is essentially what currently a clumsy trick `C-s M-e C-w' tries to do. But it is better to put this feature on `M-s w'. This was already discussed in March 2008, and Stefan agreed to this change but Richard worried about eliminating the C-w word-search feature. So I propose to display a warning after typing C-w in the isearch-edit-string minibuffer that this feature is obsolete and suggest using `M-s w' instead for the upcoming release. After this release, we can eliminate it completely or replace with word-yanking. The following patch does this, and also binds `M-s w' to a new command that starts Isearch with reading a sequence of words in the minibuffer. This feature is useful for regexp Isearch as well because often it is distracting to see warnings "incomplete input" while typing a complex regexp in Isearch mode. So it binds `M-s r' to a similar command that reads a regexp in the minibuffer and starts Isearch with it. This is the last patch I submit before the feature freeze, and I think it is important to install it now. Index: lisp/isearch.el =================================================================== RCS file: /sources/emacs/emacs/lisp/isearch.el,v retrieving revision 1.325 diff -c -r1.325 isearch.el *** lisp/isearch.el 30 Jul 2008 16:40:23 -0000 1.325 --- lisp/isearch.el 31 Jul 2008 12:35:35 -0000 *************** *** 509,514 **** --- 509,515 ---- (define-key map "\M-\t" 'isearch-complete-edit) (define-key map "\C-s" 'isearch-forward-exit-minibuffer) (define-key map "\C-r" 'isearch-reverse-exit-minibuffer) + (define-key map "\C-w" 'isearch-edit-string-set-word) (define-key map "\C-f" 'isearch-yank-char-in-minibuffer) (define-key map [right] 'isearch-yank-char-in-minibuffer) map) *************** *** 599,605 **** (define-key esc-map "\C-s" 'isearch-forward-regexp) (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) ;; Entry points to isearch-mode. --- 600,607 ---- (define-key esc-map "\C-s" 'isearch-forward-regexp) (define-key global-map "\C-r" 'isearch-backward) (define-key esc-map "\C-r" 'isearch-backward-regexp) ! (define-key search-map "r" 'isearch-edit-regexp-search) ! (define-key search-map "w" 'isearch-edit-word-search) ;; Entry points to isearch-mode. *************** *** 693,708 **** (interactive "P\np") (isearch-mode t (null not-regexp) nil (not no-recursive-edit))) - (defun isearch-forward-word (&optional not-word no-recursive-edit) - "\ - Do incremental search forward for a sequence of words. - With a prefix argument, do a regular string search instead. - Like ordinary incremental search except that your input - is treated as a sequence of words without regard to how the - words are separated. See \\[isearch-forward] for more info." - (interactive "P\np") - (isearch-mode t nil nil (not no-recursive-edit) (null not-word))) - (defun isearch-backward (&optional regexp-p no-recursive-edit) "\ Do incremental search backward. *************** *** 715,725 **** (interactive "P\np") (isearch-mode nil (null not-regexp) nil (not no-recursive-edit))) + (defun isearch-edit-regexp-search () + "Read regular expression and do incremental search on input. + It reads regular expression in the minibuffer, and after exiting minibuffer + with RET, C-s or C-r, Isearch starts incremental search with the entered + regular expression. See the command `isearch-forward' for more information." + (interactive) + (isearch-mode t t nil nil) + (isearch-edit-string)) + + (defun isearch-edit-word-search () + "Read sequence of words and do incremental search on input. + It reads words in the minibuffer, and after exiting minibuffer + with RET, C-s or C-r, Isearch starts incremental search with + entered words without regard to how the words are separated. + See the command `isearch-forward' for more information." + (interactive) + (isearch-mode t nil nil nil t) + (isearch-edit-string)) + ;; isearch-mode only sets up incremental search for the minor mode. ;; All the work is done by the isearch-mode commands. *************** *** 1111,1141 **** ;; that can change their values. (setq old-point (point) old-other-end isearch-other-end) - (isearch-message) ;; for read-char (unwind-protect ! (let* (;; Why does following read-char echo? ! ;;(echo-keystrokes 0) ;; not needed with above message ! (e (let ((cursor-in-echo-area t)) ! (read-event))) ;; Binding minibuffer-history-symbol to nil is a work-around ;; for some incompatibility with gmhist. ! (minibuffer-history-symbol) ! (message-log-max nil)) ! ;; If the first character the user types when we prompt them ! ;; for a string is the yank-word character, then go into ! ;; word-search mode. Otherwise unread that character and ! ;; read a key the normal way. ! ;; Word search does not apply (yet) to regexp searches, ! ;; no check is made here. ! (message "%s" (isearch-message-prefix nil nil t)) ! (if (memq (lookup-key isearch-mode-map (vector e)) ! '(isearch-yank-word ! isearch-yank-word-or-char)) ! (setq isearch-word t;; so message-prefix is right ! isearch-new-word t) ! (cancel-kbd-macro-events) ! (isearch-unread e)) ! (setq cursor-in-echo-area nil) (setq isearch-new-string (read-from-minibuffer (isearch-message-prefix nil nil isearch-nonincremental) --- 1122,1132 ---- ;; that can change their values. (setq old-point (point) old-other-end isearch-other-end) (unwind-protect ! (let* ((message-log-max nil) ;; Binding minibuffer-history-symbol to nil is a work-around ;; for some incompatibility with gmhist. ! (minibuffer-history-symbol)) (setq isearch-new-string (read-from-minibuffer (isearch-message-prefix nil nil isearch-nonincremental) *************** *** 1209,1214 **** --- 1200,1214 ---- (isearch-abort) ;; outside of let to restore outside global values ))) + ;; Obsolete usage of `C-s M-e C-w'. Remove after 23.1. + (defvar isearch-new-word) + (defun isearch-edit-string-set-word () + "Do word search after exiting `isearch-edit-string'." + (interactive) + (message "This feature is obsolete since 23.1; use `M-s w' instead.") + (setq isearch-word t isearch-new-word t)) + + (defun isearch-nonincremental-exit-minibuffer () (interactive) (setq isearch-nonincremental t) -- Juri Linkov http://www.jurta.org/emacs/