在 emacs 中设置 auto-mode-alist [英] 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))
以下工作:
(add-to-list 'auto-mode-alist '("twiki\.corp" . org-mode))
但不是我想要的,因为嵌入了 twiki.corp 的文件名将在组织模式下打开.
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/软件/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))
这篇关于在 emacs 中设置 auto-mode-alist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!