orgmode中在python/ipython代码块上按`o`打开新行非常慢

这个问题也是由来已久了,其它代码块没有这个问题,或者没有这么严重。直接在行后按回车也没问题。我录了一个gif说明这个问题,可以清楚地看到按下o后很久才打开新行:

test1

大家是怎么解决的?

@fuxialexander

open line的时候调用了org-edit-src-code 所以会慢

我猜是因为用了language-specific的indentation所以要调用这个函数

然后可能ipython的edit src code的implementation会新建一个ipython session 所以就尤其慢

1 个赞

没看到有调用 org-edit-src-code

多谢提醒,看来是 Indent 造成的,把这个变量设为 nil 就好了:

evil-auto-indent is a variable defined in ‘evil-vars.el’.
Its value is t

  Automatically becomes buffer-local when set.

Documentation:
Whether to auto-indent when opening lines.

You can customize this variable.


2 个赞

有同样问题的同学可以把下面代码放进你的配置,只是禁用了 Python 代码块的 indent:

    (defvar et/evil-open-line-no-indent-langs '("python" "ipython"))

    (defun evil-open-no-autoindent (oldfun arg)
      (if (and evil-auto-indent
               (eq major-mode 'org-mode)
               (member (org-eldoc-get-src-lang) et/evil-open-line-no-indent-langs))
          (let ((evil-auto-indent nil))
            (funcall oldfun arg))
        (funcall oldfun arg)))


    (advice-add #'evil-open-above :around #'evil-open-no-autoindent)
    (advice-add #'evil-open-below :around #'evil-open-no-autoindent)

3 个赞