all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Is this comment in my .emacs correct?
@ 2004-08-20  0:09 William Payne
  2004-08-20  0:53 ` Barry Margolin
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: William Payne @ 2004-08-20  0:09 UTC (permalink / raw)


>From my .emacs-file:

(setq auto-mode-alist
      (append
       (list
; Must use Makefile$ and not just Makefile or you will get makefile mode for 
any
; type of file in a directory with the string makefile in it
        '("\\Makefile$" . makefile-mode)         )
       auto-mode-alist
       )
      )

Is the comment correct?

/ WP 

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

* Re: Is this comment in my .emacs correct?
  2004-08-20  0:09 Is this comment in my .emacs correct? William Payne
@ 2004-08-20  0:53 ` Barry Margolin
  2004-08-20 16:38   ` Stefan Monnier
  2004-08-20  9:58 ` maddog
  2004-08-20 15:26 ` Kevin Rodgers
  2 siblings, 1 reply; 9+ messages in thread
From: Barry Margolin @ 2004-08-20  0:53 UTC (permalink / raw)


In article <cg3ffn$cpj$1@news.island.liu.se>,
 "William Payne" <mikas493_no_spam@student.liu.se> wrote:

> From my .emacs-file:
> 
> (setq auto-mode-alist
>       (append
>        (list
> ; Must use Makefile$ and not just Makefile or you will get makefile mode for 
> any
> ; type of file in a directory with the string makefile in it
>         '("\\Makefile$" . makefile-mode)         )
>        auto-mode-alist
>        )
>       )
> 
> Is the comment correct?

Not quite.  You'll get makefile mode for any pathname that contains the 
string "\Makefile" in it.  So it will use this mode for something like 
"C:\Data\Makefiles\README.txt", but not 
"C:\Data\My_Makefiles\README.txt".

The $ matches the end of the pathname.

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

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

* Re: Is this comment in my .emacs correct?
  2004-08-20  0:09 Is this comment in my .emacs correct? William Payne
  2004-08-20  0:53 ` Barry Margolin
@ 2004-08-20  9:58 ` maddog
  2004-08-20 15:26 ` Kevin Rodgers
  2 siblings, 0 replies; 9+ messages in thread
From: maddog @ 2004-08-20  9:58 UTC (permalink / raw)


"William Payne" <mikas493_no_spam@student.liu.se> writes:

