Loading ...
Sorry, an error occurred while loading the content.

multiple syntaxes in one file

Expand Messages
  • David Berg
    I m starting a new program and am planning on writing it as a literate program. For those who don t know, a literate program is one where the documentation and
    Message 1 of 3 , Apr 2, 2006
    • 0 Attachment
      I'm starting a new program and am planning on writing it as a literate
      program.

      For those who don't know, a literate program is one where the
      documentation and code are interspersed so that the code can read like
      a book. As plain text doesn't allow for much formating a markup
      language such as HTML or Tex/Latex is used for the documentation.

      So I have a file where HTML and C++ are mixed together which I would
      like to have the html and c++ syntax files apply to the html and c++
      blocks respectively. HTML blocks are marked by an '@' followed by a
      space or newline and c++ blocks are marked by a line containing only
      the text "<<code block>>=".

      How can I go about making this work?

      Thanks.

      --Dave
    • Charles E Campbell Jr
      ... Here s how I embed perl in vim script files: (taken from syntax/vim.vim) [-- perl --] {{{3 if (has( perl ) || g:vimembedscript) &&
      Message 2 of 3 , Apr 6, 2006
      • 0 Attachment
        David Berg wrote:

        >I'm starting a new program and am planning on writing it as a literate
        >program.
        >
        >For those who don't know, a literate program is one where the
        >documentation and code are interspersed so that the code can read like
        >a book. As plain text doesn't allow for much formating a markup
        >language such as HTML or Tex/Latex is used for the documentation.
        >
        >So I have a file where HTML and C++ are mixed together which I would
        >like to have the html and c++ syntax files apply to the html and c++
        >blocks respectively. HTML blocks are marked by an '@' followed by a
        >space or newline and c++ blocks are marked by a line containing only
        >the text "<<code block>>=".
        >
        >How can I go about making this work?
        >
        >
        Here's how I embed perl in vim script files: (taken from syntax/vim.vim)

        " [-- perl --] {{{3
        if (has("perl") || g:vimembedscript) &&
        filereadable(expand("<sfile>:p:h")."/perl.vim")
        unlet! b:current_syntax
        syn include @vimPerlScript <sfile>:p:h/perl.vim
        syn region vimPerlRegion matchgroup=vimScriptDelim
        start=+pe\%[rl]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimPerlScript
        syn region vimPerlRegion matchgroup=vimScriptDelim
        start=+pe\%[rl]\s*<<\s*$+ end=+\.$+ contains=@vimPerlScript
        endif

        You shold be able to do something similar.

        Regards,
        Chip Campbell
      • Russell Bateman
        I m confused by David s example because it involves vim script. Now, confusion comes easily and is an enduring state with me, but I m interested in what Chip
        Message 3 of 3 , Apr 6, 2006
        • 0 Attachment
          I'm confused by David's example because it involves vim script. Now,
          confusion comes easily and is an enduring state with me, but I'm
          interested in what Chip comes up with as soon as he applies what David
          is suggesting here.

          Thanks,
          Russ Bateman


          Charles E Campbell Jr wrote:
          > David Berg wrote:
          >
          >> I'm starting a new program and am planning on writing it as a literate
          >> program.
          >>
          >> For those who don't know, a literate program is one where the
          >> documentation and code are interspersed so that the code can read like
          >> a book. As plain text doesn't allow for much formating a markup
          >> language such as HTML or Tex/Latex is used for the documentation.
          >>
          >> So I have a file where HTML and C++ are mixed together which I would
          >> like to have the html and c++ syntax files apply to the html and c++
          >> blocks respectively. HTML blocks are marked by an '@' followed by a
          >> space or newline and c++ blocks are marked by a line containing only
          >> the text "<<code block>>=".
          >>
          >> How can I go about making this work?
          >>
          >>
          > Here's how I embed perl in vim script files: (taken from
          > syntax/vim.vim)
          >
          > " [-- perl --] {{{3
          > if (has("perl") || g:vimembedscript) &&
          > filereadable(expand("<sfile>:p:h")."/perl.vim")
          > unlet! b:current_syntax
          > syn include @vimPerlScript <sfile>:p:h/perl.vim
          > syn region vimPerlRegion matchgroup=vimScriptDelim
          > start=+pe\%[rl]\s*<<\s*\z(.*\)$+ end=+^\z1$+ contains=@vimPerlScript
          > syn region vimPerlRegion matchgroup=vimScriptDelim
          > start=+pe\%[rl]\s*<<\s*$+ end=+\.$+ contains=@vimPerlScript
          > endif
          >
          > You shold be able to do something similar.
          >
          > Regards,
          > Chip Campbell
          >
          >
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.