diff options
author | Bram Moolenaar <Bram@vim.org> | 2010-07-25 12:46:44 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2010-07-25 12:46:44 +0200 |
commit | 7510fe74337599f70ae2044aef4f186b1f1c1bf9 (patch) | |
tree | b61a49e70685408de65b6d6833e72ba2fcc33c3b /runtime | |
parent | e6dc573b6e0e8eb59eda14be6f94476e72fd82ca (diff) | |
download | vim-7510fe74337599f70ae2044aef4f186b1f1c1bf9.zip |
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/autoload/tohtml.vim | 3 | ||||
-rw-r--r-- | runtime/doc/eval.txt | 17 | ||||
-rw-r--r-- | runtime/doc/syntax.txt | 10 | ||||
-rw-r--r-- | runtime/doc/todo.txt | 4 | ||||
-rw-r--r-- | runtime/plugin/tohtml.vim | 7 | ||||
-rw-r--r-- | runtime/syntax/2html.vim | 123 |
6 files changed, 117 insertions, 47 deletions
diff --git a/runtime/autoload/tohtml.vim b/runtime/autoload/tohtml.vim index 6c03ecb34..620c9c350 100644 --- a/runtime/autoload/tohtml.vim +++ b/runtime/autoload/tohtml.vim @@ -1,6 +1,6 @@ " Vim autoload file for the tohtml plugin. " Maintainer: Ben Fritz <fritzophrenic@gmail.com> -" Last Change: 2010 July 16 +" Last Change: 2010 July 24 " " Additional contributors: " @@ -64,6 +64,7 @@ func! tohtml#Diff2HTML(win_list, buf_list) call add(html, '<head>') call add(html, '<title>diff</title>') call add(html, '<meta name="Generator" content="Vim/'.v:version/100.'.'.v:version%100.'">') + call add(html, '<meta name="plugin-version" content="'.g:loaded_2html_plugin.'">') " TODO: copy or move encoding logic from 2html.vim so generated markup can " validate without warnings about encoding diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index f2a9f657a..719822ed3 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1,4 +1,4 @@ -*eval.txt* For Vim version 7.3b. Last change: 2010 May 14 +*eval.txt* For Vim version 7.3b. Last change: 2010 Jul 25 VIM REFERENCE MANUAL by Bram Moolenaar @@ -5550,6 +5550,21 @@ synID({lnum}, {col}, {trans}) *synID()* Example (echoes the name of the syntax item under the cursor): > :echo synIDattr(synID(line("."), col("."), 1), "name") < + +synconcealed({lnum}, {col}) *synconcealed()* + The result is a List. The first item in the list is 0 if the + character at the position {lnum} and {col} is not part of a + concealable region, 1 if it is. The second item in the list is + a string. If the first item is 1, the second item contains the + text which will be displayed in place of the concealed text, + depending on the current setting of 'conceallevel'. The third + and final item in the list is a unique number representing the + specific syntax region matched. This allows detection of the + beginning of a new concealable region if there are two + consecutive regions with the same replacement character. + For an example use see $VIMRUNTIME/syntax/2html.vim . + + synIDattr({synID}, {what} [, {mode}]) *synIDattr()* The result is a String, which is the {what} attribute of syntax ID {synID}. This can be used to obtain information diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index c5215cc6b..e81d55bb5 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -428,8 +428,14 @@ cascading style sheets (CSS1) for the attributes (resulting in considerably shorter and valid HTML 4 file), use: > :let g:html_use_css = 1 -Closed folds are put in the HTML as they are displayed. If you don't want -this, use the |zR| command before invoking 2html, or use: > +Concealed text is removed from the HTML and replaced with the appropriate +character from |syn-cchar| or 'listchars' depending on the current value of +'conceallevel'. If you always want to display all text in your document, +either set 'conceallevel' to before invoking 2html, or use: > + :let g:html_ignore_conceal = 1 + +Similarly, closed folds are put in the HTML as they are displayed. If you +don't want this, use the |zR| command before invoking 2html, or use: > :let g:html_ignore_folding = 1 You may want to generate HTML that includes all the data within the folds, and diff --git a/runtime/doc/todo.txt b/runtime/doc/todo.txt index ae1c793aa..c28661d66 100644 --- a/runtime/doc/todo.txt +++ b/runtime/doc/todo.txt @@ -1,4 +1,4 @@ -*todo.txt* For Vim version 7.3b. Last change: 2010 Jul 24 +*todo.txt* For Vim version 7.3b. Last change: 2010 Jul 25 VIM REFERENCE MANUAL by Bram Moolenaar @@ -30,6 +30,8 @@ be worked on, but only if you sponsor Vim development. See |sponsor|. *known-bugs* -------------------- Known bugs and current work ----------------------- +concealends does not appear to work. + if_python3.c is missing some changes that were applied to if_python.c. Find the old version of if_python.c from when the copy was made. diff --git a/runtime/plugin/tohtml.vim b/runtime/plugin/tohtml.vim index 23cfd58d8..867b85d40 100644 --- a/runtime/plugin/tohtml.vim +++ b/runtime/plugin/tohtml.vim @@ -1,10 +1,15 @@ " Vim plugin for converting a syntax highlighted file to HTML. " Maintainer: Ben Fritz <fritzophrenic@gmail.com> -" Last Change: 2010 Jul 16 +" Last Change: 2010 July 24 " " The core of the code is in $VIMRUNTIME/autoload/tohtml.vim and " $VIMRUNTIME/syntax/2html.vim +if exists('g:loaded_2html_plugin') + finish +endif +let g:loaded_2html_plugin = 'vim7.3_v1' + " Define the :TOhtml command when: " - 'compatible' is not set " - this plugin was not already loaded diff --git a/runtime/syntax/2html.vim b/runtime/syntax/2html.vim index d57324f13..5094433cd 100644 --- a/runtime/syntax/2html.vim +++ b/runtime/syntax/2html.vim @@ -1,19 +1,19 @@ " Vim syntax support file " Maintainer: Ben Fritz <fritzophrenic@gmail.com> -" Last Change: 2010 July 16 +" Last Change: 2010 July 24 " " Additional contributors: " -" Original by Bram Moolenaar <Bram@vim.org> -" 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> -" Progress bar based off code from "progressbar widget" plugin by -" Andreas Politz, heavily modified: -" http://www.vim.org/scripts/script.php?script_id=2006 +" Original by Bram Moolenaar <Bram@vim.org> +" 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> +" Progress bar based off code from "progressbar widget" plugin by +" Andreas Politz, heavily modified: +" http://www.vim.org/scripts/script.php?script_id=2006 " -" See Mercurial change logs for more! +" See Mercurial change logs for more! " Transform a file into HTML, using the current syntax highlighting. @@ -241,6 +241,18 @@ setlocal et set nomore set report=1000000 +if exists(':ownsyntax') && exists('w:current_syntax') + let s:current_syntax = w:current_syntax +elseif exists('b:current_syntax') + let s:current_syntax = b:current_syntax +else + let s:current_syntax = 'none' +endif + +if s:current_syntax == '' + let s:current_syntax = 'none' +endif + " Split window to create a buffer with the HTML file. let s:orgbufnr = winbufnr(0) let s:origwin_stl = &l:stl @@ -315,10 +327,12 @@ call extend(s:lines, [ \"<head>", \("<title>".expand("%:p:~")."</title>"), \("<meta name=\"Generator\" content=\"Vim/".v:version/100.".".v:version%100.'"'.s:tag_close), + \("<meta name=\"plugin-version\" content=\"".g:loaded_2html_plugin.'"'.s:tag_close), \]) if s:html_encoding != "" call add(s:lines, "<meta http-equiv=\"content-type\" content=\"text/html; charset=" . s:html_encoding . '"' . s:tag_close) endif +call add(s:lines, '<meta name="syntax" content="'.s:current_syntax.'"'.s:tag_close) if exists("g:html_use_css") if exists("g:html_dynamic_folds") @@ -810,8 +824,11 @@ while s:lnum <= s:end " html_no_pre to make it easier if !exists("g:html_no_foldcolumn") if empty(s:foldstack) - " add the empty foldcolumn for unfolded lines - let s:new = s:new . s:HtmlFormat(repeat(' ', s:foldcolumn), "FoldColumn") + " add the empty foldcolumn for unfolded lines if there is a fold + " column at all + if s:foldcolumn > 0 + let s:new = s:new . s:HtmlFormat(repeat(' ', s:foldcolumn), "FoldColumn") + endif else " add the fold column for folds not on the opening line if get(s:foldstack, 0).firstline < s:lnum @@ -831,11 +848,24 @@ while s:lnum <= s:end " Get the diff attribute, if any. let s:diffattr = diff_hlID(s:lnum, 1) + " initialize conceal info to act like not concealed, just in case + let s:concealinfo = [0, ''] + " Loop over each character in the line let s:col = 1 while s:col <= s:len || (s:col == 1 && s:diffattr) let s:startcol = s:col " The start column for processing text - if s:diffattr + if !exists('g:html_ignore_conceal') && has('conceal') + let s:concealinfo = synconcealed(s:lnum, s:col) + endif + if !exists('g:html_ignore_conceal') && s:concealinfo[0] + let s:col = s:col + 1 + " Speed loop (it's small - that's the trick) + " Go along till we find a change in the match sequence number (ending + " the specific concealed region) or until there are no more concealed + " characters. + while s:col <= s:len && s:concealinfo == synconcealed(s:lnum, s:col) | let s:col = s:col + 1 | endwhile + elseif s:diffattr let s:id = diff_hlID(s:lnum, s:col) let s:col = s:col + 1 " Speed loop (it's small - that's the trick) @@ -854,39 +884,50 @@ while s:lnum <= s:end while s:col <= s:len && s:id == synID(s:lnum, s:col, 1) | let s:col = s:col + 1 | endwhile endif - " Expand tabs - let s:expandedtab = strpart(s:line, s:startcol - 1, s:col - s:startcol) - let s:offset = 0 - let s:idx = stridx(s:expandedtab, "\t") - while s:idx >= 0 - if has("multi_byte_encoding") - if s:startcol + s:idx == 1 - let s:i = &ts - else - if s:idx == 0 - let s:prevc = matchstr(s:line, '.\%' . (s:startcol + s:idx + s:offset) . 'c') + if exists('g:html_ignore_conceal') || !s:concealinfo[0] + " Expand tabs + let s:expandedtab = strpart(s:line, s:startcol - 1, s:col - s:startcol) + let s:offset = 0 + let s:idx = stridx(s:expandedtab, "\t") + while s:idx >= 0 + if has("multi_byte_encoding") + if s:startcol + s:idx == 1 + let s:i = &ts else - let s:prevc = matchstr(s:expandedtab, '.\%' . (s:idx + 1) . 'c') + if s:idx == 0 + let s:prevc = matchstr(s:line, '.\%' . (s:startcol + s:idx + s:offset) . 'c') + else + let s:prevc = matchstr(s:expandedtab, '.\%' . (s:idx + 1) . 'c') + endif + let s:vcol = virtcol([s:lnum, s:startcol + s:idx + s:offset - len(s:prevc)]) + let s:i = &ts - (s:vcol % &ts) endif - let s:vcol = virtcol([s:lnum, s:startcol + s:idx + s:offset - len(s:prevc)]) - let s:i = &ts - (s:vcol % &ts) + let s:offset -= s:i - 1 + else + let s:i = &ts - ((s:idx + s:startcol - 1) % &ts) endif - let s:offset -= s:i - 1 - else - let s:i = &ts - ((s:idx + s:startcol - 1) % &ts) - endif - let s:expandedtab = substitute(s:expandedtab, '\t', repeat(' ', s:i), '') - let s:idx = stridx(s:expandedtab, "\t") - endwhile + let s:expandedtab = substitute(s:expandedtab, '\t', repeat(' ', s:i), '') + let s:idx = stridx(s:expandedtab, "\t") + endwhile - " Output the text with the same synID, with class set to {s:id_name} - let s:id = synIDtrans(s:id) - let s:id_name = synIDattr(s:id, "name", s:whatterm) - let s:new = s:new . s:HtmlFormat(s:expandedtab, s:id_name) + " get the highlight group name to use + let s:id = synIDtrans(s:id) + let s:id_name = synIDattr(s:id, "name", s:whatterm) + else + " use Conceal highlighting for concealed text + let s:id_name = 'Conceal' + let s:expandedtab = s:concealinfo[1] + endif + + " Output the text with the same synID, with class set to {s:id_name}, + " unless it has been concealed completely. Always output empty lines. + if strlen(s:expandedtab) > 0 + let s:new = s:new . s:HtmlFormat(s:expandedtab, s:id_name) + endif endwhile endif - call extend(s:lines, split(s:new.s:HtmlEndline, '\n')) + call extend(s:lines, split(s:new.s:HtmlEndline, '\n', 1)) if !s:html_no_progress && s:pgb.needs_redraw redrawstatus let s:pgb.needs_redraw = 0 @@ -1054,8 +1095,8 @@ let &ls=s:ls unlet s:htmlfont unlet s:old_et s:old_paste s:old_icon s:old_report s:old_title s:old_search s:old_magic s:old_more s:old_fdm s:old_winheight s:old_winfixheight unlet s:whatterm s:idlist s:lnum s:end s:margin s:fgc s:bgc -unlet! s:col s:id s:attr s:len s:line s:new s:expandedtab s:numblines -unlet! s:orgwin s:newwin s:orgbufnr s:idx s:i s:offset s:ls s:origwin_stl s:newwin_stl +unlet! s:col s:id s:attr s:len s:line s:new s:expandedtab s:numblines s:concealinfo +unlet! s:orgwin s:newwin s:orgbufnr s:idx s:i s:offset s:ls s:origwin_stl s:newwin_stl s:current_syntax if !v:profiling delfunc s:HtmlColor delfunc s:HtmlFormat |