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

54679Re: preserving folding during :TOhtml?

Expand Messages
  • Antony Scriven
    Nov 2, 2004
    • 0 Attachment
      Peoter Veliki wrote:

      > I'd like to use :TOhtml to generate and HTML file of my
      > source code, but I'd like to be able to set the fold
      > levels in my code and and then convert it to HTML without
      > expanding the folds. For example, with the folds set tot
      > he maximum (zM) the file looks like an API with a list of
      > the functions and a description of each. I'd like to
      > generate an HTML file that preserves this view. Can this
      > be done?
      > If not, anyone figured out a good hack for doing this,
      > other than say doing a series of 'Print Screens'? (I
      > tried that, it was a nightmare.)

      I think I posted something similar to the mailing list some
      time ago. I'm now convinced it is full to the brim with
      bugs. I've not really tested this version either, so you'd
      have to do that. It seemed to work on a very short example,
      but who knows?

      You pass the function two line numbers and it returns those
      lines and all in between as a string, exactly as it is
      displyed in Vim.

      fun Text_as_displayed(line1, line2)

      let line1 = a:line1 < 1 ? 1 : a:line1
      let line2 = a:line2 > line('$') ? line('$') : a:line2
      let lines = ''
      let l = line1

      while l <= line2

      let fend = foldclosedend(l)
      let fstart = foldclosed(l)

      if fstart == l || fend == -1
      let lines = lines . "\n" . getline(l)
      let l = l + 1
      elseif fend == line('$')
      exe fend
      norm! j
      let l = line('.')


      return strpart(lines,1)

      E.g. :let @a = Text_as_displayed(1,999)

      Then you can put the text in another buffer. Or you could
      wrap the function up in a command to make it more convenient
      to use. You can then do :TOhtml on that buffer. You may lose
      the nice syntax highlighting with this approach, however.

      > What would be really cool is if when it generated the
      > HTML file, it created a whole set of HTML files that were
      > all linked, where instead of opening a fold, you'd click
      > on a hyperlink that shows that opens another HTML page
      > with the contents of that fold, and so on and so fourth.
      > That would be extremely slick. Project!

      You didn't mention what language you are writing your code
      in. Tools to do this may already exist. I'd suggest using
      Google before coming up with a Vim way to do this. If you
      do need to use Vim maybe my function will be a start.

    • Show all 11 messages in this topic