简体   繁体   中英

Setting auto-mode-alist in emacs

I notice that the current auto-mode-alist entries all end with a single quote, for example

 ("\\.java\\'" . java-mode)

What is the purpose of the single quote. I would have expected to see

 ("\\.java$" . java-mode)

The reason I ask is that I am trying to get files with names matching regexp

^twiki\.corp.* 

to open in org-mode. I have tried the following without success:

(add-to-list 'auto-mode-alist '("^twiki\\.corp" . org-mode))
(add-to-list 'auto-mode-alist '("\\'twiki\\.corp" . org-mode))

The following works:

(add-to-list 'auto-mode-alist '("twiki\\.corp" . org-mode))

but is not quite what I want since file names with twiki.corp embedded in them will be opened in org-mode.

\\\\' matches the empty string at the end of the string/buffer:

http://www.gnu.org/software/emacs/manual/html_node/emacs/Regexp-Backslash.html el

$ will match the end of the line: If you have newlines in your filename (very uncommon) $ will match the newline and not the end of the string.

The regex is matched against the whole filename, so you need include "/" to match the directory seperator:

(add-to-list 'auto-mode-alist '("/twiki\\.corp" . org-mode))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM