From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Michael Slass Newsgroups: gmane.emacs.help Subject: Re: another newbie question -- auto-mode-alist regexp Date: Mon, 23 Sep 2002 23:15:02 GMT Organization: AT&T Broadband Sender: help-gnu-emacs-admin@gnu.org Message-ID: References: NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1032823579 9997 127.0.0.1 (23 Sep 2002 23:26:19 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 23 Sep 2002 23:26:19 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17tcan-0002az-00 for ; Tue, 24 Sep 2002 01:26:18 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17tcaq-0008ER-00; Mon, 23 Sep 2002 19:26:20 -0400 Original-Path: shelby.stanford.edu!nntp.stanford.edu!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!195.238.2.15!skynet.be!skynet.be!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!12.120.28.37.MISMATCH!attla2!ip.att.net!attbi_feed3!attbi.com!sccrnsc03.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 73 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Original-NNTP-Posting-Host: 12.228.19.12 Original-X-Complaints-To: abuse@attbi.com Original-X-Trace: sccrnsc03 1032822901 12.228.19.12 (Mon, 23 Sep 2002 23:15:01 GMT) Original-NNTP-Posting-Date: Mon, 23 Sep 2002 23:15:01 GMT Original-Xref: nntp.stanford.edu gnu.emacs.help:105204 Original-To: help-gnu-emacs@gnu.org Errors-To: help-gnu-emacs-admin@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.help:1759 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:1759 "Robert P. J. Day" 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 m emacs m regexps BOL. -- Mike Slass