Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I assign a regex to a variable?

4 views
Skip to first unread message

Tom Browder

unread,
Jul 28, 2016, 3:36:45 PM7/28/16
to help-gn...@gnu.org
Drew showed me how to bind a string to a variable, and that works great!
However, when I tried it where I actually needed it I got an error saying a
regex was expected.

I have searched for emacs named regexps but have found nothing. Does
anyone know how I can define a regex to be used in a function defined like
this (from package imenu.el):

(string regexp integer)

So I want to use the function like this:

("Funcs" regex-var 1)

but regex-var must be interpreted as a regex, not as a string.

Any help is appreciated.

Cheers!

-Tom

Yuri Khan

unread,
Jul 28, 2016, 3:49:07 PM7/28/16
to Tom Browder, help-gn...@gnu.org
On Fri, Jul 29, 2016 at 2:36 AM, Tom Browder <tom.b...@gmail.com> wrote:
> Drew showed me how to bind a string to a variable, and that works great!
> However, when I tried it where I actually needed it I got an error saying a
> regex was expected.

Show a small but complete example that demonstrates the problem.
Someone will be able to tell you what’s wrong with it.

In Emacs, regexps are not special. They are just strings. If you
assign a regexp string to a variable, you should be able to use that
variable in all the ways you could use an actual regexp string.

Drew Adams

unread,
Jul 28, 2016, 4:26:00 PM7/28/16
to Yuri Khan, Tom Browder, help-gn...@gnu.org
> Show a small but complete example that demonstrates the problem.
> Someone will be able to tell you what’s wrong with it.
>
> In Emacs, regexps are not special. They are just strings. If you
> assign a regexp string to a variable, you should be able to use that
> variable in all the ways you could use an actual regexp string.

What Yuri said. My guess is that the error message was
telling you that the characters in the string you provided
do not comprise a valid regexp. A regexp is represented
in Emacs Lisp by a string of characters, but not every
string of characters is a regular expression.

Consult the Elisp manual, starting a node `Regular Expressions',
for the syntax of an Elisp regexp.

http://www.gnu.org/software/emacs/manual/html_node/elisp/Regular-Expressions.html

Tom Browder

unread,
Jul 28, 2016, 4:44:25 PM7/28/16
to Drew Adams, Yuri Khan, help-gn...@gnu.org
On Thursday, July 28, 2016, Drew Adams <drew....@oracle.com> wrote:

> > Show a small but complete example that demonstrates the problem.
> > Someone will be able to tell you what’s wrong with it.


Okay, I'll try. But I do have the regexes that work great when I put it in
double quotes directly in the function. However, I want to be able to
define the regexes external to the function for better generality and
documentation.

I'll return later with a complete example.

Cheers!

-Tom

Drew Adams

unread,
Jul 28, 2016, 4:57:46 PM7/28/16
to Tom Browder, Yuri Khan, help-gn...@gnu.org
(FWIW, that wasn't me whom you quoted. It was Yuri.)

Tom Browder

unread,
Jul 28, 2016, 5:57:55 PM7/28/16
to Drew Adams, Yuri Khan, help-gn...@gnu.org
On Thu, Jul 28, 2016 at 3:57 PM, Drew Adams <drew....@oracle.com> wrote:
> (FWIW, that wasn't me whom you quoted. It was Yuri.)

Roger, sorry, Yuri.

-Tom

Barry Margolin

unread,
Jul 29, 2016, 3:08:41 AM7/29/16
to
In article <mailman.2250.146973866...@gnu.org>,
Tom Browder <tom.b...@gmail.com> wrote:

> On Thursday, July 28, 2016, Drew Adams <drew....@oracle.com> wrote:
>
> > > Show a small but complete example that demonstrates the problem.
> > > Someone will be able to tell you what’s wrong with it.
>
>
> Okay, I'll try. But I do have the regexes that work great when I put it in
> double quotes directly in the function. However, I want to be able to
> define the regexes external to the function for better generality and
> documentation.

There's no difference between using a literal string and a variable
whose value is that string, and it doesn't matter where the value comes
from.

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
0 new messages