使用 .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 代码块中使用下划线时才会出现问题。我收到错误“缺少 $ 已插入”,它指向 R 代码中的“_”。我如何告诉 emacs 这是 R 代码,应该忽略它?