* A search function that skip some characters
@ 2011-12-06 19:03 Martin Usbach
2011-12-06 19:33 ` Tekk
2011-12-06 21:11 ` Stefan Monnier
0 siblings, 2 replies; 6+ messages in thread
From: Martin Usbach @ 2011-12-06 19:03 UTC (permalink / raw)
To: emacs-devel
Hello,
how can I implement a search function that skip some character (like these
characters { '.', ',' , '2'}). So if I search "text" the function should not
only find "text" but also "tex.t", "t.e,xt.2.", "te2xt", "te,,,x.2.t" and so
on.
Is it too difficult?
Martin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: A search function that skip some characters
2011-12-06 19:03 A search function that skip some characters Martin Usbach
@ 2011-12-06 19:33 ` Tekk
2011-12-06 21:11 ` Stefan Monnier
1 sibling, 0 replies; 6+ messages in thread
From: Tekk @ 2011-12-06 19:33 UTC (permalink / raw)
To: Martin Usbach; +Cc: emacs-devel
I don't think it'd be too bad, but I can't give you the code off the top
of my head
On Tue, 6 Dec 2011, Martin Usbach wrote:
> Hello,
> how can I implement a search function that skip some character (like these
> characters { '.', ',' , '2'}). So if I search "text" the function should not
> only find "text" but also "tex.t", "t.e,xt.2.", "te2xt", "te,,,x.2.t" and so
> on.
>
> Is it too difficult?
>
> Martin
>
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: A search function that skip some characters
2011-12-06 19:03 A search function that skip some characters Martin Usbach
2011-12-06 19:33 ` Tekk
@ 2011-12-06 21:11 ` Stefan Monnier
2011-12-09 20:29 ` martin-u
1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2011-12-06 21:11 UTC (permalink / raw)
To: Martin Usbach; +Cc: emacs-devel
> how can I implement a search function that skip some character (like
> these characters { '.', ',' , '2'}). So if I search "text" the
> function should not only find "text" but also "tex.t", "t.e,xt.2.",
> "te2xt", "te,,,x.2.t" and so on.
I don't think Emacs has any special support for that.
> Is it too difficult?
I guess it depends on the specifics and on your motivation
and expertise. You can do
(re-search-forward (mapconcat (lambda (c) (regexp-quote (string c)))
"text" "[.,2]*"))
which may work, but if "text" is long and/or includes occurrences of
",", "." or "2", this approach may fail miserably. Also if you need
"text" to be a regular expression, then it gets more interesting.
So if that's not good enough, you'll probably have to do the search "by
hand" without using Emacs's builtin search functionality.
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: A search function that skip some characters
2011-12-06 21:11 ` Stefan Monnier
@ 2011-12-09 20:29 ` martin-u
2011-12-10 16:20 ` Drew Adams
0 siblings, 1 reply; 6+ messages in thread
From: martin-u @ 2011-12-09 20:29 UTC (permalink / raw)
To: Emacs-devel
Well, I have now the function mfun:
(defun mfun (&optional regexp-p no-recursive-edit) ;I've just copied it from
another function
(interactive "P\n")
(setq str (read-from-minibuffer
"Mysearch: "))
(insert-before-markers
(mapconcat (lambda (c) (regexp-quote (string c))) str "[.,2]*"))
)
I put it into my dot.emacs and it works (but badly). So, if I want to find
the all the "t[,.2]*e[,.2]*x[,.2]*t" regexps, I call M-x mfun. Then I type
"text" into the minibuffer. Then mfun put into the normal buffer
"t[,.2]*e[,.2]*x[,.2]*t" that I have to copy. Then I have to call
isearch-forward-regexp and put in it minibuffer the copied regexp
"t[,.2]*e[,.2]*x[,.2]*t". As you see this not a good solution.
Calling "isearch-forward-regexp" from mfun is not difficult. The problem is
that I can't put the REGEXP of "mapconcat" into the minibuffer of
isearch-forward-regexp.
For this I need some help. Or maybe you have another idea?
--
View this message in context: http://old.nabble.com/A-search-function-that-skip-some-characters-tp32926746p32945125.html
Sent from the Emacs - Dev mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: A search function that skip some characters
2011-12-09 20:29 ` martin-u
@ 2011-12-10 16:20 ` Drew Adams
2011-12-11 14:47 ` martin-u
0 siblings, 1 reply; 6+ messages in thread
From: Drew Adams @ 2011-12-10 16:20 UTC (permalink / raw)
To: 'martin-u', Emacs-devel
> (defun mfun (&optional regexp-p no-recursive-edit)
> (interactive "P\n")
\n serves no purpose here.
And you don't use arg NO-RECURSIVE-EDIT.
> (setq str (read-from-minibuffer "Mysearch: "))
> (insert-before-markers
> (mapconcat (lambda (c)
> (regexp-quote (string c)))
> str "[.,2]*")))
>
> I put it into my dot.emacs and it works (but badly). So, if I
> want to find the all the "t[,.2]*e[,.2]*x[,.2]*t" regexps, I
> call M-x mfun. Then I type "text" into the minibuffer. Then
> mfun put into the normal buffer "t[,.2]*e[,.2]*x[,.2]*t" that
> I have to copy. Then I have to call isearch-forward-regexp
> and put in it minibuffer the copied regexp
> "t[,.2]*e[,.2]*x[,.2]*t". As you see this not a good solution.
>
> Calling "isearch-forward-regexp" from mfun is not difficult.
> The problem is that I can't put the REGEXP of "mapconcat"
> into the minibuffer of isearch-forward-regexp.
>
> For this I need some help. Or maybe you have another idea?
1. I already gave you another idea, off list. What was wrong with it?
Put "[[:word:].,2]+" in a register or variable, and insert it after `M-e' during
isearch.
Or define a command to insert it after `M-e':
(defun foo () (interactive) (insert "[[:word:].,2]+"))
(define-key minibuffer-local-isearch-map (kbd "M-q") 'foo)
C-M-s M-e M-q C-s
2. FYI - A better mailing list for this kind of topic (a question about how to
use Emacs or Emacs Lisp) is help-gnu-emacs@gnu.org.
HTH.
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: A search function that skip some characters
2011-12-10 16:20 ` Drew Adams
@ 2011-12-11 14:47 ` martin-u
0 siblings, 0 replies; 6+ messages in thread
From: martin-u @ 2011-12-11 14:47 UTC (permalink / raw)
To: Emacs-devel
> 1. I already gave you another idea, off list. What was wrong with it?
This was my answer:
Hello,
"w[.,X]*o[.,X]*r[.,X]d" was just an example. It could be any other "text".
Everytime I give a text like "abc" or "xyz" (as argument for the function)
the special search function should
search "a[.,X]*b[.,X]*c[.,X]*" or "x[.,X]*y[.,X]*z[.,X]*".
But anyway, I have found a solution in your answer.
This was my help:
> (defun foo () (interactive) (insert "[[:word:].,2]+"))
> (define-key minibuffer-local-isearch-map (kbd "M-q") 'foo)
Here's the function
(defun my-search ()
(interactive)
(move-beginning-line 1)
(kill-line)
(setq g (car kill-ring))
(insert (mapconcat (lambda (c) (regexp-quote (string c)))
g "[.,2]*")))
and here's the keybinding:
(define-key minibuffer-local-isearch-map (kbd "M-q") 'my-search)
After C-M-S M-e I write the text I'm searching "text" and then I type M-q. I
get what I want "t[,.2]*e[,.2]*x[,.2]*t".
--
View this message in context: http://old.nabble.com/A-search-function-that-skip-some-characters-tp32926746p32955446.html
Sent from the Emacs - Dev mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-12-11 14:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-06 19:03 A search function that skip some characters Martin Usbach
2011-12-06 19:33 ` Tekk
2011-12-06 21:11 ` Stefan Monnier
2011-12-09 20:29 ` martin-u
2011-12-10 16:20 ` Drew Adams
2011-12-11 14:47 ` martin-u
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.