[英]emacs org-mode file local key binding
我正在emacs中使用org-mode和ox-reveal。 后者定义了org-reveal-export-to-html命令,我想将其绑定到具有org文件的缓冲区的键,该文件是演示文稿(并非针对所有org文件)。
所以问题是:如何在组织模式下定义文件本地键绑定?
我目前所拥有的是:
#+BEGIN_COMMENT
Local Variables:
eval: (local-set-key [f5] 'org-reveal-export-to-html)
End:
#+END_COMMENT
但是恕我直言,这不是很优雅。
您可以使用org-defkey定义仅用于org-mode的密钥,基本上将以下内容添加到您的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 -*-
我想出了以下解决方案,该解决方案利用局部变量钩子hack并定义了缓冲区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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.