emacs-devel
[Top][All Lists]
Advanced

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

Re: word search (Re: isearch in Dired)


From: Juri Linkov
Subject: Re: word search (Re: isearch in Dired)
Date: Thu, 31 Jul 2008 15:35:59 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu)

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




reply via email to

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