No edit summary |
|||
(One intermediate revision by one other user not shown) | |||
Line 34: | Line 34: | ||
String variable declaration (in the .vimrc file) does not need escapes for the double quotes (VIM 7.3), so the correct variable declarations would be: |
String variable declaration (in the .vimrc file) does not need escapes for the double quotes (VIM 7.3), so the correct variable declarations would be: |
||
+ | <pre> |
||
let noweb_backend = "tex" |
let noweb_backend = "tex" |
||
let noweb_language = "cpp" |
let noweb_language = "cpp" |
||
+ | </pre> |
||
+ | |||
+ | ==noweb syntax with vim-latexsuite== |
||
+ | If used as directed, the noweb filetype prevents latex-suite from being loaded. However it is possible to have different <code>filetype</code> and <code>syntax</code> like this: |
||
+ | |||
+ | <pre> |
||
+ | autocmd BufRead,BufNewFile *.Rnw set filetype=tex syntax=noweb |
||
+ | </pre> |
||
+ | |||
+ | Note that the order in which you set <code>filetype</code> and <code>syntax</code> is important. |
Latest revision as of 02:14, 10 October 2013
Use this page to discuss script 3038 noweb: syntax file with separate highlighting for documentation and code
- Add constructive comments, bug reports, or discuss improvements (see the guideline).
- Do not document the script here (the author should do that on vim.org).
- This page may be out of date: check the script's vim.org page above, and its release notes.
Language and Backend from filename[]
To set noweb_language and noweb_backend based on filename (e.g. foo.tex.cpp.nw is a C++/TeX noweb file):
au BufEnter *.*.*.nw set filetype=noweb | exe "let noweb_language = \"" . expand("%:r:e") . "\"" | exe "let noweb_backend = \"" . expand("%:r:r:e") . "\""
To allow a default backend (e.g. foo.c.nw is a C noweb file with the default—here TeX—backend):
let noweb_backend="tex" au BufEnter *.*.nw set filetype=noweb | exe "let noweb_language = \"" . expand("%:r:e") . "\""
Or, combining these and a default language {{script_id=3038]}}:
let noweb_language="c" let noweb_backend="tex" au BufEnter *.nw set filetype=noweb au BufEnter *.*.nw exe "let noweb_language = \"" . expand("%:r:e") . "\"" au BufEnter *.*.*.nw exe "let noweb_backend = \"" . expand("%:r:r:e") . "\""
NOTE: backend and language in the filename are unmodified for noweb_backend
and noweb_language
, which in turn (currently) uses them unmodified to create filenames syntax/noweb_backend.vim
and syntax/noweb_langauge.vim
, so to use the above unmodified in your .vimrc, name files to match the vim syntax file names (rather than the language's typical extension if it differs)--it might be better to create special cases; for example, to use syntax/perl.vim for *.pl.nw (and *.*.pl.nw) files, add the following after the code listed above.
au BufEnter *.pl.nw let noweb_language="perl"
There may be a way to make this better match Vim's filetype detection—perhaps by actually using it with a temporary buffer.
Comments[]
Instead of "^@$" for detecting end of code chunks I suggest you use "^@\($\| \)" (that is, @ at beginning of line followed by either end of line or space character). That is how beginning of comment blocks is defined in the noweb man page. %def's, for example, are written in the same line as the @ that ends the code chunk.
String variable declaration (in the .vimrc file) does not need escapes for the double quotes (VIM 7.3), so the correct variable declarations would be:
let noweb_backend = "tex" let noweb_language = "cpp"
noweb syntax with vim-latexsuite[]
If used as directed, the noweb filetype prevents latex-suite from being loaded. However it is possible to have different filetype
and syntax
like this:
autocmd BufRead,BufNewFile *.Rnw set filetype=tex syntax=noweb
Note that the order in which you set filetype
and syntax
is important.