Domanda

I am trying to set some key bindings for 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.

While there is a LaTeX-mode-hook, I don't see something like `ess-noweb-mode-hook.

È stato utile?

Soluzione 2

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))).

If we are outside chunks of an ESS buffer this is true: 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"))

Altri suggerimenti

ess-noweb mode is just a wrapper and it loads latex-mode and R-mode in corresponding chunks. So if you define a shortcut in latex-mode-map it should be available in .rnw buffers as well.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top