On Thu, Jun 21, 2007 at 10:11:16AM -0500, Mike Miller wrote:
> On Thu, 21 Jun 2007, John Hawley wrote:
> 
> >A bit off topic, but a question about getting an emacs macro to find 
> >alternative regexp's.  Can't seem to get the right syntax.
> >Here's the macro.  Should find and jump to either 'foo' or 'bar'.
> >
> >The macro displays a message about not finding '\(foo\|bar\)'.
> >I've tried myriad variations of the search string pattern with differing 
> >quoting and escaping.  :(
> 
> I'm trying to learn this kind of thing too.  So does it do what you want 
> if you search for foo alone?  In other words, is this all about getting 
> the OR to work correctly?  Is the grouping (parens) always needed?
> 
> Mike
> 

Yes, the below macro works with or without the parens.

;(defconst search_patterns "\\(foo\\|bar\\)")
(defconst search_patterns "foo\\|bar")
(defun search-for-patterns ()
  "Search for alternative patterns."
  (interactive)
  (message "searching for %s" search_patterns)
  (let ((cur (point)))
    (re-search-forward search_patterns nil t)
    (let ((pnt (point)))
      (cond ((= cur pnt)
             (message "no find %s" search_patterns))
            (t
             (goto-char pnt)
             (message "found %s at char %s" search_patterns pnt)))
      )))