2014-02-14 83 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