使用.Rnw文件在emacs中突出显示语法

时间:2013-04-10 12:10:03

标签: emacs latex sweave ess

使用.Rnw文件时,带有ess的emacs会突出显示紫色的R代码块。这很好,但我遇到的问题是在R代码之后,一切都还是紫色的!

有些人说过,一旦你以后再加入更多的R代码就会消失,但这对我没用。

例如,

This is some text
<<>>=
This is some R-code, its in purple
@
This is some more text, but its still in purple!

这是我的.emacs文件

(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq TeX-PDF-mode t)


(add-hook 'LaTeX-mode-hook 'flyspell-mode)

(require 'ess-site)
(require 'whitespace)
(setq whitespace-style '(face lines-tail))

(setq backup-by-copying t
      backup-directory-alist '(("." . "~/.emacsBkups"))
      delete-old-versions t
      kept-new-versions 5
      kept-old-versions 2
      version-control t)

;; does not use white-space mode in latex-mode
(define-global-minor-mode white-space-no-latex-mode whitespace-mode
  (lambda ()
    (when (not (memq major-mode
             (list 'latex-mode)))
      (whitespace-mode))))

(white-space-no-latex-mode)
(ess-toggle-underscore nil)

(setq TeX-view-program-list '(("Evince" "evince --page-index=%(outpage) %o")))
(setq TeX-view-program-selection '((output-pdf "Evince")))



;; Make TeX and RefTex aware of Snw and Rnw files
(setq reftex-file-extensions
      '(("Snw" "Rnw" "nw" "tex" ".tex" ".ltx") ("bib" ".bib")))
(setq TeX-file-extensions
      '("Snw" "Rnw" "nw" "tex" "sty" "cls" "ltx" "texi" "texinfo"))

;; Lets you do 'C-c C-c Sweave' from your Rnw file
(defun emacsmate-add-Sweave ()
  (add-to-list 'TeX-command-list
           '("Sweave" "R CMD Sweave %s"
         TeX-run-command nil (latex-mode) :help "Run Sweave") t)
  (add-to-list 'TeX-command-list
           '("LatexSweave" "%l %(mode) %s"
         TeX-run-TeX nil (latex-mode) :help "Run Latex after Sweave") t)
  (setq TeX-command-default "Sweave"))

(add-hook 'Rnw-mode-hook 'emacsmate-add-Sweave)

我想这与我的.emacs文件有关。但我对lisp了解不足以找出冲突发生的地方......

编辑我找到了罪魁祸首......只有当我在R代码块中使用下划线时才会出现问题。我收到错误“missing $ inserted”,它指向R代码中的“_”。我如何告诉emacs这是R代码,应该忽略它?

0 个答案:

没有答案