每个文件定制的Emacs [英] Emacs Per File Customization
问题描述
(defmacro * when-let((var value)& rest body)
` (let((,var,value))
(when,var,@ body)))
(defun func()
(when-let(a 1)
a))
我想要 when-let
fontized as a font-lock-keyword
并缩进如上。我知道我可以在我的.emacs文件中执行此操作,但我更愿意将其作为本地或文件本地定制的目录。问题是目录本地和文件本地自定义似乎限于设置变量。在我的.emacs文件中,我有以下内容。
(add-hook'emacs-lisp-mode-hook
(lambda()
(put'when-let'lisp-indent-function 1)
(font-lock-add-keywords nil
'(((\\ - ))$)
我想在 .dir-locals.el
中,因为它只适用于一个文件。
通过指定可以在文件局部变量 1 eval:
value(文档说Eval),但只有小写的eval:似乎可以工作)例如:
;;;本地变量:
;;;模式:outline-minor
;;; eval:(hide-body)
;;;结束:
作为安全措施,Emacs会询问您是否确认它看到一个它不被认为是安全的值。如果你告诉它永久记住它,它会将值写入(custom-set-variables)中的
safe-local-variable-values
/ code>部分。
请注意,上述启用次要模式的示例已被弃用(模式
局部变量只适用于主要模式),所以我们需要重写它作为另一个评估表单,我们称之为次模式函数。
如果需要评估多个表单,您可以指定多个 eval
值,这些值将按顺序进行评估:
;;;本地变量:
;;; eval:(outline-minor-mode 1)
;;; eval:(hide-body)
;;;结束:
或者,只需使用progn:
;;;本地变量:
;;; eval:(progn(outline-minor-mode 1)(hide-body))
;;;结束:
区别是后者将被认为是一个单一的值,用于 safe-local-variable-value
,而多个 eval
值,每个值独立考虑。
1 Ch 我 g (elisp)变量
RET
I have an Emacs Lisp file with custom macros I want fontified and indented differently. The code looks like:
(defmacro* when-let ((var value) &rest body)
`(let ((,var ,value))
(when ,var ,@body)))
(defun func ()
(when-let (a 1)
a))
I want when-let
fontified as a font-lock-keyword
and indented as above. I know I can do this in my .emacs file but I'd prefer to make it a directory local or file local customization. The problem is that directory local and file local customizations seem to be limited to setting variables. In my .emacs file I have the following.
(add-hook 'emacs-lisp-mode-hook
(lambda ()
(put 'when-let 'lisp-indent-function 1)
(font-lock-add-keywords nil
'(("(\\(when-let\\)\\>" 1
font-lock-keyword-face)))))
I want this in .dir-locals.el
because it applies only to one file.
You can specify elisp for evaluation in file local variables1 by specifying an eval:
value (the documentation says 'Eval:' but only lower-case 'eval:' seems to work). e.g.:
;;; Local Variables:
;;; mode: outline-minor
;;; eval: (hide-body)
;;; End:
As a security measure, Emacs will ask you for confirmation whenever it sees a value it does not already recognise as safe. If you tell it to remember it permanently, it writes the value to safe-local-variable-values
in the (custom-set-variables)
section of your init file.
Note that the above example of enabling a minor mode is deprecated (the mode
local variable is for major modes only), so we need to re-write it as another evaluated form, in which we call the minor mode function.
If you need to evaluate multiple forms, you can either specify multiple eval
values, which will be evaluated in order:
;;; Local Variables:
;;; eval: (outline-minor-mode 1)
;;; eval: (hide-body)
;;; End:
Or alternatively, just use progn:
;;; Local Variables:
;;; eval: (progn (outline-minor-mode 1) (hide-body))
;;; End:
The difference is that the latter would be considered a single value for the purposes of safe-local-variable-values
, whereas with multiple eval
values each one is considered independently.
1 C-hig (elisp) File Local Variables
RET
这篇关于每个文件定制的Emacs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!