[ESS] Highlighting in Rnw/noweb-mode

Kevin Wright kw.statr at gmail.com
Wed Mar 11 14:38:16 CET 2009


I have my configuration highlight the first and last lines of a code
chunk.  Note: Consolas is a windows Vista font.

Add this to .emacs

;This must be done before ess-noweb is loaded
;; (C. Beleites) 2 new faces for highlighting the start lines of chunks
; http://www.nabble.com/font-lock-with-Sweave-noweb-tt17133613.html
(defface noweb-font-lock-code-chunk-face
  '((t (:family "Consolas" :height 1 :background "#262644")))
  "Face to highlight noweb code chunks")
(defface noweb-font-lock-doc-chunk-face
  '((t (:family "Consolas" :height 1 :background "#263326")))
  "Face to highlight noweb doc chunks")
(defvar noweb-font-lock-code-chunk-face 'noweb-font-lock-code-chunk-face
  "Face to use to highlight the first line of each code chunk (i.e. <<>>=)")
(defvar noweb-font-lock-doc-chunk-face 'noweb-font-lock-doc-chunk-face
  "Face to use to highlight the first line of each doc chunk (i.e. @)")

In ess/lisp/noweb-font-lock-mode.el Change this:

append font-lock-keywords
		  '(("\\(\\[\\[\\)\\([^]]*\\]*\\)\\(\\]\\]\\|\\$\\)"
		     (1 font-lock-reference-face prepend )
		     (2 font-lock-keyword-face prepend)
		     (3 font-lock-reference-face prepend))
		    ("^[ \t\n]*\\(<<\\)\\([^>]*\\)\\(>>=?\\)"
		     (1 font-lock-reference-face  prepend )
		     (2 font-lock-keyword-face prepend)
		     (3 font-lock-reference-face prepend))
		    ("^@[ \t\n]+"
		     (0 font-lock-reference-face prepend )))))

To

;; C. Beleites: changed keywords for highlighting the first lines
;; 	  (append font-lock-keywords
;; 		  '(("\\(\\[\\[\\)\\([^]]*\\]*\\)\\(\\]\\]\\|\\$\\)"
;; 		     (1 font-lock-reference-face prepend )
;; 		     (2 font-lock-keyword-face prepend)
;; 		     (3 font-lock-reference-face prepend))
;; 		    ("^[ \t\n]*\\(<<\\)\\([^>]*\\)\\(>>=?\\)"
;; 		     (1 font-lock-reference-face  prepend )
;; 		     (2 font-lock-keyword-face prepend)
;; 		     (3 font-lock-reference-face prepend))
;; 		    ("^@[ \t\n]+"
;; 		     (0 font-lock-reference-face prepend )))))
          (append font-lock-keywords
                  '(("\\(\\[\\[\\)\\([^]]*\\]*\\)\\(\\]\\]\\|\\$\\)"
                     (1 font-lock-reference-face prepend)
                     (2 font-lock-keyword-face prepend)
                     (3 font-lock-reference-face prepend))
                    ("^[ \t\n]*<<\\([^>]+\\)>>"        ;; reuse code chunk
                     (1 font-lock-keyword-face  prepend ))
                    ("^\\(<<\\)\\([^>]*\\)\\(>>=\\)\\(\\(?:[
\t][^\n]*\\)?\\)[\n]" ;; code chunk start
                     (0 noweb-font-lock-code-chunk-face prepend )
                     (1 font-lock-reference-face  prepend )
                     (2 font-lock-keyword-face prepend)
                     (3 font-lock-reference-face prepend)
                     (4 font-lock-comment-face prepend))
                    ("^@\\(\\(?:[ \t][^\n]*\\)?\\)[\n]" ;; doc chunk start
                     (0 font-lock-reference-face prepend )
                     (0 noweb-font-lock-doc-chunk-face prepend )
                     (1 font-lock-comment-face prepend)
                     ))))

Good luck,

Kevin Wright

On Mon, Mar 9, 2009 at 4:48 AM, Moritz Gerstung
<moritz.gerstung at bsse.ethz.ch> wrote:
> Hi,
> I'm looking for a possibility to get the background of the code chunks in
> noweb-mode (Rnw-mode, in particular) a little colored so I can distinguish
> them more clearly from the remaining text. I had a look at
> noweb-font-lock-mode.el, but couldn't really figure out how to manage this.
> (Actually, I do not understand much of lisp..).
> Thanks for any help,
> Moritz
>
> ETH Zurich
> Moritz Gerstung
> Computational Biology Group
> Dept. of Biosystems Science and Engineering, D-BSSE
> Mattenstrasse 26
> 4058 Basel
> SWITZERLAND
>
> moritz.gerstung[a]bsse.ethz.ch
> +41 (0) 61 38 73193 phone
> www.bsse.ethz.ch/cbg
>
> ______________________________________________
> ESS-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help
>




More information about the ESS-help mailing list