Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!husc6!yale!Ram-Ashwin
From: Ram-Ashwin@cs.yale.edu (Ashwin Ram)
Newsgroups: comp.emacs
Subject: Re: Function needed: is point within regexp?
Message-ID: <33135@yale-celray.yale.UUCP>
Date: 8 Jul 88 15:10:30 GMT
References: <8807070659.AA07832@blueberry.inria.fr>
Sender: root@yale.UUCP
Reply-To: Ram-Ashwin@cs.yale.edu (Ashwin Ram)
Organization: Computer Science, Yale University, New Haven, CT 06520-2158
Lines: 26
In-reply-to: shapiro@inria.inria.fr (Marc Shapiro)

In article <8807070659.AA07832@blueberry.inria.fr>, shapiro@inria (Marc Shapiro) writes:
> I am hacking a new, much-improved bibtex-mode for GNU Emacs.  For
> this, I need a function which checks if point is *within* a certain
> regular expression.
> 
> The function bibtex-enclosing-regexp enclosed below does the trick,
> but in a very stupid way.  It moves backwards by an arbitrary number
> of characters, and then repeatedly calls re-search-forward until a
> match is found, and its boundaries enclose the original point.
> 
> Surely there is a better way to do this!  Any ideas?

You can do better than this by --

- searching backward for a character that matches the first "thing" in the
  regexp (since any match must start at such a character)
- checking if you're looking-at the regexp, and, if so, if the boundaries of the
  match enclose the original point
- and repeating this until you're done.

The first step is a little tricky since the "first thing in the regexp" could be
a wild card or a disjunction, so you'll have to write code that will pick this
out by pseudo-parsing the regexp string.  If you don't want to write the general
function, it should be pretty easy to do this for the bibtex case.

-- Ashwin.