Wikia

Vim Tips Wiki

Changes: Script:3038

Edit

Back to page

(`- Comments)
(Change <tt> to <code>, perhaps also minor tweak.)
Line 22: Line 22:
 
</pre>
 
</pre>
   
NOTE: backend and language in the filename are unmodified for <tt>noweb_backend</tt> and <tt>noweb_language</tt>, which in turn (currently) uses them unmodified to create filenames <tt>syntax/noweb_backend.vim</tt> and <tt>syntax/noweb_langauge.vim</tt>, 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.
+
NOTE: backend and language in the filename are unmodified for <code>noweb_backend</code> and <code>noweb_language</code>, which in turn (currently) uses them unmodified to create filenames <code>syntax/noweb_backend.vim</code> and <code>syntax/noweb_langauge.vim</code>, 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.
 
<pre>
 
<pre>
 
au BufEnter *.pl.nw let noweb_language="perl"
 
au BufEnter *.pl.nw let noweb_language="perl"
Line 30: Line 30:
 
==Comments==
 
==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.
+
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.

Revision as of 09:49, July 14, 2012

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.

Around Wikia's network

Random Wiki