1. emacs 绑定文件类型到特地模式
1. emacs 绑定文件类型到特地模式
比如说扩展名为 .c 的文件默认打开 c-mode ,如果想绑定 .h 文件到 c-mode
就可以使用 auto-mode-alist 变量
C-h v 输入auto-mode-alist 查看变量信息
Alist of filename patterns vs corresponding major mode functions
Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION NON-NIL).
(NON-NIL stands for anything that is not nil; the value does not matter.)
Visiting a file whose name matches REGEXP specifies FUNCTION as the
mode function to use. FUNCTION will be called, unless it is nil.
实例:
emacs开发javascript ,可以使用 js2-mode.el 这个良好的开发环境,
配置: 把 .js 文件绑定到 js2-mode上
<span style="font-size:14px;">(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
(add-to-list 'auto-mode-alist '("\\.json$" . js2-mode))</span>
把以 .js 和 .json 为后缀名的文件绑定到js2-mode上
\\.js$ 是正则表达式,. 符号用 \\ 来转义得到 , $ 表示行尾