diff options
author | Bram Moolenaar <Bram@vim.org> | 2010-01-06 20:54:52 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2010-01-06 20:54:52 +0100 |
commit | 5c73622a9066182ee4479fd7b3aa86e1825808c3 (patch) | |
tree | c92ed672cbb989fa3585387ebd4598f5bdfcc637 /runtime/syntax | |
parent | 8f3f58f2c361f1b7241128d9821f88d8a30aa066 (diff) |
Update runtime files.
Diffstat (limited to 'runtime/syntax')
107 files changed, 2145 insertions, 1251 deletions
diff --git a/runtime/syntax/2html.vim b/runtime/syntax/2html.vim index ee66bf644d..252a841f20 100644 --- a/runtime/syntax/2html.vim +++ b/runtime/syntax/2html.vim @@ -1,13 +1,18 @@ " Vim syntax support file " Maintainer: Bram Moolenaar <Bram@vim.org> -" Last Change: 2008 Jul 17 +" Last Change: 2009 Jul 14 " (modified by David Ne\v{c}as (Yeti) <yeti@physics.muni.cz>) " (XHTML support by Panagiotis Issaris <takis@lumumba.luc.ac.be>) " (made w3 compliant by Edd Barrett <vext01@gmail.com>) " (added html_font. Edd Barrett <vext01@gmail.com>) +" (dynamic folding by Ben Fritz <fritzophrenic@gmail.com>) " Transform a file into HTML, using the current syntax highlighting. +" this file uses line continuations +let s:cpo_sav = &cpo +set cpo-=C + " Number lines when explicitely requested or when `number' is set if exists("html_number_lines") let s:numblines = html_number_lines @@ -22,6 +27,37 @@ else let s:htmlfont = "monospace" endif +" make copies of the user-defined settings that we may overrule +if exists("html_dynamic_folds") + let s:html_dynamic_folds = 1 +endif +if exists("html_hover_unfold") + let s:html_hover_unfold = 1 +endif +if exists("html_use_css") + let s:html_use_css = 1 +endif + +" hover opening implies dynamic folding +if exists("s:html_hover_unfold") + let s:html_dynamic_folds = 1 +endif + +" dynamic folding with no foldcolumn implies hover opens +if exists("s:html_dynamic_folds") && exists("html_no_foldcolumn") + let s:html_hover_unfold = 1 +endif + +" ignore folding overrides dynamic folding +if exists("html_ignore_folding") && exists("s:html_dynamic_folds") + unlet s:html_dynamic_folds +endif + +" dynamic folding implies css +if exists("s:html_dynamic_folds") + let s:html_use_css = 1 +endif + " When not in gui we can only guess the colors. if has("gui_running") let s:whatterm = "gui" @@ -62,7 +98,7 @@ else endfun endif -if !exists("html_use_css") +if !exists("s:html_use_css") " Return opening HTML tag for given highlight id function! s:HtmlOpening(id) let a = "" @@ -150,6 +186,26 @@ function! s:CSS1(id) return a endfun +if exists("s:html_dynamic_folds") + + " compares two folds as stored in our list of folds + " A fold is "less" than another if it starts at an earlier line number, + " or ends at a later line number, ties broken by fold level + function! s:FoldCompare(f1, f2) + if a:f1.firstline != a:f2.firstline + " put it before if it starts earlier + return a:f1.firstline - a:f2.firstline + elseif a:f1.lastline != a:f2.lastline + " put it before if it ends later + return a:f2.lastline - a:f1.lastline + else + " if folds begin and end on the same lines, put lowest fold level first + return a:f1.level - a:f2.level + endif + endfunction + +endif + " Figure out proper MIME charset from the 'encoding' option. if exists("html_use_encoding") let s:html_encoding = html_use_encoding @@ -223,13 +279,13 @@ else let s:tag_close = '>' endif -" Cache html_no_pre incase we have to turn it on for non-css mode +" Cache html_no_pre in case we have to turn it on for non-css mode if exists("html_no_pre") let s:old_html_no_pre = html_no_pre endif -if !exists("html_use_css") - " Cant put font tags in <pre> +if !exists("s:html_use_css") + " Can't put font tags in <pre> let html_no_pre=1 endif @@ -251,9 +307,86 @@ if s:html_encoding != "" exe "normal! a<meta http-equiv=\"content-type\" content=\"text/html; charset=" . s:html_encoding . '"' . s:tag_close . "\n\e" endif -if exists("html_use_css") - exe "normal! a<style type=\"text/css\">\n<!--\n-->\n</style>\n\e" +if exists("s:html_use_css") + if exists("s:html_dynamic_folds") + if exists("s:html_hover_unfold") + " if we are doing hover_unfold, use css 2 with css 1 fallback for IE6 + exe "normal! a". + \ "<style type=\"text/css\">\n<!--\n". + \ ".FoldColumn { text-decoration: none; white-space: pre; }\n\n". + \ "body * { margin: 0; padding: 0; }\n". + \ "\n". + \ ".open-fold > .Folded { display: none; }\n". + \ ".open-fold > .fulltext { display: inline; }\n". + \ ".closed-fold > .fulltext { display: none; }\n". + \ ".closed-fold > .Folded { display: inline; }\n". + \ "\n". + \ ".open-fold > .toggle-open { display: none; }\n". + \ ".open-fold > .toggle-closed { display: inline; }\n". + \ ".closed-fold > .toggle-open { display: inline; }\n". + \ ".closed-fold > .toggle-closed { display: none; }\n" + exe "normal! a\n/* opening a fold while hovering won't be supported by IE6 and other\n". + \ "similar browsers, but it should fail gracefully. */\n". + \ ".closed-fold:hover > .fulltext { display: inline; }\n". + \ ".closed-fold:hover > .toggle-filler { display: none; }\n". + \ ".closed-fold:hover > .Folded { display: none; }\n" + exe "normal! a-->\n</style>\n" + exe "normal! a<!--[if lt IE 7]>". + \ "<style type=\"text/css\">\n". + \ ".open-fold .Folded { display: none; }\n". + \ ".open-fold .fulltext { display: inline; }\n". + \ ".open-fold .toggle-open { display: none; }\n". + \ ".closed-fold .toggle-closed { display: inline; }\n". + \ "\n". + \ ".closed-fold .fulltext { display: none; }\n". + \ ".closed-fold .Folded { display: inline; }\n". + \ ".closed-fold .toggle-open { display: inline; }\n". + \ ".closed-fold .toggle-closed { display: none; }\n". + \ "</style>\n". + \ "<![endif]-->\n" + else + " if we aren't doing hover_unfold, use CSS 1 only + exe "normal! a<style type=\"text/css\">\n<!--\n". + \ ".FoldColumn { text-decoration: none; white-space: pre; }\n\n". + \ ".open-fold .Folded { display: none; }\n". + \ ".open-fold .fulltext { display: inline; }\n". + \ ".open-fold .toggle-open { display: none; }\n". + \ ".closed-fold .toggle-closed { display: inline; }\n". + \ "\n". + \ ".closed-fold .fulltext { display: none; }\n". + \ ".closed-fold .Folded { display: inline; }\n". + \ ".closed-fold .toggle-open { display: inline; }\n". + \ ".closed-fold .toggle-closed { display: none; }\n". + \ "-->\n</style>\n" + endif + else + " if we aren't doing any dynamic folding, no need for any special rules + exe "normal! a<style type=\"text/css\">\n<!--\n-->\n</style>\n\e" + endif +endif + +" insert javascript to toggle folds open and closed +if exists("s:html_dynamic_folds") + exe "normal! a\n". + \ "<script type='text/javascript'>\n". + \ "<!--\n". + \ "function toggleFold(objID)\n". + \ "{\n". + \ " var fold;\n". + \ " fold = document.getElementById(objID);\n". + \ " if(fold.className == 'closed-fold')\n". + \ " {\n". + \ " fold.className = 'open-fold';\n". + \ " }\n". + \ " else if (fold.className == 'open-fold')\n". + \ " {\n". + \ " fold.className = 'closed-fold';\n". + \ " }\n". + \ "}\n". + \ "-->\n". + \ "</script>\n\e" endif + if exists("html_no_pre") exe "normal! a</head>\n<body>\n\e" else @@ -265,7 +398,81 @@ exe s:orgwin . "wincmd w" " List of all id's let s:idlist = "," -" Loop over all lines in the original text. +" First do some preprocessing for dynamic folding. Do this for the entire file +" so we don't accidentally start within a closed fold or something. +let s:allfolds = [] + +if exists("s:html_dynamic_folds") + let s:lnum = 1 + let s:end = line('$') + " save the fold text and set it to the default so we can find fold levels + let s:foldtext_save = &foldtext + set foldtext& + + " we will set the foldcolumn in the html to the greater of the maximum fold + " level and the current foldcolumn setting + let s:foldcolumn = &foldcolumn + + " get all info needed to describe currently closed folds + while s:lnum < s:end + if foldclosed(s:lnum) == s:lnum + " default fold text has '+-' and then a number of dashes equal to fold + " level, so subtract 2 from index of first non-dash after the dashes + " in order to get the fold level of the current fold + let s:level = match(foldtextresult(s:lnum), '+-*\zs[^-]') - 2 + if s:level+1 > s:foldcolumn + let s:foldcolumn = s:level+1 + endif + " store fold info for later use + let s:newfold = {'firstline': s:lnum, 'lastline': foldclosedend(s:lnum), 'level': s:level,'type': "closed-fold"} + call add(s:allfolds, s:newfold) + " open the fold so we can find any contained folds + execute s:lnum."foldopen" + else + let s:lnum = s:lnum + 1 + endif + endwhile |