Wikia

Vim Tips Wiki

Script:3038

Talk0
1,610pages on
this wiki
Revision as of 11:17, November 22, 2012 by 128.214.202.248 (Talk)

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"

Around Wikia's network

Random Wiki