all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* another newbie question -- auto-mode-alist regexp
@ 2002-09-23 22:43 Robert P. J. Day
  0 siblings, 0 replies; 7+ messages in thread
From: Robert P. J. Day @ 2002-09-23 22:43 UTC (permalink / raw)



  i've looked through both the emacs and elisp info pages, and
i haven't found a simple explanation for the syntax of the 
expression for setting the auto-mode-alist in my .emacs.

  a couple of examples that are part of the
(add-to-list 'auto-mode-alist ...  when i bring up online help
within emacs on the variable auto-mode-alist:

  ("\\.xml\\'" . xml-mode)
  ("\\.spec$" . rpm-spec-mode)
  ("\\.php[34]\\'\\|\\.php\\'\\|\\.phtml\\'" . php-mode)

what i haven't figured out yet:

1)  what means the sequence \\', as in what you see after
   ".xml" in that first example?  i can understand everything
   else, but that baffles me.

2) i assume that the "$" after .spec means end of string, which
  is familiar.  i'm curious why a lot of the other suffix regexp
  matches also don't match to end of string.  like the first one,
  .xml.  just curious.

3) regarding the php example, couldn't that have been written as
  
  ("\\.php[34]?\\'\\|\\.phtml\\'" . php-mode)


(this assumes that i still don't know what \\' means.)

  a pointer to the correct online help or info page would do
nicely.  thanks for your patience.

rday

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

* RE: another newbie question -- auto-mode-alist regexp
@ 2002-09-23 22:59 Bingham, Jay
  2002-09-23 23:27 ` Robert P. J. Day
  0 siblings, 1 reply; 7+ messages in thread
From: Bingham, Jay @ 2002-09-23 22:59 UTC (permalink / raw)


1. The \\ means make the next character literal.  Two are required because the string is parsed before it is placed in the variable if there are not two then the single \ gets stripped out and the literalness is lost.  So \. becomes just . (which means match any character) while \\. becomes \. (which means find a dot).

2. Yes, the $ means end of string.  Why it is not used on the xml is speculation unless you can get the author to respond.  My guess is the author wanted to match anything that had .xml in it.

3. Probably.

-_
J_)
C_)ingham
.    HP - NonStop Austin Software & Services - Software Product Assurance
.    Austin, TX
. Language is the apparel in which your thoughts parade in public.
. Never clothe them in vulgar and shoddy attire.          -Dr. George W. Crane-

 -----Original Message-----
From: 	Robert P. J. Day [mailto:rpjday@mindspring.com] 
Sent:	Monday, September 23, 2002 5:44 PM
To:	GNU emacs mailing list
Subject:	another newbie question -- auto-mode-alist regexp


  i've looked through both the emacs and elisp info pages, and
i haven't found a simple explanation for the syntax of the 
expression for setting the auto-mode-alist in my .emacs.

  a couple of examples that are part of the
(add-to-list 'auto-mode-alist ...  when i bring up online help
within emacs on the variable auto-mode-alist:

  ("\\.xml\\'" . xml-mode)
  ("\\.spec$" . rpm-spec-mode)
  ("\\.php[34]\\'\\|\\.php\\'\\|\\.phtml\\'" . php-mode)

what i haven't figured out yet:

1)  what means the sequence \\', as in what you see after
   ".xml" in that first example?  i can understand everything
   else, but that baffles me.

2) i assume that the "$" after .spec means end of string, which
  is familiar.  i'm curious why a lot of the other suffix regexp
  matches also don't match to end of string.  like the first one,
  .xml.  just curious.

3) regarding the php example, couldn't that have been written as
  
  ("\\.php[34]?\\'\\|\\.phtml\\'" . php-mode)


(this assumes that i still don't know what \\' means.)

  a pointer to the correct online help or info page would do
nicely.  thanks for your patience.

rday



_______________________________________________
Help-gnu-emacs mailing list
Help-gnu-emacs@gnu.org
http://mail.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: another newbie question -- auto-mode-alist regexp
       [not found] <mailman.1032821006.2883.help-gnu-emacs@gnu.org>
@ 2002-09-23 23:15 ` Michael Slass
  2002-09-23 23:17   ` Michael Slass
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Slass @ 2002-09-23 23:15 UTC (permalink / raw)


"Robert P. J. Day" <rpjday@mindspring.com> writes:

>  i've looked through both the emacs and elisp info pages, and
>i haven't found a simple explanation for the syntax of the 
>expression for setting the auto-mode-alist in my .emacs.
>
>  a couple of examples that are part of the
>(add-to-list 'auto-mode-alist ...  when i bring up online help
>within emacs on the variable auto-mode-alist:
>
>  ("\\.xml\\'" . xml-mode)
>  ("\\.spec$" . rpm-spec-mode)
>  ("\\.php[34]\\'\\|\\.php\\'\\|\\.phtml\\'" . php-mode)
>
>what i haven't figured out yet:
>
>1)  what means the sequence \\', as in what you see after
>   ".xml" in that first example?  i can understand everything
>   else, but that baffles me.
>
>2) i assume that the "$" after .spec means end of string, which
>  is familiar.  i'm curious why a lot of the other suffix regexp
>  matches also don't match to end of string.  like the first one,
>  .xml.  just curious.
>
>3) regarding the php example, couldn't that have been written as
>  
>  ("\\.php[34]?\\'\\|\\.phtml\\'" . php-mode)
>
>
>(this assumes that i still don't know what \\' means.)
>
>  a pointer to the correct online help or info page would do
>nicely.  thanks for your patience.
>
>rday
>
>
>

In a regexp, backslash is used to escape the following character.
Since "." is a metacharacter meaning "any character except newline",
if you want to match an actual dot, like in ".xml", you need to escape
the dot, as in \.

The next wrinkle is that the regexps you're looking at are represented
as string constants.  In string constants, backslashes are used to
introduce escape sequences, or characters that are harder to type.
'\n' represents the newline character, for example.  In order to
introduce a literal backslash into a string constant, you need to
escape the backslash with another one "\\"

Putting that together, in a regexp string constant, "\\." will match
exactly one literal dot.


In emacs regexps, \' is an anchor regexp:

,----
| `\''
|      matches the empty string, but only at the end of the buffer or
|      string being matched against.
`----

You can read all about that in the emacs manual that came with your
emacs.  To read this from within emacs:

C-h i <RET> m emacs <RET> m regexps <RET>

BOL.

-- 
Mike Slass

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

* Re: another newbie question -- auto-mode-alist regexp
  2002-09-23 23:15 ` Michael Slass
