我一直在使用emacs已经有一段时间了,我正在慢慢掌握一切.但是,我不知道足够的emacs-lisp来实现以下功能:
我想定义一个列表(比如prog-modes),它将是我使用的编程模式列表(.c,.cpp,.h,.el,.py).如果我打开的文件是此列表中提到的类型,我希望它以只读方式打开.否则,我希望它正常打开.
我更喜欢以只读方式打开我的文件以避免任何杂乱编辑,但是当emacs尝试自动打开文件并写入文件时(例如,在org-mode中),这会变得很烦人,因此需要这样的功能.
这样的事情应该满足你的需求.显然可以自定义主要模式列表:
(defun make-some-files-read-only ()
"when file opened is of a certain mode, make it read only"
(when (memq major-mode '(c++-mode tcl-mode text-mode))
(toggle-read-only 1)))
(add-hook 'find-file-hooks 'make-some-files-read-only)
Run Code Online (Sandbox Code Playgroud)