在emacs中设置auto-mode-alist [英] Setting auto-mode-alist in emacs

查看:156
本文介绍了在emacs中设置auto-mode-alist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到当前的自动模式输入全部以单引号结尾,例如

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

单引号。我会期望看到

 (\\.java $。java-mode)

我问的原因是我正在尝试获取名称与regexp匹配的文件

  ^ twiki\.corp。* 

在组织模式下打开。我尝试了以下成功:

 (add-to-list'auto-mode-alist'(^ twiki\\ \\\corporg-mode))
(add-to-list'auto-mode-alist'(\\'twiki\\corporg-mode))

以下作品:

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

但是并不完全是我想要的,因为它们中嵌入的twiki.corp的文件名将在组织模式下打开。

解决方案

\\'匹配字符串/缓冲区末尾的空字符串:



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



$将匹配行尾:如果您的文件名中有换行符(非常罕见) $将匹配新的线,而不是字符串的末尾。



正则表达式与整个文件名匹配,因此您需要包含/来匹配目录分隔符:

 (add-to-list'auto-mode-alist'(/twiki\\corp 。组织模式))


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 e l

$ 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