@ 2002-09-23 23:17   ` Michael Slass
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Slass @ 2002-09-23 23:17 UTC (permalink / raw)


Michael Slass <miknrene@drizzle.com> writes:

>In a regexp, backslash is used to escape the following character.
>Since "." is a metacharacter meaning "any character except newline",
>if you want to match an actual dot, like in ".xml", you need to escape
>the dot, as in \.
>
>The next wrinkle is that the regexps you're looking at are represented
>as string constants.  In string constants, backslashes are used to
>introduce escape sequences, or characters that are harder to type.
>'\n' represents the newline character, for example.  In order to
>introduce a literal backslash into a string constant, you need to
>escape the backslash with another one "\\"
>
>Putting that together, in a regexp string constant, "\\." will match
>exactly one literal dot.
>
>
>In emacs regexps, \' is an anchor regexp:
>
>,----
>| `\''
>|      matches the empty string, but only at the end of the buffer or
>|      string being matched against.
>`----
>
>You can read all about that in the emacs manual that came with your
>emacs.  To read this from within emacs:
>
>C-h i <RET> m emacs <RET> m regexps <RET>
>
>BOL.
>
>-- 
>Mike Slass


There's an extra <RET> in my instructions above.  This is correct:

C-h i m emacs <RET> m regexps <RET>

-- 
Mike Slass

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

* RE: another newbie question -- auto-mode-alist regexp
  2002-09-23 22:59 Bingham, Jay
@ 2002-09-23 23:27 ` Robert P. J. Day
  2002-09-23 23:34   ` Robert P. J. Day
  0 siblings, 1 reply; 7+ messages in thread
From: Robert P. J. Day @ 2002-09-23 23:27 UTC (permalink / raw)


On Mon, 23 Sep 2002, Bingham, Jay wrote:

> 1. The \\ means make the next character literal.  Two are required
> because the string is parsed before it is placed in the variable if
> there are not two then the single \ gets stripped out and the
> literalness is lost.  So \. becomes just . (which means match any
> character) while \\. becomes \. (which means find a dot).

i knew that part.  what i didn't understand was the function of
the double-escaped sinqle quote: \\'.  what does *that* represent?
the way it's used suggests something related to end-of-string,
but doesn't the "$" already serve that purpose?

rday

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

* RE: another newbie question -- auto-mode-alist regexp
  2002-09-23 23:27 ` Robert P. J. Day
@ 2002-09-23 23:34   ` Robert P. J. Day
  0 siblings, 0 replies; 7+ messages in thread
From: Robert P. J. Day @ 2002-09-23 23:34 UTC (permalink / raw)


On Mon, 23 Sep 2002, Robert P. J. Day wrote:

> On Mon, 23 Sep 2002, Bingham, Jay wrote:
> 
> > 1. The \\ means make the next character literal.  Two are required
> > because the string is parsed before it is placed in the variable if
> > there are not two then the single \ gets stripped out and the
> > literalness is lost.  So \. becomes just . (which means match any
> > character) while \\. becomes \. (which means find a dot).
> 
> i knew that part.  what i didn't understand was the function of
> the double-escaped sinqle quote: \\'.  what does *that* represent?
> the way it's used suggests something related to end-of-string,
> but doesn't the "$" already serve that purpose?

never mind, i finally found it in the elisp info manual.
apparently, \' matches the empty string, but only at the end
of the buffer or string being matched.

so, AFAICT, it appears to serve the same purpose as a trailing
$ to match end of string.

rday

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

* Re: another newbie question -- auto-mode-alist regexp
       [not found] <mailman.1032823999.4821.help-gnu-emacs@gnu.org>
@ 2002-09-23 23:56 ` Barry Margolin
  0 siblings, 0 replies; 7+ messages in thread
From: Barry Margolin @ 2002-09-23 23:56 UTC (permalink / raw)


In article <mailman.1032823999.4821.help-gnu-emacs@gnu.org>,
Robert P. J. Day <rpjday@mindspring.com> wrote:
>never mind, i finally found it in the elisp info manual.
>apparently, \' matches the empty string, but only at the end
>of the buffer or string being matched.
>
>so, AFAICT, it appears to serve the same purpose as a trailing
>$ to match end of string.

$ also matches the end of a line.  If you ever encounter a filename
containing an embedded newline, it would make a difference.

-- 
Barry Margolin, barmar@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

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

end of thread, other threads:[~2002-09-23 23:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1032823999.4821.help-gnu-emacs@gnu.org>
2002-09-23 23:56 ` another newbie question -- auto-mode-alist regexp Barry Margolin
     [not found] <mailman.1032821006.2883.help-gnu-emacs@gnu.org>
2002-09-23 23:15 ` Michael Slass
2002-09-23 23:17   ` Michael Slass
2002-09-23 22:59 Bingham, Jay
2002-09-23 23:27 ` Robert P. J. Day
2002-09-23 23:34   ` Robert P. J. Day
  -- strict thread matches above, loose matches on Subject: below --
2002-09-23 22:43 Robert P. J. Day

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.