在Emacs中按顺序调用交互式函数

时间:2014-02-15 16:16:14

标签: emacs elisp org-mode

我的init.el是从init.org动态生成的。我还从init.org文件生成init.html文档。

我可以毫无问题地手动调用M-x org-babel-tangleM-x org-export-as-html,但我想要一个同时执行这两项工作的功能。

我写了以下函数:

(defun export-init-org ()
  "Generate init.html and init.html from the current init.org file."
  (interactive)
  (call-interactively 'org-export-as-html)
  (call-interactively 'org-babel-tangle))

这不起作用。它创建init.html文件,但不创建init.el文件。我尝试重新排序电话:

(defun export-init-org ()
  "Generate init.html and init.html from the current init.org file."
  (interactive)
  (call-interactively 'org-babel-tangle)
  (call-interactively 'org-export-as-html))

这可以正常工作,init.el和init.html都已创建。为什么是这样?我的第一个功能出了什么问题?

1 个答案:

答案 0 :(得分:1)

我的org安装中没有org-export-as-html。我怀疑你使用的是旧版本。但是,我认为您所看到的是org-export-as-html文件副作用的结果。如果此函数导致Emacs切换缓冲区,则最终会在html结果上调用org-babel-tangle,而不是org源。这当然不起作用。请尝试相应确认:

(defun export-init-org ()
  "Generate init.html and init.html from the current init.org file."
  (interactive)
  (save-excursion ;; restores original buffer after running
    (call-interactively 'org-export-as-html))
  (call-interactively 'org-babel-tangle))
相关问题