如何关闭特定主要模式的电气模式?

发布于 2025-02-07 16:38:32 字数 913 浏览 2 评论 0原文

我有几个主要模式(例如:yaml和nxml),我不想要电气模式(我想要像c一样的语言),但是如果关闭,我无法关闭。为了启用我:

(electric-indent-mode 1)

从文档(用于可变的电气模式)中

非nil如果启用了电动模式。 有关此次要模式的描述,请参见命令electric-Indent模式'。 直接设置此变量不会生效; 要么自定义(请参阅信息节点易于自定义') 或调用函数`electric-indent mode'。

并且用于功能

在即时重新注册(电气缩进模式)。有前缀 参数arg,如果ARG为正,则启用电气缩进模式,并且 否则将其禁用。如果是从LISP调用的,则启用模式如果ARG为 省略或零。

因此,我尝试用钩子将其关闭:(

(add-hook 'yaml-mode-hook (lambda ()                        
                             (electric-indent-mode -1)))

实际上我使用后修改后模式钩并检查(memql major-mode'(yaml-mode python-mode nxml-mode))我可以在列表中添加更多模式)。

但这不起作用,我也尝试:

(set (make-local-variable 'electric-indent-mode) nil)

没有快乐。但是,当我从.emacs文件中评估(electric-indent-mode -1)时,它可以正常工作。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我们只是彼此的过ke 2025-02-14 16:38:32

使用最近的emacs(可能仅使用Emacs快照),您可以使用electry-Indent-Local-Mode,例如:

(add-hook 'yaml-mode-hook (lambda () (electric-indent-local-mode -1)))

如果您的emacs缺乏此功能,您仍然可以通过electry electry electry -Indent-funnctions,例如

(add-hook 'yaml-mode-hook
          (lambda ()
             (add-hook 'electric-indent-functions
                            (lambda () 'no-indent) nil 'local)))

,无论哪种情况,您都可能想通过CJ通过

(add-hook 'yaml-mode-hook 
          (lambda () (local-set-key (kbd "C-j") #'newline-and-indent)))

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)))
£冰雨忧蓝° 2025-02-14 16:38:32

电动indent模式将在24.4中启用。要在本地关闭它,您将能够使用Lunaryorn提到的电气内部模式。但是要在24.3中将其关闭,您可以做:

(add-hook 'foo-mode-hook
          (lambda () (set (make-local-variable 'electric-indent-mode) nil)))

您提到第一个表格对您不起作用,但应该(即,如果不适合,这是由于其他一些问题)。

electric-indent-mode will be enabled by default in 24.4. To turn it off locally, you will be able to use electric-indent-local-mode as mentioned by lunaryorn. But to turn it off locally in 24.3, you can do:

(add-hook 'foo-mode-hook
          (lambda () (set (make-local-variable 'electric-indent-mode) nil)))

You mentioned that the first form didn't work for you, but it should (i.e. if it doesn't, it's because of the some other problem).

时间海 2025-02-14 16:38:32

至少在EMACS 24.3上,您不能在本地禁用电气凹痕模式,因为它是global-mode。无论如何,yaml模式的问题是,electric-indent功能已内置在其中,即使没有exight> exight> electry-code> electry-indent-mode 。该软件包没有提供关闭此行为的方法,也许您应该在其GitHub仓库上提出问题。

尝试以yaml-mode中的电动式功能禁用电动性功能,

(define-key yaml-mode-map "|" nil)
(define-key yaml-mode-map ">" nil)
(define-key yaml-mode-map "-" nil)
(define-key yaml-mode-map "." nil)
(define-key yaml-mode-map [backspace] nil)

以恢复电动性行为,您可以执行

(define-key yaml-mode-map "|" 'yaml-electric-bar-and-angle)
(define-key yaml-mode-map ">" 'yaml-electric-bar-and-angle)
(define-key yaml-mode-map "-" 'yaml-electric-dash-and-dot)
(define-key yaml-mode-map "." 'yaml-electric-dash-and-dot)
(define-key yaml-mode-map [backspace] 'yaml-electric-backspace)

At least on emacs 24.3 you cannot disable electric indent mode locally, since it is a global-mode. Anyways the issue with yaml-mode is that the electric-indent functionality is built into it i.e. it will be enabled even without electric-indent-mode. The package does not provide a way to turn this behaviour off, maybe you should file an issue on its github repo.

Try this to disable the electric-indent functionality in yaml-mode

(define-key yaml-mode-map "|" nil)
(define-key yaml-mode-map ">" nil)
(define-key yaml-mode-map "-" nil)
(define-key yaml-mode-map "." nil)
(define-key yaml-mode-map [backspace] nil)

To restore the electric-indent behaviour afterwards, you can do

(define-key yaml-mode-map "|" 'yaml-electric-bar-and-angle)
(define-key yaml-mode-map ">" 'yaml-electric-bar-and-angle)
(define-key yaml-mode-map "-" 'yaml-electric-dash-and-dot)
(define-key yaml-mode-map "." 'yaml-electric-dash-and-dot)
(define-key yaml-mode-map [backspace] 'yaml-electric-backspace)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文