字节编译时的无限循环

时间:2015-10-26 14:41:22

标签: emacs elisp

我是evil-commentary的作者,在回购邮件中可以找到少于200行的完整来源。

基本上我有类似的东西。

(evil-define-operator evil-commentary (beg end type)
  "Comment or uncomment region that {motion} moves over."
  :move-point nil
  (interactive "<R>")
  (let ((comment-function
         (cdr (assoc major-mode
                     evil-commentary-comment-function-for-mode-alist))))
    (if comment-function (funcall comment-function beg end)
      (comment-or-uncomment-region beg end))))


(defun evil-commentary-comment-for-org (beg end)
  "Comment function for `org-mode'."
  (interactive "r")
  (if (and (fboundp 'org-in-src-block-p)
           (org-in-src-block-p))
      (evil-commentary-do-in-org-src-block beg end
        (call-interactively 'evil-commentary))
    (comment-or-uncomment-region beg end)))

我们的想法是evil-commentary会在组织文件中调用evil-commentary-comment-for-org,如果我们在src块中,evil-commentary-comment-for-org会再次调用evil-commentary src-edit缓冲区(现在有不同的major-mode

设置工作正常,但是当我编译代码时,我得到一个无限循环evil-commentary - &gt; evil-commentary-comment-for-org - &gt; evil-commentary ... Variable binding depth exceeds max-specpdl-size错误...

我发现如果我在加载org之后编译代码,它会起作用,但这不是我想要的,因为如果用户使用旧版{{1}进行编译,evil-commentary将停止工作然后升级它。 (org)的缺陷

谢谢!

1 个答案:

答案 0 :(得分:1)

问题出在this line,扩展为:

  (org-babel-do-in-edit-buffer
   (call-interactively 'evil-commentary))

如果您尚未加载org,则字节编译器不知道org-babel-do-in-edit-buffer是宏,并且无法扩展它。因此,它只是编译一个名为org-babel-do-in-edit-buffer的函数(尚未知)。

当执行到达该行时,首先计算函数参数(与任何其他函数调用一样),并且你有无限循环。

尝试org阻止eval-when-compile内的Queries.List = new ObservableCollection<Query>(Queries.List.Where(x => x.Name.Equals(value)));