unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Test for a list of words?
@ 2003-05-11 10:45 Svend Tollak Munkejord
  2003-05-11 14:12 ` Jesper Harder
  0 siblings, 1 reply; 3+ messages in thread
From: Svend Tollak Munkejord @ 2003-05-11 10:45 UTC (permalink / raw)


Hi,

How can I test whether a buffer contains some words? Here is an example:

(re-search-forward "foo\\|bar\\|baz" nil t)

tests if one or more of the words are present, but I would like to test for
all of them. (This is inside a function)

Thanks for any hint.
-- 
Svend Tollak Munkejord 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Test for a list of words?
  2003-05-11 10:45 Test for a list of words? Svend Tollak Munkejord
@ 2003-05-11 14:12 ` Jesper Harder
  2003-05-11 15:10   ` Svend Tollak Munkejord
  0 siblings, 1 reply; 3+ messages in thread
From: Jesper Harder @ 2003-05-11 14:12 UTC (permalink / raw)


Svend Tollak Munkejord <stm@bacchus.pvv.org> writes:

> How can I test whether a buffer contains some words? Here is an
> example:
>
> (re-search-forward "foo\\|bar\\|baz" nil t)
>
> tests if one or more of the words are present, but I would like to
> test for all of them. (This is inside a function)

You could make a small function, say, `all-words-present-p':

  (require 'cl)

  (defun all-words-present-p (words)
    (every (lambda (word) 
	     (goto-char (point-min)) 
	     (search-forward word nil t))
	   words))

and then test like this:

  (all-words-present-p '("foo" "bar" "baz"))

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Test for a list of words?
  2003-05-11 14:12 ` Jesper Harder
@ 2003-05-11 15:10   ` Svend Tollak Munkejord
  0 siblings, 0 replies; 3+ messages in thread
From: Svend Tollak Munkejord @ 2003-05-11 15:10 UTC (permalink / raw)


Today, Jesper Harder <harder@myrealbox.com> wrote:

>Svend Tollak Munkejord <stm@bacchus.pvv.org> writes:
>
>>How can I test whether a buffer contains some words?
>
>You could make a small function, say, `all-words-present-p':
>
>(require 'cl)
>
>(defun all-words-present-p (words)
>(every (lambda (word) 
>	     (goto-char (point-min)) 
>	     (search-forward word nil t))
>	   words))

Great! Thanks!

-- 
Svend Tollak Munkejord 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-05-11 15:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-05-11 10:45 Test for a list of words? Svend Tollak Munkejord
2003-05-11 14:12 ` Jesper Harder
2003-05-11 15:10   ` Svend Tollak Munkejord

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).