我在启用了 python-mode
的 Emacs 上有以下代码:
def func(a):
if a:
return True
return False
当我在 return False
和 def func(
之间移动光标时,代码会自动缩进,打破它:
def func(a):
if a:
return True
return False #Oops!
我开始知道这种情况的发生是由于 electric-indent-mode
,一种次要的全局模式。但是,我尝试将其关闭,但问题仍然存在。
我使用的 elisp 代码是这样的:
(defun disable-electric-indent ()
(set (make-local-variable 'electric-indent-functions)
(list (lambda (arg) 'no-indent))))
这就是我的 python-mode-hook
的样子:
(add-hook 'python-mode-hook
(lambda ()
(flyspell-prog-mode)
(auto-complete-mode)
(nlinum-mode)
(toggle-truncate-lines t)
(setq autopair-handle-action-fns
(list 'autopair-default-handle-action 'autopair-python-triple-quote-action))
(centered-cursor-mode)
(auto-indent-mode)
(autopair-mode)
(column-marker-1 80)
(flycheck-mode)
(setq ac-auto-start 2)
(disable-electric-indent) ;; esto deberia hacer que emacs deje de romper las pelotas con el codigo en python
(jedi:setup)))
如果我关闭自动缩进模式
,此行为就会停止(但是,我没有自动缩进,哈哈)。
我的 emacs 版本:eric 上的 2013-04-29 的 GNU Emacs 24.3.1(x86_64-unknown-linux-gnu,GTK+ 版本 3.8.1)
编辑:我在其版本 0.24.2 中使用
,根据梅尔帕的说法。也许我应该删除它并在其版本 6.0.10 中使用 python
包(内置的 Python 对 Emacs 的飞行马戏团支持) python-mode
包?
最佳答案
你可能想尝试
(defun my-disable-electric-indent ()
(set (make-local-variable 'electric-indent-mode) nil))
关于emacs - electric-indent-mode 破坏了我的 Python 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17095247/