[R] Can't get Sweave syntax highlighting with Emacs

Waichler, Scott R Scott.Waichler at pnl.gov
Thu Nov 13 23:54:53 CET 2003


I can't get Emacs to automatically do syntax highlighting of 
Sweave files.  I have followed Friedrich's suggestion for code
to insert into my .emacs file.  The complete section from my .emacs
file is given below.  When I load a *.Snw file, font is white until I press
M-x, then the first code and document chunks get highlighted, but not
the rest of the file.  Latex and Noweb menus are active, but not ESS,
and there is no switching of modes as I move the pointer to different
types of chunks.

; -------------------------------------------------------------
; Emacs Speaks Statistics
; mode for R
; -------------------------------------------------------------
(load "/home/waichler/emacs/ess-5.1.19/lisp/ess-site")

; ESS  "emacs speaks statistics" SRW 2-19-01
(autoload 'ess-mode "ess" "ess major mode" t)
(autoload 'ess-noweb-mode "ess" "ess noweb mode" t)
(autoload 'ess-noweb-make-buffer "ess" "open a buffer in R mode" t)
(autoload 'ess-make-buffer "ess" "open a buffer in R mode" t)
(setq auto-mode-alist (append '(("\\.R$" . ess-mode)) auto-mode-alist))
(setq auto-mode-alist (append '(("\\.S$" . ess-mode)) auto-mode-alist))
(setq auto-mode-alist (append '(("\\.sp$" . ess-mode)) auto-mode-alist))
(global-set-key [(f10)] 'ess-make-buffer)    
(add-hook 'ess-mode-hook 'turn-on-font-lock)         

; Sweave mode
(defun Rnw-mode ()
  (require 'ess-noweb)
  (noweb-mode)
  (if (fboundp 'R-mode)
      (setq noweb-default-code-mode 'R-mode)))
(add-to-list 'auto-mode-alist '("\\.Rnw\\'" . Rnw-mode))
(add-to-list 'auto-mode-alist '("\\.Snw\\'" . Rnw-mode))
(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"))


Scott

Scott Waichler, Senior Research Scientist
Pacific Northwest National Laboratory
MSIN K9-36
P.O. Box 999
Richland, WA   99352    USA
509-372-4423 (voice)
509-372-6089 (fax)
scott.waichler at pnl.gov
http://hydrology.pnl.gov




More information about the R-help mailing list