emacs - electric-indent-mode 破坏了我的 Python 代码

标签 emacs elisp python-mode

我在启用了 python-mode 的 Emacs 上有以下代码:

def func(a):
    if a:
        return True
    return False

当我在 return Falsedef 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 中使用 python 包(内置的 Python 对 Emacs 的飞行马戏团支持) ,根据梅尔帕的说法。也许我应该删除它并在其版本 6.0.10 中使用 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/

相关文章:

ubuntu - Shift 键在我的 emacs 中不起作用

emacs - Paredit:删除不需要的键绑定(bind)

Emacs 组织模式 : How can i fold everything but the current headline?

emacs - 如何使用elisp将十六进制字符串转换为ASCII?

emacs - 我的替换功能有问题

python - 在 ]vim python-mode 中禁用 PEP-257 警告

emacs - 如何从文件安装 Emacs 包

emacs - 以下解除绑定(bind)脚本有什么问题?

emacs python 模式 : designate which python shell to send commands to

python - 在 python 模式下更改 "send code to interpreter"(C-c |) 命令