unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: "Lennart Borgman \(gmail\)" <lennart.borgman@gmail.com>
Cc: Stefan Monnier <monnier@IRO.UMontreal.CA>, emacs-devel@gnu.org
Subject: Re: word search (Re: isearch in Dired)
Date: Tue, 29 Jul 2008 18:44:17 +0300	[thread overview]
Message-ID: <87abg0ohx6.fsf_-_@jurta.org> (raw)
In-Reply-To: <48892105.7000504@gmail.com> (Lennart Borgman's message of "Fri,  25 Jul 2008 02:40:37 +0200")

>> As for 3-state regexp/word toggles, I currently have no idea for a
>> good key: "r" means "regexp" and "w" means "word", but I don't see
>> what a key would be common for them.
>
> r - regular expression search
> w - word search
> s - search

When you want to switch to the regexp search then the most natural key
is "r".  When you want to switch to the word search then the most natural
key is "w".  Currently I see no alternative common key whose mnemonics
would be obvious.  So to toggle to the regexp or word search and back
to the non-regexp non-word search could be done using either of two keys
`M-s r' or `M-s w'.  It seems there is no problem with this.  In this
case, the following patch looks like a satisfactory solution.  It also
binds `M-s w' globally to start word isearch.

Index: lisp/isearch.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/isearch.el,v
retrieving revision 1.324
diff -c -r1.324 isearch.el
*** lisp/isearch.el	27 Jul 2008 18:24:30 -0000	1.324
--- lisp/isearch.el	29 Jul 2008 15:43:27 -0000
***************
*** 491,496 ****
--- 491,499 ----
      (define-key map "\M-r" 'isearch-toggle-regexp)
      (define-key map "\M-e" 'isearch-edit-string)
  
+     (define-key map "\M-sr" 'isearch-toggle-regexp)
+     (define-key map "\M-sw" 'isearch-toggle-word)
+ 
      (define-key map [?\M-%] 'isearch-query-replace)
      (define-key map [?\C-\M-%] 'isearch-query-replace-regexp)
      (define-key map "\M-so" 'isearch-occur)
***************
*** 596,601 ****
--- 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.
  
***************
*** 684,689 ****
--- 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.
***************
*** 1303,1308 ****
--- 1322,1334 ----
    (setq isearch-success t isearch-adjusted t)
    (isearch-update))
  
+ (defun isearch-toggle-word ()
+   "Toggle word searching on or off."
+   (interactive)
+   (setq isearch-word (not isearch-word))
+   (setq isearch-success t isearch-adjusted t)
+   (isearch-update))
+ 
  (defun isearch-toggle-case-fold ()
    "Toggle case folding in searching on or off."
    (interactive)

-- 
Juri Linkov
http://www.jurta.org/emacs/




  reply	other threads:[~2008-07-29 15:44 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-08  3:05 propose: dired-isearch.el --- isearch in Dired William Xu
2007-08-08  3:47 ` Levin
2007-08-08  5:29   ` William Xu
2007-08-08  8:12     ` Herbert Euler
2007-08-08  8:16 ` Miles Bader
2007-08-08  9:35   ` William Xu
2007-08-08 13:01   ` Stefan Monnier
2007-08-09  2:45     ` Miles Bader
2007-08-08 18:46 ` Stefan Monnier
2007-08-08 22:54   ` Juri Linkov
2008-07-23 20:34     ` Juri Linkov
2008-07-24  6:41       ` Mathias Dahl
2008-07-25  0:32         ` Juri Linkov
2008-07-24 13:53       ` Stefan Monnier
2008-07-24 15:52         ` Drew Adams
2008-07-24 17:20           ` Stefan Monnier
2008-07-24 17:31             ` dired-details status [was: isearch in Dired] Drew Adams
2008-07-25  0:33         ` isearch in Dired Juri Linkov
2008-07-25  0:40           ` Lennart Borgman (gmail)
2008-07-29 15:44             ` Juri Linkov [this message]
2008-07-29 17:22               ` word search (Re: isearch in Dired) Chong Yidong
2008-07-30 16:50                 ` Juri Linkov
2008-07-31 12:35                   ` Juri Linkov
2008-07-31 14:10                     ` Stefan Monnier
2008-07-31 15:16                       ` Juri Linkov
2008-07-31 16:30                         ` Stefan Monnier
2008-07-31 15:24                       ` Stefan Monnier
2008-07-29 15:45           ` isearch in Dired Juri Linkov
2008-07-29 17:56             ` Stefan Monnier
2008-07-30 14:29               ` Juri Linkov
2007-08-09  2:46   ` propose: dired-isearch.el --- " William Xu
2007-08-09  0:06 ` Richard Stallman
2007-08-09  1:53   ` William Xu
2007-08-09 23:11     ` Richard Stallman
2007-08-10  1:42       ` William Xu
2007-08-10  8:37         ` Mathias Dahl
2007-08-10  9:22           ` David Kastrup
2007-08-10 15:56           ` Drew Adams
2007-08-11 10:52             ` William Xu
2007-08-11 15:15               ` Drew Adams
2007-08-11 16:58               ` Robert J. Chassell
2007-08-12  1:02                 ` Drew Adams
2007-08-12 20:46               ` Juri Linkov
2007-08-12 21:43                 ` Drew Adams
2007-08-12 23:23                   ` Juri Linkov
2007-08-13  9:14                     ` Mathias Megyei
2007-08-13  9:24                       ` Andreas Schwab
2007-08-13 13:09                         ` Mathias Dahl
2007-08-09 16:07   ` Drew Adams
2007-08-09  2:37 ` Herbert Euler

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87abg0ohx6.fsf_-_@jurta.org \
    --to=juri@jurta.org \
    --cc=emacs-devel@gnu.org \
    --cc=lennart.borgman@gmail.com \
    --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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).