> From my .emacs-file:
>
> (setq auto-mode-alist
>       (append
>        (list
> ; Must use Makefile$ and not just Makefile or you will get makefile mode for 
> any
> ; type of file in a directory with the string makefile in it
>         '("\\Makefile$" . makefile-mode)         )
>        auto-mode-alist
>        )
>       )
>
> Is the comment correct?
>
> / WP 

Why not give a test by your hand?

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

* Re: Is this comment in my .emacs correct?
  2004-08-20  0:09 Is this comment in my .emacs correct? William Payne
  2004-08-20  0:53 ` Barry Margolin
  2004-08-20  9:58 ` maddog
@ 2004-08-20 15:26 ` Kevin Rodgers
  2004-08-20 16:18   ` William Payne
  2 siblings, 1 reply; 9+ messages in thread
From: Kevin Rodgers @ 2004-08-20 15:26 UTC (permalink / raw)


William Payne wrote:
 > From my .emacs-file:
 >
 > (setq auto-mode-alist
 >       (append
 >        (list
 > ; Must use Makefile$ and not just Makefile or you will get makefile mode for
 > any
 > ; type of file in a directory with the string makefile in it
 >         '("\\Makefile$" . makefile-mode)         )
 >        auto-mode-alist
 >        )
 >       )
 >
 > Is the comment correct?

Almost.  You do need to anchor the "Makefile" string, because the
auto-mode-alist entries are matched against the entire file name
(`C-h v buffer-file-name' for an example).  But "$" is not the best
anchor, because it can also match a newline in the path; that's an
admittedly unusual case, but it'd be better and consistent with the
other entries if you used "\\'".  Also, you might want to anchor the
beginning of the file name; but the default entries don't provide much
guidance since there are examples with no anchor, some with just "/",
and some with "\\(/\\|\\`\\)".

(setq auto-mode-alist
       (cons '("\\(\\`\\|/\\)Makefile\\'" . makefile-mode)
             auto-mode-alist))

-- 
Kevin Rodgers

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

* Re: Is this comment in my .emacs correct?
  2004-08-20 15:26 ` Kevin Rodgers
@ 2004-08-20 16:18   ` William Payne
  0 siblings, 0 replies; 9+ messages in thread
From: William Payne @ 2004-08-20 16:18 UTC (permalink / raw)



"Kevin Rodgers" <ihs_4664@yahoo.com> wrote in message 
news:41261839.20804@yahoo.com...
> William Payne wrote:
> > From my .emacs-file:
> >
> > (setq auto-mode-alist
> >       (append
> >        (list
> > ; Must use Makefile$ and not just Makefile or you will get makefile mode 
> > for
> > any
> > ; type of file in a directory with the string makefile in it
> >         '("\\Makefile$" . makefile-mode)         )
> >        auto-mode-alist
> >        )
> >       )
> >
> > Is the comment correct?
>
> Almost.  You do need to anchor the "Makefile" string, because the
> auto-mode-alist entries are matched against the entire file name
> (`C-h v buffer-file-name' for an example).  But "$" is not the best
> anchor, because it can also match a newline in the path; that's an
> admittedly unusual case, but it'd be better and consistent with the
> other entries if you used "\\'".  Also, you might want to anchor the
> beginning of the file name; but the default entries don't provide much
> guidance since there are examples with no anchor, some with just "/",
> and some with "\\(/\\|\\`\\)".
>
> (setq auto-mode-alist
>       (cons '("\\(\\`\\|/\\)Makefile\\'" . makefile-mode)
>             auto-mode-alist))
>
> -- 
> Kevin Rodgers
>

Thanks for the reply, Kevin. I wanted to make sure I load makefile-mode only 
when dealing with a file named Makefile and not when the path to the file 
contained the string Makefile. Your version seems to work, thanks.

/ WP 

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

* Re: Is this comment in my .emacs correct?
  2004-08-20  0:53 ` Barry Margolin
@ 2004-08-20 16:38   ` Stefan Monnier
  2004-08-20 16:59     ` Eli Zaretskii
       [not found]     ` <mailman.2116.1093021754.2011.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 9+ messages in thread
From: Stefan Monnier @ 2004-08-20 16:38 UTC (permalink / raw)


>> '("\\Makefile$" . makefile-mode)         )
[...]
> Not quite.  You'll get makefile mode for any pathname that contains the 
> string "\Makefile" in it.  So it will use this mode for something like 
> "C:\Data\Makefiles\README.txt", but not 
> "C:\Data\My_Makefiles\README.txt".

Still not quite: the string "\\Makefile$" turns into the regexp \Makefile$
but the `\M' is interpreted as just `M' (i.e. the backslash is ignored:
it should be flagged as an error, really).

> The $ matches the end of the pathname.

And it also matches a newline embedded in the pathname (e.g. if a file or
directory's name spans two or more lines).  Use the regexp operator \' if
you only want to match the end of the pathname.

So what the original regexp probably meant was: "\\\\Makefile\\'".
But note that Emacs will very often turn a \ into a / in your pathnames.
So maybe "[\\/]Makefile\\'" is better.

But in any case, there is already an entry

 ("\\(M\\|m\\|GNUm\\)akefile\\'" . makefile-mode)

in auto-mode-alist in not too ancient Emacsen, so you can simply remove the
whole thing from your .emacs file.


        Stefan

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

* Re: Is this comment in my .emacs correct?
  2004-08-20 16:38   ` Stefan Monnier
@ 2004-08-20 16:59     ` Eli Zaretskii
       [not found]     ` <mailman.2116.1093021754.2011.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2004-08-20 16:59 UTC (permalink / raw)


> Newsgroups: gnu.emacs.help
> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Fri, 20 Aug 2004 16:38:10 GMT
> 
> > The $ matches the end of the pathname.
> 
> And it also matches a newline embedded in the pathname

True, but irrelevant in this case: Windows file names cannot have
embedded newlines.

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

* Re: Is this comment in my .emacs correct?
       [not found]     ` <mailman.2116.1093021754.2011.help-gnu-emacs@gnu.org>
@ 2004-08-20 18:10       ` Stefan Monnier
  2004-08-20 18:15         ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2004-08-20 18:10 UTC (permalink / raw)


>> > The $ matches the end of the pathname.
>> And it also matches a newline embedded in the pathname
> True, but irrelevant in this case: Windows file names cannot have
> embedded newlines.

Good to know, thanks.
What happens if you use SMB to access a file from another system (GNU/Linux,
for example) that includes a newline?


        Stefan

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

* Re: Is this comment in my .emacs correct?
  2004-08-20 18:10       ` Stefan Monnier
@ 2004-08-20 18:15         ` Eli Zaretskii
  0 siblings, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2004-08-20 18:15 UTC (permalink / raw)


> Newsgroups: gnu.emacs.help
> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Fri, 20 Aug 2004 18:10:29 GMT
> 
> What happens if you use SMB to access a file from another system (GNU/Linux,
> for example) that includes a newline?

I didn't try that (and cannot try it where I'm typing this), but I'm
almost certain that SMB will fail such a request, because the host
that controls the disk will not allow it.

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

end of thread, other threads:[~2004-08-20 18:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-20  0:09 Is this comment in my .emacs correct? William Payne
2004-08-20  0:53 ` Barry Margolin
2004-08-20 16:38   ` Stefan Monnier
2004-08-20 16:59     ` Eli Zaretskii
     [not found]     ` <mailman.2116.1093021754.2011.help-gnu-emacs@gnu.org>
2004-08-20 18:10       ` Stefan Monnier
2004-08-20 18:15         ` Eli Zaretskii
2004-08-20  9:58 ` maddog
2004-08-20 15:26 ` Kevin Rodgers
2004-08-20 16:18   ` William Payne

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.