Code chunk fontification in Emacs noweb mode?

811 Views Asked by At

In noweb mode, I would like to make the doc chunks and code chunks easier to distinguish. I'm already using font-lock-mode, but it applies the same face to strings in R and strings in tex, so doesn't distinguish the code and doc chunks very well.

For example, a slightly different background color for the code chunks.

One possibility would be to define a new face for the minor mode of the code chunk, but then that face would also apply when editing a buffer in that mode.

Another possibility would be to create an overlay for the code chunks.

Also, somewhat related, org-mode can be configured to use different background colors for source blocks.

Update: I now use polymode to achive this.

3

There are 3 best solutions below

0
On

You can use noweb-font-lock-mode from ESS to get syntax highlighting for both code and documentation chunks. I'd recommend you also use noweb-mode from ESS too, because it has some improvements.

0
On

One option would be mmm-mode, with which you can define regions that are in a different mode -- it also applies a face to the entire sub-mode region, which you can use to easily distinguish those regions within the parent file.

I personally use this for Ruby within IRB, Javascript and CSS within HTML etc. There's an example for javascript in my emacs config.

0
On

The MuMaMo extensions allows different rules for different parts of the file. Getting the nXhtml package will give you the mode and I think you can configure it to do what you want.