" Vim syntax support file " Maintainer: Nikolai Weibull " Latest Revision: 2005-12-04 function! s:Format(text, group) let formatted = strtrans(a:text) let formatted = substitute(formatted, '{', '\\leftargument', 'g') let formatted = substitute(formatted, '}', '\\rightargument', 'g') " TODO: Replace the reserved ConTeXt characters. " TODO: make sure to escape everything. if a:group != "" let formatted = "\\highlight[" . a:group . ']{' . formatted . '}' endif return formatted endfunction function! s:Append(text) exe s:new_win . 'wincmd w' call append(line('$'), a:text) exe s:org_win . 'wincmd w' endfunction function! s:AppendFillers(filler, diff_fillchar) let n = filler while n > 0 let new = repeat(diff_fillchar, 3) if n > 2 && n < filler && !exists('context_whole_filler') let new .= ' ' . filler . ' inserted lines ' let n = 2 endif let new .= repeat(diff_fillchar, &columns - strlen(new)) call s:Append(s:Format(new, 'DiffDelete')) let n -= 1 endwhile endfunction function! s:GetFillChar(char, default) let fillchar = &fillchars[matchend(&fillchars, a:char . ':')] return (fillchar != '' ? fillchar : default) endfunction function! s:MainLoop() " Set up stuff for handling folding. if has('folding') && !exists('context_ignore_folding') let fold_fillchar = s:GetFillChar('fold', '-') endif " Set up stuff for handling diffs. let diff_fillchar = s:GetFillChar('diff', '-') let lnum = 1 let last = line('$') while lnum <= last " If there are filler lines for diff mode, show these above the line. let filler = diff_filler(lnum) if filler > 0 call s:AppendFillers(filler, diff_fillchar) endif let new = "" if has('folding') && !exists('context_ignore_folding') && foldclosed(lnum) > -1 let new = s:Format(new . foldtextresult(lnum), 'Folded') let lnum = foldclosedend(lnum) else let line = getline(lnum) let len = strlen(line) let diff_attr = diff_hlID(lnum, 1) let col = 1 while col <= len || (col == 1 && diff_attr) let start_col = col " The start column for processing text. if diff_attr let id = diff_hlID(lnum, col) let col += 1 while col <= len && id == diff_hlID(lnum, col) | let col += 1 | endwhile if len < &columns " Add spaces at the end to mark the changed line. let line = line . repeat(' ', &columns - len) let len = &columns endif else " TODO: why not use synIDtrans here instead? That’t give longest " possible matches. let id = synID(lnum, col, 1) let col += 1 while col <= len && id == synID(lnum, col, 1) | let col += 1 | endwhile endif " Expand tabs. " TODO: make a function? let new .= s:ExpandAndFormat(strpart(...), id) let expanded = strpart(line, start_col - 1, col - start_col) let idx = stridx(expanded, "\t") while idx >= 0 let i = &ts - (idx + start_col - 1) % &ts let expanded = substitute(expanded, '\t', repeat(' ', i), '') let idx = stridx(expanded, "\t") endwhile if expanded =~ '^\s*$' let new .= expanded else let new .= s:Format(expanded, synIDattr(synIDtrans(id), 'name')) endif endwhile endif call s:Append(new) let lnum = lnum + 1 endwhile endfunction " Set up options. let s:old_title = &title let s:old_icon = &icon let s:old_search = @/ set notitle noicon " Split window to create a buffer with the ConTeXt file. let s:org_bufnr = winbufnr(0) if expand("%") == "" new untitled.tex else new %.tex endif let s:new_win = winnr() let s:org_win = bufwinnr(s:org_bufnr) " Set up the new buffer. set modifiable %delete call setline(1, '\startlines') " Switch to the original window. exe s:org_win . 'wincmd w' call s:MainLoop() " Cleanup. exe s:new_win . 'wincmd w' call append(line('$'), '\stoplines') silent %s:\s\+$::e " Restore old settings. let &title = s:old_title let &icon = s:old_icon let @/ = s:old_search " Save a little bit of memory. (Is this worth doing?) unlet s:old_title s:old_icon s:old_search unlet s:org_bufnr s:new_win s:org_win if !v:profiling delfunction s:Format delfunction s:Append delfunction s:AppendFillers delfunction s:GetFillChar delfunction s:MainLoop endif