2014-02-14 81 views
1

我在emacs中使用org-mode和ox-reveal。后者定义了org-reveal-export-to-html命令,我想绑定到带有org文件的缓存键,这是演示文稿(所有组织文件不适用)。emacs组织模式文件本地密钥绑定

所以问题是:如何在组织模式下定义文件本地键绑定?

我现在有是这样的:

#+BEGIN_COMMENT 
Local Variables: 
eval: (local-set-key [f5] 'org-reveal-export-to-html) 
End: 
#+END_COMMENT 

但恕我直言,这是不是很优雅。

+0

重复[文件特定的键绑定在Emacs(http://stackoverflow.com/a/21493693/324105)? – phils

回答

2

您可以通过使用ORG-defkey定义仅适用于组织模式的关键,基本上添加以下到您的init文件

(org-defkey org-mode-map [f5] 'org-reveal-export-to-html) 

UPDATE

您可以使用文件的局部变量。

(defvar export-with-reveal nil) 

(defun export-with-reveal-or-html() 
    (interactive) 
    (if (or export-with-reveal (file-exists-p "reveal.js")) 
     (call-interactively 'org-reveal-export-to-html) 
    (call-interactively 'org-export-as-html))) 

(org-defkey org-mode-map [f5] 'export-with-reveal-or-html) 

功能export-with-reveal-or-html如果变量export-with-reveal具有值T或有一个文件“reveal.js”相对于ORG文件,如果是的话它reveal出口也回落到默认的HTML出口。你可以指定一个文件,以出口加作为显示以下到您的组织文件的顶部

# -*- export-with-reveal: t -*- 

更新2

您还可以通过使用文件的本地变量做定义任意输出功能

(defvar my-export-fn nil) 

(defun my-export() 
    (interactive) 
    (if my-export-fn 
     (call-interactively my-export-fn) 
    (call-interactively 'org-export-as-html))) 

(org-defkey org-mode-map [f5] 'my-export) 

然后在文件的顶部,你可以设置导出功能要使用如

# -*- export-fn: org-reveal-export-to-html -*- 
+0

是的,但我不希望这个绑定的所有组织文件,只为一些特定的(在我的情况下,我希望导出到HTML使用revealJS)。 – theldoria

+0

如果我可以在组织模式下定义一个缓冲区局部变量,那么我可以编写一个函数来处理我想要的缓冲区的导出。但是我对组织模式很陌生,所以,是否有这样的可能性(尽管上面提到的局部变量)? – theldoria

+0

确定这可以通过org-mode-hook来完成,当你点击'f5'时你想为其他组织模式文件做些什么? – 2014-02-14 09:01:18

0

我想出了以下解决方案,它利用局部变量挂钩黑客和定义​​缓冲LOKAL钩:

(add-hook 'org-mode-hook 'my-org-mode-hook) 
(defun my-org-mode-hook() 
    (add-hook 'hack-local-variables-hook 
      (lambda() 
       (local-set-key [f5] (if (boundp 'my-org-export) 
             my-org-export 
            'org-html-export-to-html))))) 

然后在组织模式,我补充一点:

#+BEGIN_COMMENT 
Local Variables: 
my-org-export: org-reveal-export-to-html 
End: 
#+END_COMMENT 

我还是希望能看到这样的事情,没有任何挂钩黑客:

#+EXPORT: org-reveal-export-to-html 
+0

我已经更新了我的答案,它允许您指定用于导出文件的函数 – 2014-02-14 10:22:02

+0

谢谢,您的答案就是我正在寻找的答案。 – theldoria

+0

我很高兴它帮助你,只是注意确保变量名是唯一的,否则可能会导致冲突。我忘了照顾它,对不起会更新答案 – 2014-02-14 10:30:31