特定主模式如何转动电压缩模式? [英] How to turn of electric-indent-mode for specific Major mode?
问题描述
我有几个主要模式(如:Yaml和NXML),我不想要电子缩进模式(我想要像C语言),但是我无法关闭。要使我有:
(电 - 缩进模式1)
pre>
从文档(用于可变电子缩进模式)
非-nil如果启用了电压缩模式。
有关此次要模式的说明,请参阅命令电 - 缩进模式。
轻松自定义)
直接设置此变量不生效;
可以定制它(请参阅信息节点
或调用函数`electric-indent-mode'。
和功能
切换即时重新压缩(电压缩模式) 。使用前缀
参数ARG,如果ARG为正,则启用电压缩模式,否则禁用
。如果从Lisp调用,如果ARG为
,则启用该模式,否则为零。
所以我尝试将其关闭一个钩子:
(add-hook'yaml-mode-hook(lambda()
(electric-indent-模式-1)))
(Actualy我使用改变后主模式挂钩和检查
(memql major-mode'(yaml-mode python-mode nxml-mode))
我可以在列表中添加更多的模式。
但它不起作用,我也尝试:
(set(make-local -variable'电子缩进模式)nil)
没有喜悦。但是当我从.emacs文件中eval
(电压缩模式-1)
时,它工作。解决方案使用最近的Emacs(可能仅仅是Emacs的快照),您可以使用
electric-indent-local-mode
,例如:(add-hook'yaml-mode-hook(lambda()(electric-indent-local-mode -1))
如果您的Emacs缺少此功能,您仍然可以通过
electric-indent-函数
,例如(add-hook'yaml-mode-hook
$ p在任何一种情况下,您可能想要通过
()
(add-hook'electric-indent-functions
(lambda()'no-indent)nil'local)))
$还原Cj
$ p
b $ b
(add-hook'yaml-mode-hook
(lambda()(local-set-key(kbdCj)#'newline- -intent)))
I have few Major modes (like: Yaml and NXML) that I don't want electric-indent-mode (I want it for C like languages) but I'm unable to turn if off. To enable I have:
(electric-indent-mode 1)
from documentation (for variable electric-indent-mode)
Non-nil if Electric-Indent mode is enabled. See the command
electric-indent-mode' for a description of this minor mode. Setting this variable directly does not take effect; either customize it (see the info node
Easy Customization') or call the function `electric-indent-mode'.and for a function
Toggle on-the-fly reindentation (Electric Indent mode). With a prefix argument ARG, enable Electric Indent mode if ARG is positive, and disable it otherwise. If called from Lisp, enable the mode if ARG is omitted or nil.
so I try to turn it off in a hook:
(add-hook 'yaml-mode-hook (lambda () (electric-indent-mode -1)))
(Actualy I use after-change-major-mode-hook and check
(memql major-mode '(yaml-mode python-mode nxml-mode))
where I can add more modes to the list).But it don't work, I've also try:
(set (make-local-variable 'electric-indent-mode) nil)
No joy. But it work when I eval
(electric-indent-mode -1)
from .emacs files.解决方案With a recent Emacs (probably Emacs snapshot only) you can use
electric-indent-local-mode
, e.g.:(add-hook 'yaml-mode-hook (lambda () (electric-indent-local-mode -1)))
If your Emacs lacks this function, you can still sort of disable the mode via
electric-indent-functions
, e.g.(add-hook 'yaml-mode-hook (lambda () (add-hook 'electric-indent-functions (lambda () 'no-indent) nil 'local)))
And in either case, you may probably want to restore
C-j
, via(add-hook 'yaml-mode-hook (lambda () (local-set-key (kbd "C-j") #'newline-and-indent)))
这篇关于特定主模式如何转动电压缩模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!