unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Specifying a file in auto-mode-alist
@ 2021-04-23 20:25 Patrick Mahan
  2021-04-23 20:42 ` Óscar Fuentes
  0 siblings, 1 reply; 6+ messages in thread
From: Patrick Mahan @ 2021-04-23 20:25 UTC (permalink / raw)
  To: help-gnu-emacs

All,

I have build scripts that capture a build (makefile output) into files
called build*.log or Build*.log. These files may occur at various points in
the directory tree.

However if I use the following:

(add-to-list 'auto-mode-alist (quote("build*\\.log'" . compilation-mode)))

When I edit a file say 'build.log' it does not enable compilation mode.

I tried -

(add-to-list 'auto-mode-alist (quote("build*\\'" . compilation-mode)))

But that clashes with other files like a0build.h.

I've read the wiki page on auto-mode-alist, but none of the examples are
about how to use filename that starts with 'xyz*.log'.

Thanks,

Patrick


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

* Re: Specifying a file in auto-mode-alist
  2021-04-23 20:25 Specifying a file in auto-mode-alist Patrick Mahan
@ 2021-04-23 20:42 ` Óscar Fuentes
  2021-04-23 21:42   ` Stefan Monnier
  2021-04-23 22:09   ` Patrick Mahan
  0 siblings, 2 replies; 6+ messages in thread
From: Óscar Fuentes @ 2021-04-23 20:42 UTC (permalink / raw)
  To: help-gnu-emacs

Patrick Mahan <plmahan@gmail.com> writes:

> All,
>
> I have build scripts that capture a build (makefile output) into files
> called build*.log or Build*.log. These files may occur at various points in
> the directory tree.
>
> However if I use the following:
>
> (add-to-list 'auto-mode-alist (quote("build*\\.log'" . compilation-mode)))
____________________________________________________^

> When I edit a file say 'build.log' it does not enable compilation mode.
>
> I tried -
>
> (add-to-list 'auto-mode-alist (quote("build*\\'" . compilation-mode)))
________________________________________________^

Why the ' ?

Try this regexp: "^[Bb]uild.*\\.log$"

That means: Starts with B or b followed by uild and then zero or more
arbitrary characters and ends with .log

(add-to-list 'auto-mode-alist '("^[Bb]uild.*\\.log$" . compilation-mode))




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

* Re: Specifying a file in auto-mode-alist
  2021-04-23 20:42 ` Óscar Fuentes
@ 2021-04-23 21:42   ` Stefan Monnier
  2021-04-23 22:14     ` Patrick Mahan
  2021-04-23 22:09   ` Patrick Mahan
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2021-04-23 21:42 UTC (permalink / raw)
  To: help-gnu-emacs

>> (add-to-list 'auto-mode-alist (quote("build*\\.log'" . compilation-mode)))
> ____________________________________________________^

Here you needed to replace ' with \\'

>> When I edit a file say 'build.log' it does not enable compilation mode.
>>
>> I tried -
>>
>> (add-to-list 'auto-mode-alist (quote("build*\\'" . compilation-mode)))
> ________________________________________________^
>

And here you just forgot the \\.log

> Why the ' ?
>
> Try this regexp: "^[Bb]uild.*\\.log$"

No, he was on the right path.

The correct regexp construct to match the end of a string is \' (which
inside a string ends up looking like \\' since the backslash needs to be
escaped), whereas the $ you're recommending matches both the end of
a string and an end of *line*, so it can mis-match with a file named
"build.log\nhello.svg".


        Stefan




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

* Re: Specifying a file in auto-mode-alist
  2021-04-23 20:42 ` Óscar Fuentes
  2021-04-23 21:42   ` Stefan Monnier
@ 2021-04-23 22:09   ` Patrick Mahan
  2021-04-23 22:23     ` Stefan Monnier
  1 sibling, 1 reply; 6+ messages in thread
From: Patrick Mahan @ 2021-04-23 22:09 UTC (permalink / raw)
  To: Óscar Fuentes; +Cc: help-gnu-emacs

On Fri, Apr 23, 2021 at 1:51 PM Óscar Fuentes <ofv@wanadoo.es> wrote:

> Patrick Mahan <plmahan@gmail.com> writes:
>
> > All,
> >
> > I have build scripts that capture a build (makefile output) into files
> > called build*.log or Build*.log. These files may occur at various points
> in
> > the directory tree.
> >
> > However if I use the following:
> >
> > (add-to-list 'auto-mode-alist (quote("build*\\.log'" .
> compilation-mode)))
> ____________________________________________________^
>
> > When I edit a file say 'build.log' it does not enable compilation mode.
> >
> > I tried -
> >
> > (add-to-list 'auto-mode-alist (quote("build*\\'" . compilation-mode)))
> ________________________________________________^
>
> Why the ' ?
>
>
A lot of the examples in the wiki used them.  But I see I should have
prefaced it with \\'.


> Try this regexp: "^[Bb]uild.*\\.log$"
>
> That means: Starts with B or b followed by uild and then zero or more
> arbitrary characters and ends with .log
>
> (add-to-list 'auto-mode-alist '("^[Bb]uild.*\\.log$" . compilation-mode))
>
>
emacs ~/workspace/src/build.log
Nope, it shows up in Fundamental mode.

Neither does emacs ~/workspace/src/build202104191533.log

Is there a "verbose" mode for emacs?  Someway of seeing what is being
applied?

Thanks,

Patrick


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

* Re: Specifying a file in auto-mode-alist
  2021-04-23 21:42   ` Stefan Monnier
@ 2021-04-23 22:14     ` Patrick Mahan
  0 siblings, 0 replies; 6+ messages in thread
From: Patrick Mahan @ 2021-04-23 22:14 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

On Fri, Apr 23, 2021 at 2:52 PM Stefan Monnier <monnier@iro.umontreal.ca>
wrote:

> >> (add-to-list 'auto-mode-alist (quote("build*\\.log'" .
> compilation-mode)))
> > ____________________________________________________^
>
> Here you needed to replace ' with \\'
>
> >> When I edit a file say 'build.log' it does not enable compilation mode.
> >>
> >> I tried -
> >>
> >> (add-to-list 'auto-mode-alist (quote("build*\\'" . compilation-mode)))
> > ________________________________________________^
> >
>
> And here you just forgot the \\.log
>
> > Why the ' ?
> >
> > Try this regexp: "^[Bb]uild.*\\.log$"
>
> No, he was on the right path.
>
> The correct regexp construct to match the end of a string is \' (which
> inside a string ends up looking like \\' since the backslash needs to be
> escaped), whereas the $ you're recommending matches both the end of
> a string and an end of *line*, so it can mis-match with a file named
> "build.log\nhello.svg".
>
>
Yes!  Success!  Thanks Stefan!  Changing it to escape the ' makes it work
now.

Patrick


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

* Re: Specifying a file in auto-mode-alist
  2021-04-23 22:09   ` Patrick Mahan
@ 2021-04-23 22:23     ` Stefan Monnier
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2021-04-23 22:23 UTC (permalink / raw)
  To: help-gnu-emacs

>> (add-to-list 'auto-mode-alist '("^[Bb]uild.*\\.log$" . compilation-mode))
[...]
> emacs ~/workspace/src/build.log
> Nope, it shows up in Fundamental mode.

BTW, this is because of the `^` in his regexp: the regexps in
`auto-mode-alist` are matched against the full (absolute) file name, so
your regexp has to match ".../build.log" rather than just "build.log".


        Stefan




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

end of thread, other threads:[~2021-04-23 22:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-23 20:25 Specifying a file in auto-mode-alist Patrick Mahan
2021-04-23 20:42 ` Óscar Fuentes
2021-04-23 21:42   ` Stefan Monnier
2021-04-23 22:14     ` Patrick Mahan
2021-04-23 22:09   ` Patrick Mahan
2021-04-23 22:23     ` Stefan Monnier

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