[patch] Dynamic folding in 2html.vim output

88 views
Skip to first unread message

Benjamin Fritz

unread,
Jan 17, 2009, 2:40:17 AM1/17/09
to vim_dev
A patch is attached for the behavior discussed in these threads:
http://groups.google.com/group/vim_use/browse_thread/thread/8532e7236f113ab7/0b508a50b767a1e1
http://groups.google.com/group/vim_dev/browse_thread/thread/56d5debad6f5f351/44cc7eb3b4787440

Also attached is an example of the output when used on the two
attached patches. I used html_dynamic_folds on the 2html.vim patch,
and additionally html_no_foldcolumn and html_hover_unfold on the
syntax.txt patch.

As discussed in the vim_dev thread above, it may be desirable to be
able to do away with the foldcolumn in the html output, but it was
hard to determine what to do to allow folds to open and close without
it. Rather than making the javascript and markup needlessly complex, I
just used CSS 2.0 :hover selection to open folds on hover if desired
(though normally, only CSS 1.0 support is required, and a fallback is
inserted for IE6).

Please comment!

-- Ben

2html.vim.diff
syntax.txt.diff
2html.vim.diff.html
syntax.txt.diff.html

Dominique Pelle

unread,
Jan 17, 2009, 3:48:39 AM1/17/09
to vim...@googlegroups.com
Benjamin Fritz wrote


That's very nice and useful. Thanks.
One minor comment. In syntax.txt, I read:

If you use this option, it would not be possible to open the folds

I think it should be...

If you used this option, it would not be possible to open the folds

:s/use/&d/

-- Dominique

Dominique Pelle

unread,
Jan 17, 2009, 6:57:08 AM1/17/09
to vim...@googlegroups.com
Benjamin Fritz:


I can't apply the patch cleanly unfortunately. There are conflicts.

2html.vim.diff is a patch from a version last changed on "2008 Dec 03"

But...

2html.vim in CVS was last changed on "2008 Jul 17" (too old)
2html.vim from ftp contains a version changed on "2009 Jan 13" (too new)

Regards
-- Dominique

Tony Mechelynck

unread,
Jan 17, 2009, 7:56:25 AM1/17/09
to vim...@googlegroups.com

Another possibility is:

If you use this version, it won't be possible to open the folds.

...used...would not... makes it seem that no one would ever use the
option in question.

