Wednesday, February 24, 2010

Re: Saving signs

fu! <sid>ParseSignsOutput(...)
let s:signs=[]
let s:signdict={}
redir => a
sil sign list
redir end


let s:signs=split(a, '\n')
call insert(s:signs, '" Define Signs')
call map(s:signs, 'substitute(v:val, "^sign", "& define", "")')
let s:signs += [ '', '" Define Placement of Signs' ]

redir => a
sil sign place
redir end

let list=split(a, '\n')[1:]
call filter(list, "!empty(v:val)")
let fname=""
let pat='^Signs for \zs.*\ze:'
for val in list
if match(val, pat) >= 0
let fname=fnamemodify(matchstr(val, pat), ':p')
let s:signdict[fname]=[]
else
let place=split(val, '\s\+')
if place[2] =~ '\[Deleted\]'
continue
endif
call add(s:signdict[fname], "\tsign place " . matchstr(place[1],'id=\zs.*') . " " . place[0] . " " . place[2] . " file=".fname )
endif
endfor
for file in keys(s:signdict)
call insert(s:signdict[file], "if bufexists('" . file . "')")
call add(s:signdict[file], "endif")
endfor
call <sid>CreateSignFiles(exists("a:1") ? a:1 : '', empty(a:2) ? 0 : 1)
endfu

fun! <sid>CreateSignFiles(fname, force)
if !empty(s:signs) && !empty(keys(s:signdict))
if !empty(a:fname) && !isdirectory(a:fname) && (a:force || !filereadable(a:fname))
let filename=a:fname
else
if filereadable(a:fname)
echohl WarningMsg
echomsg "File " . a:fname . " exists! Creating new file"
echomsg "Use ! to override"
echohl Normal
endif
let filename=tempname()
endif

if bufloaded(filename)
exe bufwinnr(filename) . "wincmd w"
else
exe ":sp" filename
endif
%d

call append('.', [ '" Remove all previously placed signs' , 'sign unplace *', ''])
$
call append('.', [
\'" Undefine all previously defined signs' ,
\'redir => a | exe "sil sign list" | redir end',
\'let signlist=split(a, "\n")',
\"call map(signlist, '\"sign undefine \" . split(v:val, ''\\s\\+'')[1]')",
\'for sign in signlist | exe sign | endfor ',
\''])
$
call append('.',s:signs)
for file in keys(s:signdict)
call append('$', s:signdict[file])
endfor
setf vim
"setl nomodified
endif
endfun


com! -nargs=? -bang -complete=file Signs :call <sid>ParseSignsOutput(<q-args>, "<bang>")
Hi

On Mi, 24 Feb 2010, Christian Brabandt wrote:
> You probably have to do it manually by parsing the output of :sign list
> and :sign place.

Try the attached plugin.

Mit freundlichen Grüßen
Christian
--
Die Geschichte der Wissenschaften ist eine große Fuge, in der die
Stimmen der Völker nach und nach zum Vorschein kommen.
-- Goethe, Maximen und Reflektionen, Nr. 95

--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

No comments: