help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Specifying a file in auto-mode-alist


From: Stefan Monnier
Subject: Re: Specifying a file in auto-mode-alist
Date: Fri, 23 Apr 2021 17:42:05 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

>> (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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]