* does emacs support incremental searching for partial matches?
@ 2011-02-21 10:28 Leh CHAO
2011-02-22 14:21 ` Drew Adams
0 siblings, 1 reply; 10+ messages in thread
From: Leh CHAO @ 2011-02-21 10:28 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
I'm wondering if emacs has built-in support for incremental searching
for partial matches, such as searching for 'memcache' matches
'memorycache'. It would be really helpful to me when I'm working on
Visual C++ code because the programmers tend to use long variable
names.
Thanks!
eric
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: does emacs support incremental searching for partial matches?
2011-02-21 10:28 does emacs support incremental searching for partial matches? Leh CHAO
@ 2011-02-22 14:21 ` Drew Adams
2011-02-22 19:33 ` Leh CHAO
[not found] ` <mailman.2.1298403193.16069.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 10+ messages in thread
From: Drew Adams @ 2011-02-22 14:21 UTC (permalink / raw)
To: 'Leh CHAO', help-gnu-emacs
> I'm wondering if emacs has built-in support for incremental searching
> for partial matches, such as searching for 'memcache' matches
> 'memorycache'. It would be really helpful to me when I'm working on
> Visual C++ code because the programmers tend to use long variable
> names.
You can use regexp search: `C-M-s mem.*cache'.
See `C-h r g regexp search RET'.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: does emacs support incremental searching for partial matches?
2011-02-22 14:21 ` Drew Adams
@ 2011-02-22 19:33 ` Leh CHAO
2011-02-22 20:42 ` Drew Adams
[not found] ` <mailman.2.1298403193.16069.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 10+ messages in thread
From: Leh CHAO @ 2011-02-22 19:33 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs
Hi Drew, thank you for your help!
Sometimes I would be able to know the .* part, for example, I want to
match WindowsMemoryCacheManagement by using 'memcache'. With regular
expression, I have to specify .*m.*e.*m.*c.*a.*c.*h.*e.*
Is there any command or plugin I can use?
Thanks!
eric
On Tue, Feb 22, 2011 at 6:21 AM, Drew Adams <drew.adams@oracle.com> wrote:
>> I'm wondering if emacs has built-in support for incremental searching
>> for partial matches, such as searching for 'memcache' matches
>> 'memorycache'. It would be really helpful to me when I'm working on
>> Visual C++ code because the programmers tend to use long variable
>> names.
>
> You can use regexp search: `C-M-s mem.*cache'.
> See `C-h r g regexp search RET'.
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: does emacs support incremental searching for partial matches?
2011-02-22 19:33 ` Leh CHAO
@ 2011-02-22 20:42 ` Drew Adams
0 siblings, 0 replies; 10+ messages in thread
From: Drew Adams @ 2011-02-22 20:42 UTC (permalink / raw)
To: 'Leh CHAO'; +Cc: help-gnu-emacs
> >> I'm wondering if emacs has built-in support for
> >> incremental searching for partial matches, such as searching
> >> for 'memcache' matches 'memorycache'.
> >
> > You can use regexp search: `C-M-s mem.*cache'.
> > See `C-h r g regexp search RET'.
>
> Hi Drew, thank you for your help!
> Sometimes I would be able to know the .* part, for example, I want to
> match WindowsMemoryCacheManagement by using 'memcache'. With regular
> expression, I have to specify .*m.*e.*m.*c.*a.*c.*h.*e.*
I don't understand. Why would you have to specify that? You should be able to
match `WindowsMemoryCacheManagement' using just `C-M-s mem.*cache'. Or maybe
you meant that you do _not_ know where the possible skips are located?
> Is there any command or plugin I can use?
Do you mean something that lets you not need to include the `.*'?
I.e., to type only `memcache', not `mem.*cache'?
Again, IMHO it's not a big deal to type `.*'. But if that's what you're looking
for then yes, you can use Icicles search with scatter-match completion.
This kind of completion is the same as TextMate's file-name completion and Ido's
flex-match completion. It automatically inserts `.*' between every pair of
characters you type - nothing more. So you type only `memcache' and it thinks
`m.*e.*m.*c.*a.*c.*h.*e'.
In Icicles you can change the completion mode to scatter matching at any time by
hitting `M-(' in the minibuffer. `M-(' cycles the possible matching modes for
`S-TAB' completion: `apropos' (regexp), `scatter', `Levenshtein', `Levenshtein
strict', and `Jaro-Winkler'. (Apropos completion is the `S-TAB' default.)
Icicles search (an incremental search that uses completion):
http://www.emacswiki.org/emacs/Icicles_-_Search_Commands%2c_Overview
Scatter-match completion:
http://www.emacswiki.org/emacs/Icicles_-_Fuzzy_Completion
But I recommend that you just get used to using a regexp pattern, regardless of
the search tool you use. You won't regret it.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: does emacs support incremental searching for partial matches?
[not found] <mailman.10.1298381786.4429.help-gnu-emacs@gnu.org>
@ 2011-02-22 21:34 ` Tim X
0 siblings, 0 replies; 10+ messages in thread
From: Tim X @ 2011-02-22 21:34 UTC (permalink / raw)
To: help-gnu-emacs
Leh CHAO <lehchao@gmail.com> writes:
> Hi,
>
> I'm wondering if emacs has built-in support for incremental searching
> for partial matches, such as searching for 'memcache' matches
> 'memorycache'. It would be really helpful to me when I'm working on
> Visual C++ code because the programmers tend to use long variable
> names.
>
> Thanks!
>
> eric
>
Yes, you have regexp-search
,----[ C-h k CONTROL meta s ]
| CONTROL meta s runs the command isearch-forward-regexp, which is an
| interactive compiled Lisp function in `isearch.el'.
|
| It is bound to CONTROL meta s , <menu-bar> <edit> <search> <i-search>
| <isearch-forward-regexp> .
|
| (isearch-forward-regexp &optional NOT-REGEXP NO-RECURSIVE-EDIT)
|
| Do incremental search forward for regular expression.
| With a prefix argument, do a regular string search instead.
| Like ordinary incremental search except that your input is treated
| as a regexp. See the command `isearch-forward' for more information.
|
| In regexp incremental searches, a space or spaces normally matches
| any whitespace (the variable `search-whitespace-regexp' controls
| precisely what that means). If you want to search for a literal space
| and nothing else, enter C-q SPC.
|
| [back]
`----
However, from your description, it sounds like what you really want is
to use emacs' TAGS facility, which will help you find specific code
'tags'. Also look into imenu, speedbar and cedet. Emacs has a lot of
tools to support coding, particularly with languages like C/C++. Some of
the tools take a bit o effort to get configured the first time, but once
you have learnt them, they make things very productive/easy.
Tim
--
tcross (at) rapttech dot com dot au
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: does emacs support incremental searching for partial matches?
[not found] ` <mailman.2.1298403193.16069.help-gnu-emacs@gnu.org>
@ 2011-02-22 21:49 ` Tim X
2011-02-23 15:53 ` Stefan Monnier
1 sibling, 0 replies; 10+ messages in thread
From: Tim X @ 2011-02-22 21:49 UTC (permalink / raw)
To: help-gnu-emacs
Leh CHAO <lehchao@gmail.com> writes:
> Hi Drew, thank you for your help!
>
> Sometimes I would be able to know the .* part, for example, I want to
> match WindowsMemoryCacheManagement by using 'memcache'. With regular
> expression, I have to specify .*m.*e.*m.*c.*a.*c.*h.*e.*
>
You need to learn regexp. Have a look at M-x re-builder.
To match WindowsMemoryCacheManagement you don't need
.*m.*e.*m.*c.*a.*c.*h.*e.* at all. The pattern \w*mem\w*cache\w* would
find that string. Note also that emacs isearch (C-s) is an incremental
search in the sense that if you start by typeing 'mem' it will match all
words in the buffer with mem in them, typing the next character i.e. 'o'
will match all with memo etc. Using the regexp version means you can add
regexp patterns. So, in the above case, I would type memoryc or
mem\w*cache, which would match the string you want.
Tim
>
> Thanks!
>
> eric
>
> On Tue, Feb 22, 2011 at 6:21 AM, Drew Adams <drew.adams@oracle.com> wrote:
>>> I'm wondering if emacs has built-in support for incremental searching
>>> for partial matches, such as searching for 'memcache' matches
>>> 'memorycache'. It would be really helpful to me when I'm working on
>>> Visual C++ code because the programmers tend to use long variable
>>> names.
>>
>> You can use regexp search: `C-M-s mem.*cache'.
>> See `C-h r g regexp search RET'.
>>
>>
>
--
tcross (at) rapttech dot com dot au
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: does emacs support incremental searching for partial matches?
[not found] ` <mailman.2.1298403193.16069.help-gnu-emacs@gnu.org>
2011-02-22 21:49 ` Tim X
@ 2011-02-23 15:53 ` Stefan Monnier
2011-02-24 5:59 ` Le Wang
1 sibling, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2011-02-23 15:53 UTC (permalink / raw)
To: help-gnu-emacs
> Hi Drew, thank you for your help!
> Sometimes I would be able to know the .* part, for example, I want to
> match WindowsMemoryCacheManagement by using 'memcache'. With regular
> expression, I have to specify .*m.*e.*m.*c.*a.*c.*h.*e.*
> Is there any command or plugin I can use?
It shouldn't be too difficult to write up a quick hack to do it, using
isearch-search-fun-function. Something like
(defconst my-isearch-re "[^\n\s\t]*?")
(defun my-isearch-search-fun ()
(if isearch-forward
(lambda (text bound noerror)
(re-search-forward (mapconcat 'string text my-isearch-re)
bound noerror))
(lambda (text bound noerror)
(re-search-backward (mapconcat 'string text my-isearch-re)
bound noerror))))
(defun my-search-end ()
(kill-local-variable 'isearch-search-fun-function)
(remove-hook 'isearch-mode-end-hook #'my-search-end 'local))
(defun my-isearch ()
"Like isearch but lets you omit chars."
(interactive)
(add-hook 'isearch-mode-end-hook #'my-search-end nil 'local)
(set (make-local-variable 'isearch-search-fun-function)
#'my-isearch-search-fun)
(isearch-forward))
-- Stefan "who actually tested his code this time ;-)"
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: does emacs support incremental searching for partial matches?
2011-02-23 15:53 ` Stefan Monnier
@ 2011-02-24 5:59 ` Le Wang
2011-02-24 14:43 ` Stefan Monnier
[not found] ` <mailman.1.1298558638.12984.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 10+ messages in thread
From: Le Wang @ 2011-02-24 5:59 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 388 bytes --]
On Wed, Feb 23, 2011 at 11:53 PM, Stefan Monnier
<monnier@iro.umontreal.ca>wrote:
> It shouldn't be too difficult to write up a quick hack to do it, using
> isearch-search-fun-function. Something like
>
I learnt a few things from this snippet. Thanks Stefan!
> (defconst my-isearch-re "[^\n\s\t]*?")
>
or (defconst my-isearch-re "\\S *?")
I'm not sure which is clearer.
--
Le
[-- Attachment #2: Type: text/html, Size: 900 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: does emacs support incremental searching for partial matches?
2011-02-24 5:59 ` Le Wang
@ 2011-02-24 14:43 ` Stefan Monnier
[not found] ` <mailman.1.1298558638.12984.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2011-02-24 14:43 UTC (permalink / raw)
To: Le Wang; +Cc: help-gnu-emacs
>> (defconst my-isearch-re "[^\n\s\t]*?")
> or (defconst my-isearch-re "\\S *?")
> I'm not sure which is clearer.
Many languages set \n to have syntax "close comment" rather than
"space", in which case \S- does not exclude \n.
Stefan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: does emacs support incremental searching for partial matches?
[not found] ` <mailman.1.1298558638.12984.help-gnu-emacs@gnu.org>
@ 2011-02-26 3:22 ` jpkotta
0 siblings, 0 replies; 10+ messages in thread
From: jpkotta @ 2011-02-26 3:22 UTC (permalink / raw)
To: help-gnu-emacs
On Feb 24, 8:43 am, Stefan Monnier <monn...@iro.umontreal.ca> wrote:
> >> (defconst my-isearch-re "[^\n\s\t]*?")
> > or (defconst my-isearch-re "\\S *?")
> > I'm not sure which is clearer.
>
> Many languages set \n to have syntax "close comment" rather than
> "space", in which case \S- does not exclude \n.
>
> Stefan
I just added http://www.emacswiki.org/emacs/FlexIsearch to the wiki.
It's something that I've been thinking about for a while, but I didn't
know how to hook into isearch. I think it's very close to what the OP
wanted.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2011-02-26 3:22 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-21 10:28 does emacs support incremental searching for partial matches? Leh CHAO
2011-02-22 14:21 ` Drew Adams
2011-02-22 19:33 ` Leh CHAO
2011-02-22 20:42 ` Drew Adams
[not found] ` <mailman.2.1298403193.16069.help-gnu-emacs@gnu.org>
2011-02-22 21:49 ` Tim X
2011-02-23 15:53 ` Stefan Monnier
2011-02-24 5:59 ` Le Wang
2011-02-24 14:43 ` Stefan Monnier
[not found] ` <mailman.1.1298558638.12984.help-gnu-emacs@gnu.org>
2011-02-26 3:22 ` jpkotta
[not found] <mailman.10.1298381786.4429.help-gnu-emacs@gnu.org>
2011-02-22 21:34 ` Tim X
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).