[英]Emacs ESS key bindings
I am trying to set some key bindings for ESS. 我正在尝试为ESS设置一些键绑定。 I read one way is:
我读过一种方法是:
(eval-after-load "ess-mode"
'(define-key ess-mode-map (kbd "<f5>") 'myfunc))
But this works only inside the code blocks delimited by <<>>
, @
. 但这仅适用于由
<<>>
, @
分隔的代码块内部。
Another problem is that I would like to use the same key both for plain LaTeX mode (a .tex file) and LaTeX as part of Noweb (a .rnw file) and so I can't just define the key twice for LaTeX mode and ESS mode. 另一个问题是我想使用相同的密钥作为普通LaTeX模式(.tex文件)和LaTeX作为Noweb(.rnw文件)的一部分,因此我不能只为LaTeX模式定义密钥两次ESS模式。
While there is a LaTeX-mode-hook
, I don't see something like `ess-noweb-mode-hook
. 虽然有一个
LaTeX-mode-hook
,但我没有看到类似`ess-noweb-mode-hook
。
ess-noweb mode is just a wrapper and it loads latex-mode and R-mode in corresponding chunks. ess-noweb模式只是一个包装器,它在相应的块中加载latex模式和R模式。 So if you define a shortcut in
latex-mode-map
it should be available in .rnw buffers as well. 因此,如果您在
latex-mode-map
定义一个快捷方式,它也应该在.rnw缓冲区中可用。
After some trial and error, I found the answer. 经过一些反复试验,我找到了答案。
If we are in a LaTeX only buffer this is true: (and (equal (symbol-name major-mode) "latex-mode") (not ess-noweb-mode)))
. 如果我们在只有LaTeX的缓冲区中这是真的:(
(and (equal (symbol-name major-mode) "latex-mode") (not ess-noweb-mode)))
。
If we are outside chunks of an ESS buffer this is true: ess-noweb-mode
. 如果我们在ESS缓冲区的外部,这是真的:
ess-noweb-mode
。
You may be interested to the following convenience functions. 您可能对以下便利功能感兴趣。
;Check ESS related modes
(defun is-pure-latex ()
"The buffer is in LaTeX mode, but not in ESS mode."
(and (equal (symbol-name major-mode) "latex-mode") (not ess-noweb-mode)))
(defun is-ess ()
"The buffer is in ESS mode."
ess-noweb-mode)
(defun is-ess-doc ()
"The buffer is in ESS mode and insertion point is outside a chunk."
(and ess-noweb-mode (equal (symbol-name major-mode) "latex-mode")))
(defun is-ess-chunk ()
"The buffer is in ESS mode an insertion point is inside a chunk."
(equal (symbol-name major-mode) "ess-mode"))
(defun is-ess-inf ()
"The buffer is in inferior ESS mode"
(equal (symbol-name major-mode) "inferior-ess-mode"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.