unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How can I assign a regex to a variable?
@ 2016-07-28 19:36 Tom Browder
  2016-07-28 19:48 ` Yuri Khan
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Browder @ 2016-07-28 19:36 UTC (permalink / raw)
  To: help-gnu-emacs

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


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

* Re: How can I assign a regex to a variable?
  2016-07-28 19:36 How can I assign a regex to a variable? Tom Browder
@ 2016-07-28 19:48 ` Yuri Khan
  2016-07-28 20:25   ` Drew Adams
  0 siblings, 1 reply; 7+ messages in thread
From: Yuri Khan @ 2016-07-28 19:48 UTC (permalink / raw)
  To: Tom Browder; +Cc: help-gnu-emacs@gnu.org

On Fri, Jul 29, 2016 at 2:36 AM, Tom Browder <tom.browder@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.



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

* RE: How can I assign a regex to a variable?
  2016-07-28 19:48 ` Yuri Khan
@ 2016-07-28 20:25   ` Drew Adams
  2016-07-28 20:44     ` Tom Browder
       [not found]     ` <mailman.2250.1469738663.26859.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 7+ messages in thread
From: Drew Adams @ 2016-07-28 20:25 UTC (permalink / raw)
  To: Yuri Khan, Tom Browder; +Cc: help-gnu-emacs

> 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



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

* Re: How can I assign a regex to a variable?
  2016-07-28 20:25   ` Drew Adams
@ 2016-07-28 20:44     ` Tom Browder
  2016-07-28 20:57       ` Drew Adams
       [not found]     ` <mailman.2250.1469738663.26859.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 7+ messages in thread
From: Tom Browder @ 2016-07-28 20:44 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs@gnu.org, Yuri Khan

On Thursday, July 28, 2016, Drew Adams <drew.adams@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


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

* RE: How can I assign a regex to a variable?
  2016-07-28 20:44     ` Tom Browder
@ 2016-07-28 20:57       ` Drew Adams
  2016-07-28 21:57         ` Tom Browder
  0 siblings, 1 reply; 7+ messages in thread
From: Drew Adams @ 2016-07-28 20:57 UTC (permalink / raw)
  To: Tom Browder; +Cc: help-gnu-emacs, Yuri Khan

(FWIW, that wasn't me whom you quoted. It was Yuri.)

 

On Thursday, July 28, 2016, Drew Adams wrote:

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


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

* Re: How can I assign a regex to a variable?
  2016-07-28 20:57       ` Drew Adams
@ 2016-07-28 21:57         ` Tom Browder
  0 siblings, 0 replies; 7+ messages in thread
From: Tom Browder @ 2016-07-28 21:57 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs, Yuri Khan

On Thu, Jul 28, 2016 at 3:57 PM, Drew Adams <drew.adams@oracle.com> wrote:
> (FWIW, that wasn't me whom you quoted. It was Yuri.)

Roger, sorry, Yuri.

-Tom



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

* Re: How can I assign a regex to a variable?
       [not found]     ` <mailman.2250.1469738663.26859.help-gnu-emacs@gnu.org>
@ 2016-07-29  7:08       ` Barry Margolin
  0 siblings, 0 replies; 7+ messages in thread
From: Barry Margolin @ 2016-07-29  7:08 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 834 bytes --]

In article <mailman.2250.1469738663.26859.help-gnu-emacs@gnu.org>,
 Tom Browder <tom.browder@gmail.com> wrote:

> On Thursday, July 28, 2016, Drew Adams <drew.adams@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, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


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

end of thread, other threads:[~2016-07-29  7:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-28 19:36 How can I assign a regex to a variable? Tom Browder
2016-07-28 19:48 ` Yuri Khan
2016-07-28 20:25   ` Drew Adams
2016-07-28 20:44     ` Tom Browder
2016-07-28 20:57       ` Drew Adams
2016-07-28 21:57         ` Tom Browder
     [not found]     ` <mailman.2250.1469738663.26859.help-gnu-emacs@gnu.org>
2016-07-29  7:08       ` Barry Margolin

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