(For you Frenchmen, it's the same as between "si vous utilisiez cette
option, il serait impossible d'ouvrir les plis" vs. "si vous utilisez...
il sera...".


Best regards,
Tony.
--
Happiness, n.:
An agreeable sensation arising from contemplating the misery of
another.
-- Ambrose Bierce, "The Devil's Dictionary"

Ben Fritz

unread,
Jan 17, 2009, 10:54:57 AM1/17/09
to vim_dev


On Jan 17, 5:57 am, "Dominique Pelle" <dominique.pe...@gmail.com>
wrote:

>
> I can't apply the patch cleanly unfortunately. There are conflicts.
>
> 2html.vim.diff is a patch from a version last changed on "2008 Dec 03"
>
> But...
>
> 2html.vim in CVS was last changed on "2008 Jul 17"  (too old)
> 2html.vim from ftp contains a version changed on "2009 Jan 13"  (too new)
>

Rats, I thought I was safe. I started editing in late December.

I have tried in the past to find the runtime files in ftp...where
would I find the latest one to update my patch?

Alternatively, I could use SVN if the runtime files are up-to-date in
there. It looks like the ones in CVS are not. I would probably prefer
this method, actually.

-- Ben

Ben Fritz

unread,
Jan 17, 2009, 10:58:19 AM1/17/09
to vim_dev


On Jan 17, 9:54 am, Ben Fritz <fritzophre...@gmail.com> wrote:

> > I can't apply the patch cleanly unfortunately. There are conflicts.
>

>
> I could use SVN if the runtime files are up-to-date in
> there. It looks like the ones in CVS are not. I would probably prefer
> this method, actually.
>

Thouh, I would need someone to tell me where to find the latest
runtime files in the huge tree in the repository. I've tried browsing
the SVN repo before, and it's a bit overwhelming for someone who's
never worked in it before.

Markus Heidelberg

unread,
Jan 17, 2009, 11:18:14 AM1/17/09
to vim...@googlegroups.com
Ben Fritz, 17.01.2009:

>
> On Jan 17, 5:57 am, "Dominique Pelle" <dominique.pe...@gmail.com>
> wrote:
>
> >
> > I can't apply the patch cleanly unfortunately. There are conflicts.
> >
> > 2html.vim.diff is a patch from a version last changed on "2008 Dec 03"
> >
> > But...
> >
> > 2html.vim in CVS was last changed on "2008 Jul 17"  (too old)
> > 2html.vim from ftp contains a version changed on "2009 Jan 13"  (too new)
> >
>
> Rats, I thought I was safe. I started editing in late December.
>
> I have tried in the past to find the runtime files in ftp...where
> would I find the latest one to update my patch?

Yes, on the FTP server.

> Alternatively, I could use SVN if the runtime files are up-to-date in
> there. It looks like the ones in CVS are not. I would probably prefer
> this method, actually.

SVN has the same content as CVS, i.e. older runtime files.

If you prefer the convenience of a version control system to get the
latest runtime files, you can also use one of my git trees. They are
kept simple and clear and won't add confusion.

http://repo.or.cz/w/vim_mainline.git
branch 'vim-runtime' for merely the latest runtime files
branch 'master' for vim sources + the latest runtime files
or
http://repo.or.cz/w/vim_extended.git
branch 'vim-with-runtime' is the same as 'master' from vim_mainline
Not as simple due to

Markus

Markus Heidelberg

unread,
Jan 17, 2009, 11:52:46 AM1/17/09
to vim...@googlegroups.com
Markus Heidelberg, 17.01.2009:

> http://repo.or.cz/w/vim_extended.git
> branch 'vim-with-runtime' is the same as 'master' from vim_mainline
> Not as simple due to

Oh, an unfinished sentence, while looking for an appropriate word in the
dictionary and digressing. What I wanted to say is, that there are more
branches, so it seems naturally not as simple.

Markus

Dominique Pelle

unread,
Jan 17, 2009, 11:59:52 AM1/17/09
to vim...@googlegroups.com
Ben Fritz wrote


Try: rsync -avzcP --delete --exclude="dos" --exclude="spell"
ftp.nluug.nl::Vim/runtime/ .

But I personally do that in another directory than my main vim
directory because it not only pulls new files but also delete files.

I don't know why runtime files are not updated in CVS like source
files. It would be more convenient. Or maybe in a separate CVS
module if runtime files are deemed too large.

-- Dominique

Benjamin Fritz

unread,
Jan 17, 2009, 12:23:45 PM1/17/09
to vim_dev
New patches attached, against the latest files on the FTP server.

Also fixed a bug due to an interesting quirk of the default fold text:

+-- 35 for 2-digit line counts
+--200 for 3 or more digits in the line count

2html.vim.diff
syntax.txt.diff

Antony Scriven

unread,
Jan 17, 2009, 8:56:15 PM1/17/09
to vim...@googlegroups.com
On Sat, Jan 17, 2009 at 12:56 PM, Tony Mechelynck
<antoine.m...@gmail.com> wrote:

> On 17/01/09 09:48, Dominique Pelle wrote:
> > Benjamin Fritz wrote
> >
> > > A patch is attached for the behavior discussed in
> > > these threads:
> > > http://groups.google.com/group/vim_use/browse_thread/thread/8532e7236f113ab7/0b508a50b767a1e1
> > > http://groups.google.com/group/vim_dev/browse_thread/thread/56d5debad6f5f351/44cc7eb3b4787440
> > >

> > > [...]


> >
> > That's very nice and useful. Thanks.
> > One minor comment. In syntax.txt, I read:
> >
> > If you use this option, it would not be possible to
> > open the folds
> >
> > I think it should be...
> >
> > If you used this option, it would not be possible to
> > open the folds
> >
> > :s/use/&d/
> >
> > -- Dominique
>
> Another possibility is:
>
> If you use this version, it won't be possible to
> open the folds.

(s/version/option/ but this is irrelevant to the discussion.)

> ...used...would not... makes it seem that no one would
> ever use the option in question.

Yes, this is better, but it should be

If you :let html_no_foldcolumn = 1 it
won't be possible to open the folds unless
you use :let html_hover_unfold = 1

or whatever the correct usage is. Alternatively remove
the sentence altogether and say:

:let html_hover_unfold = 1 will use CSS 2.0 to
allow a user to open a fold by hovering the mouse
pointer over it. This is useful when using
:let html_no_foldcolumn = 1.

--Antony

Ben Fritz

unread,
Jan 17, 2009, 9:47:32 PM1/17/09
to vim_dev


On Jan 17, 7:56 pm, Antony Scriven <adscri...@gmail.com> wrote:

>
> Yes, this is better, but it should be
>
>    If you :let html_no_foldcolumn = 1 it
>    won't be possible to open the folds unless
>    you use :let html_hover_unfold = 1
>
> or whatever the correct usage is. Alternatively remove
> the sentence altogether and say:
>
>    :let html_hover_unfold = 1 will use CSS 2.0 to
>    allow a user to open a fold by hovering the mouse
>    pointer over it. This is useful when using
>    :let html_no_foldcolumn = 1.
>

Actually, I was trying to say that html_no_foldcolumn will
automatically set html_hover_unfold. How's this?

----

Using this option, there will be no foldcolumn available to open the
folds in
the HTML. For this reason, another option is provided:
html_hover_unfold.
Enabling this option will use CSS 2.0 to allow a user to open a fold
by
hovering the mouse pointer over it. Note that old browsers (notably
Internet
Explorer 6) will not support this feature. Browser-specific markup
for IE6 is
included to fall back to the normal CSS1 code so that the folds show
up
correctly for this browser, but they will not be openable without a
foldcolumn. Note that using html_hover_unfold will allow modern
browsers with
disabled javascript to view closed folds. To use this option, use: >
:let html_hover_unfold

Setting html_no_foldcolumn with html_dynamic_folds will automatically
set
html_hover_unfold, because otherwise the folds wouldn't be dynamic.

Yue Wu

unread,
Jan 20, 2009, 4:01:12 AM1/20/09
to vim...@googlegroups.com

Thank you Benjamin! Why not just put a completed version here? It's not so
convenient to install it on windows.

--
Regards,
Van.

Markus Heidelberg

unread,
Jan 21, 2009, 7:47:21 PM1/21/09
to vim...@googlegroups.com
Dominique Pelle, 17.01.2009:
>
> Ben Fritz wrote

>
> > Thouh, I would need someone to tell me where to find the latest
> > runtime files in the huge tree in the repository. I've tried browsing
> > the SVN repo before, and it's a bit overwhelming for someone who's
> > never worked in it before.
>
>
> Try: rsync -avzcP --delete --exclude="dos" --exclude="spell"
> ftp.nluug.nl::Vim/runtime/ .
>
> But I personally do that in another directory than my main vim
> directory because it not only pulls new files but also delete files.
>
> I don't know why runtime files are not updated in CVS like source
> files.

Me neither. I think the problem is that Vim doesn't have a repository
with useful history. The only history available are the bugfixes from
the official patches. The CVS/SVN repo seems rather to be intended for
ease of updating the sources than having a history.

> It would be more convenient.

If you need convenience, try the 'master' branch from
http://repo.or.cz/w/vim_mainline.git

Markus

Benjamin Fritz

unread,
Jan 22, 2009, 10:52:09 PM1/22/09
to vim...@googlegroups.com
On Tue, Jan 20, 2009 at 3:01 AM, Yue Wu <van...@gmail.com> wrote:

> Thank you Benjamin! Why not just put a completed version here? It's not so
> convenient to install it on windows.
>

Indeed, why not? I really don't see it done very often (or at all),
but I've attached the full script. I've also attached new patches to
fix the text in the help file as discussed, and to make the 2html
script not over-ride user-defined variables (it stores its own local
copy instead). I think these are ready for inclusion, unless the
version has changed under my nose again. I'll check that tomorrow.

To the list: is there a reason not to post full files? I will
certainly avoid it in the future if it is frowned upon for good
reason...

syntax.txt
2html.vim.diff
syntax.txt.diff
2html.vim

Yue Wu

unread,
Jan 22, 2009, 11:08:06 PM1/22/09
to vim...@googlegroups.com
On Fri, 23 Jan 2009 11:52:09 +0800, Benjamin Fritz wrote:

> On Tue, Jan 20, 2009 at 3:01 AM, Yue Wu <van...@gmail.com> wrote:
>
>> Thank you Benjamin! Why not just put a completed version here? It's not
>> so
>> convenient to install it on windows.
>>
>
> Indeed, why not? I really don't see it done very often (or at all),
> but I've attached the full script. I've also attached new patches to
> fix the text in the help file as discussed, and to make the 2html
> script not over-ride user-defined variables (it stores its own local
> copy instead). I think these are ready for inclusion, unless the
> version has changed under my nose again. I'll check that tomorrow.
>

Hi, Benjamin,

I don't know if I use it correctly? I throw the 2html.vim into
~/.vim/syntax, then open a file that has folding enabled, then use 2html
to output the html:

source ~/.vim/syntax/2html.vim

But seems it doesn't work.

--
Regards,
Van.

Benjamin Fritz

unread,
Jan 23, 2009, 9:49:24 AM1/23/09
to vim...@googlegroups.com
On Thu, Jan 22, 2009 at 10:08 PM, Yue Wu <van...@gmail.com> wrote:
>
> I don't know if I use it correctly? I throw the 2html.vim into
> ~/.vim/syntax, then open a file that has folding enabled, then use 2html
> to output the html:
>
> source ~/.vim/syntax/2html.vim
>
> But seems it doesn't work.
>

That's the right way to use it. Make sure you do this first:

:let html_dynamic_folds = 1

Otherwise you will just get the default behavior.

You should also be able to use the TOhtml command.

Yue Wu

unread,
Jan 23, 2009, 10:13:40 PM1/23/09
to vim...@googlegroups.com

Awesome! Thank you!

--
Regards,
Van.

Ben Fritz

unread,
Feb 9, 2009, 6:29:56 PM2/9/09
to vim_dev
I just realize my patch doesn't handle the g:html_no_pre option. I'll
make another patch in the next day or two to also handle this option
(I notice I'll need to get the latest from FTP again).

Bram, once I fix the handling of g:html_no_pre, is there a reason not
to include this in the official script?

Benjamin Fritz

unread,
Feb 10, 2009, 12:01:31 AM2/10/09
to vim_dev, Bram Moolenaar

New patches attached, based off the latest from FTP, and accounting
for g:html_no_pre.

2html.vim.diff
syntax.txt.diff

Bram Moolenaar

unread,
Feb 10, 2009, 1:55:11 PM2/10/09
to Ben Fritz, vim_dev

Ben Fritz wrote:

I haven't looked in detail at the changes yet. I'm first awaiting
comments. If the change looks like it won't break anything when folding
is off it should be OK to include.

--
hundred-and-one symptoms of being an internet addict:
69. Yahoo welcomes you with your own start page

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ download, build and distribute -- http://www.A-A-P.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Ben Fritz

unread,
Feb 12, 2009, 12:54:46 PM2/12/09
to vim_dev


On Feb 9, 11:01 pm, Benjamin Fritz <fritzophre...@gmail.com> wrote:

>
> New patches attached, based off the latest from FTP, and accounting
> for g:html_no_pre.
>
>  2html.vim.diff
> 38KViewDownload
>

I just realized some of the comments in the code are incorrect. The
code works, but the comments regarding the removal of "duplicate"
folds no longer apply (they are left over from an earlier attempt that
didn't quite work). I'll clean it up and attach another patch tonight
or tomorrow to fix the comments, but the code should be fine as-is.

Benjamin Fritz

unread,
Feb 13, 2009, 12:23:25 AM2/13/09
to vim_dev
On Thu, Feb 12, 2009 at 11:54 AM, Ben Fritz wrote:
>
> I just realized some of the comments in the code are incorrect. The
> code works, but the comments regarding the removal of "duplicate"
> folds no longer apply (they are left over from an earlier attempt that
> didn't quite work). I'll clean it up and attach another patch tonight
> or tomorrow to fix the comments, but the code should be fine as-is.

This should do it. I also fixed a minor bug in the generated html when
multiple folds open on the same line and using g:html_hover_unfold
with a fold column.

Sorry this took so many tries to get right...I think this should be
it, though. Please try it out and let me know if I missed anything or
if there's something you don't like!

2html.vim.diff
Reply all
Reply to author
Forward
0 new messages