Reputation: 378
I'm using org-mode in emacs together with ox-reveal. The latter defines the command org-reveal-export-to-html, which I would like to bind to a key for buffers with org files, which are presentations (so not for all org files).
So the question is: how can I define file local key bindings in org-mode?
What I currently have is this:
#+BEGIN_COMMENT
Local Variables:
eval: (local-set-key [f5] 'org-reveal-export-to-html)
End:
#+END_COMMENT
But imho this is not very elegant.
Upvotes: 2
Views: 1654
Reputation:
You can define a key only for org-mode by using org-defkey, basically add the following to your init file
(org-defkey org-mode-map [f5] 'org-reveal-export-to-html)
UPDATE
You can use file local variables.
(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)
The function export-with-reveal-or-html
if the variable export-with-reveal
has value t or there is a file 'reveal.js' relative to org file , if so it exports with reveal
or it falls back to default html export. You can specify a file to exported as reveal by adding the following to top of your org file
# -*- export-with-reveal: t -*-
UPDATE 2
You can also define arbitrary export function by doing using, file-local variables
(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)
Then at top of the file you can set the export function you want to use eg
# -*- export-fn: org-reveal-export-to-html -*-
Upvotes: 3
Reputation: 378
I came up with following solution, which exploits local variables hook hack and defines buffer lokal hook:
(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)))))
Then in org mode I add this:
#+BEGIN_COMMENT
Local Variables:
my-org-export: org-reveal-export-to-html
End:
#+END_COMMENT
Still I would love to see something like this, without any hook hacking:
#+EXPORT: org-reveal-export-to-html
Upvotes: 0