...
 
Commits (3)
syntax:glob
*.un~
*.pyc
tags
.DS_Store
4101cbccf1d5fd0cfb81a3c6757c8f71657c1243 v0.8.0
4101cbccf1d5fd0cfb81a3c6757c8f71657c1243 semver
aa431c484c032ebc7b11e1e49c3b339d6d775384 v0.9.0
ede41dc6613eac08af5c98e69e123788b5a8e65a v1.0.0
e1365403fefc8b192252fa1dfda997f6c166ab60 v2.0.0
7fb1c286cca3c0c07974cc1b59002cfe2b7132f5 v2.1.0
dc582486455b428fc2ae50913b7844966ce64afc v2.1.1
d2406d0bce25549bb35c59767574386d3d241ace v2.2.0
c1cda256969c75523f9a8ef9629f08fca9ded216 v2.2.1
d6f98011d079bb1fd1bf6debb3f7cae55263b093 v2.2.2
bf31800e9784bd83c220f18fafde215abc72c4ef v2.3.0
25b74fe299c35aba1bc54c4af3febad1682b682b v2.4.0
39f23f08456425288c4a7e0ab94bec34c0b629ab v2.5.0
5eceebd06c39b670901d1b61c87aa07b7ac57f10 v2.6.0
3a3d8751bbe989566242e852dfabc7b335e649da v2.6.1
6918f8da3839158a38b4aa184b5dfa899f8d3987 v2.6.2
Gundo.vim is Vim plugin to visualize your Vim undo tree.
Preview
-------
Screencast:
### [http://screenr.com/M9l](http://screenr.com/M9l)
Screenshot:
<a href="http://www.flickr.com/photos/sjl7678/5093114605/" title="gundo by stevelosh, on Flickr"><img src="http://farm5.static.flickr.com/4113/5093114605_ebc46d6494.jpg" width="487" height="500" alt="gundo" /></a>
Requirements
------------
* Vim 7.3+
* Python support for Vim
* Python 2.4+
Installation and Usage
----------------------
Check out the [project site][] for installation instructions.
[project site]: https://sjl.bitbucket.io/gundo.vim/
License
-------
GPLv2+, just like Mercurial.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#!/usr/bin/env bash
hg archive ~/Desktop/gundo.zip -I 'doc' -I 'plugin' -I 'autoload' -I README.markdown
" ============================================================================
" File: gundo.vim
" Description: vim global plugin to visualize your undo tree
" Maintainer: Steve Losh <steve@stevelosh.com>
" License: GPLv2+ -- look it up.
" Notes: Much of this code was thiefed from Mercurial, and the rest was
" heavily inspired by scratch.vim and histwin.vim.
"
" ============================================================================
"{{{ Init
if !exists('g:gundo_debug') && (exists('g:gundo_disable') || exists('loaded_gundo') || &cp)"{{{
finish
endif
let loaded_gundo = 1"}}}
"}}}
"{{{ Misc
command! -nargs=0 GundoToggle call gundo#GundoToggle()
command! -nargs=0 GundoShow call gundo#GundoShow()
command! -nargs=0 GundoHide call gundo#GundoHide()
command! -nargs=0 GundoRenderGraph call gundo#GundoRenderGraph()
"}}}
This diff is collapsed.
This diff is collapsed.
#!/usr/bin/env bash
hg -R ~/src/sjl.bitbucket.org pull -u
rsync --delete -az . ~/src/sjl.bitbucket.org/gundo.vim
hg -R ~/src/sjl.bitbucket.org commit -Am 'gundo.vim: Update documentation.'
hg -R ~/src/sjl.bitbucket.org push
@font-face {
font-family: "Essays 1743";
src: url(Essays1743.ttf);
}
html {
overflow-y: scroll;
}
html, body {
background-color: #fdfdfd;
color: #111;
font: normal 16px/22px Palatino, Georgia, serif;
.wrap {
width: 599px;
margin: 48px auto;
}
h1, h2, h3, h4, h5, h6 {
font-family: "Essays 1743", Palatino, serif;
line-height: 1;
margin: 0;
margin-bottom: 22px;
}
a {
color: #04C;
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
p, pre {
margin: 0 0 22px 0;
}
code {
background-color: #f5f5f5;
border: 1px solid #ccc;
font: normal 14px Menlo, Monaco, Consolas, monospace;
padding: 1px 4px;
line-height: 1;
}
pre {
background-color: #f5f5f5;
border: 1px solid #ccc;
font: normal 14px Menlo, Monaco, Consolas, monospace;
margin-left: 22px;
padding: 11px;
}
img {
border: 1px solid #ccc;
padding: 4px;
float: right;
margin-left: 36px;
margin-bottom: 44px;
}
}
#repos {
position: fixed;
right: 10px;
top: 10px;
}
header {
h1 {
text-align: center;
font-size: 92px;
margin-bottom: 6px;
}
h2 {
color: #444;
text-align: center;
font-size: 36px;
letter-spacing: -1px;
}
}
section {
margin-top: 44px;
h1 {
font-size: 38px;
}
h2 {
font-size: 28px;
}
ol.changelog {
list-style-type: none;
padding-left: 0;
font-weight: bold;
ul {
font-weight: normal;
}
}
}
footer {
text-align: center;
font-style: italic;
margin-top: 66px;
}
This is Gundo's test suite. In case you didn't know, unit testing vim plugins
is a horrible experience.
Gundo bundles Luc Hermitte's [UT][] framework to make the process less painful.
[UT]: http://code.google.com/p/lh-vim/wiki/UT
To run a test, `cd` into the `tests` directory and use:
./run-tests.sh [[some-test.vim] ...]
The script will run the console vim command with its own vimrc and .vim
directory, so none of your other plugins should interfere. The result of the
tests will be shown in the quickfix window of this vim instance.
The `q` key will be remapped to perform `:qa!` so you can close everything
quickly if it all looks good.
The `run-tests.sh` script is still a work in progress. I need to figure out
a good way of collecting results. Suggestions and/or patches are very welcome.
../../../../bundled/ut/autoload/lh/UT.vim
\ No newline at end of file
"=============================================================================
" $Id: askvim.vim 246 2010-09-19 22:40:58Z luc.hermitte $
" File: autoload/lh/askvim.vim {{{1
" Author: Luc Hermitte <EMAIL:hermitte {at} free {dot} fr>
" <URL:http://code.google.com/p/lh-vim/>
" Version: 2.2.1
" Created: 17th Apr 2007
" Last Update: $Date: 2010-09-19 18:40:58 -0400 (Sun, 19 Sep 2010) $ (17th Apr 2007)
"------------------------------------------------------------------------
" Description:
" Defines functions that asks vim what it is relinquish to tell us
" - menu
"
"------------------------------------------------------------------------
" Installation:
" Drop it into {rtp}/autoload/lh/
" Vim 7+ required.
" History:
" v2.0.0:
" TODO: missing features
" }}}1
"=============================================================================
"=============================================================================
let s:cpo_save=&cpo
set cpo&vim
"------------------------------------------------------------------------
" ## Functions {{{1
" # Debug {{{2
function! lh#askvim#verbose(level)
let s:verbose = a:level
endfunction
function! s:Verbose(expr)
if exists('s:verbose') && s:verbose
echomsg a:expr
endif
endfunction
function! lh#askvim#debug(expr)
return eval(a:expr)
endfunction
"------------------------------------------------------------------------
" # Public {{{2
" Function: lh#askvim#exe(command) {{{3
function! lh#askvim#Exe(command)
echomsg 'lh#askvim#Exe() is deprecated, use lh#askvim#exe()'
return lh#askvim#exe(a:command)
endfunction
function! lh#askvim#exe(command)
let save_a = @a
try
silent! redir @a
silent! exe a:command
redir END
finally
" Always restore everything
let res = @a
let @a = save_a
return res
endtry
endfunction
" Function: lh#askvim#menu(menuid) {{{3
function! s:AskOneMenu(menuact, res)
let sKnown_menus = lh#askvim#exe(a:menuact)
let lKnown_menus = split(sKnown_menus, '\n')
" echo string(lKnown_menus)
" 1- search for the menuid
" todo: fix the next line to correctly interpret "stuff\.stuff" and
" "stuff\\.stuff".
let menuid_parts = split(a:menuact, '\.')
let simplifiedKnown_menus = deepcopy(lKnown_menus)
call map(simplifiedKnown_menus, 'substitute(v:val, "&", "", "g")')
" let idx = lh#list#match(simplifiedKnown_menus, '^\d\+\s\+'.menuid_parts[-1])
let idx = match(simplifiedKnown_menus, '^\d\+\s\+'.menuid_parts[-1])
if idx == -1
" echo "not found"
return
endif
" echo "l[".idx."]=".lKnown_menus[idx]
if empty(a:res)
let a:res.priority = matchstr(lKnown_menus[idx], '\d\+\ze\s\+.*')
let a:res.name = matchstr(lKnown_menus[idx], '\d\+\s\+\zs.*')
let a:res.actions = {}
" else
" what if the priority isn't the same?
endif
" 2- search for the menu definition
let idx += 1
while idx != len(lKnown_menus)
echo "l[".idx."]=".lKnown_menus[idx]
" should not happen
if lKnown_menus[idx] =~ '^\d\+' | break | endif
" :h showing-menus
" -> The format of the result of the call to Exe() seems to be:
" ^ssssMns-sACTION$
" s == 1 whitespace
" M == mode (inrvcs)
" n == noremap(*)/script(&)
" - == disable(-)/of not
let act = {}
let menu_def = matchlist(lKnown_menus[idx],
\ '^\s*\([invocs]\)\([&* ]\) \([- ]\) \(.*\)$')
if len(menu_def) > 4
let act.mode = menu_def[1]
let act.nore_script = menu_def[2]
let act.disabled = menu_def[3]
let act.action = menu_def[4]
else
echomsg string(menu_def)
echoerr "lh#askvim#menu(): Cannot decode ``".lKnown_menus[idx]."''"
endif
let a:res.actions["mode_" . act.mode] = act
let idx += 1
endwhile
" n- Return the result
return a:res
endfunction
function! lh#askvim#menu(menuid, modes)
let res = {}
let i = 0
while i != strlen(a:modes)
call s:AskOneMenu(a:modes[i].'menu '.a:menuid, res)
let i += 1
endwhile
return res
endfunction
" Functions }}}1
"------------------------------------------------------------------------
let &cpo=s:cpo_save
"=============================================================================
" vim600: set fdm=marker:
"=============================================================================
" $Id: buffer.vim 246 2010-09-19 22:40:58Z luc.hermitte $
" File: autoload/lh/buffer.vim {{{1
" Author: Luc Hermitte <EMAIL:hermitte {at} free {dot} fr>
" <URL:http://code.google.com/p/lh-vim/>
" Version: 2.2.1
" Created: 23rd Jan 2007
" Last Update: $Date: 2010-09-19 18:40:58 -0400 (Sun, 19 Sep 2010) $
"------------------------------------------------------------------------
" Description:
" Defines functions that help finding windows and handling buffers.
"
"------------------------------------------------------------------------
" Installation:
" Drop it into {rtp}/autoload/lh/
" Vim 7+ required.
" History:
" v 1.0.0 First Version
" (*) Functions moved from searchInRuntimeTime
" v 2.2.0
" (*) new function: lh#buffer#list()
" TODO:
" }}}1
"=============================================================================
"=============================================================================
let s:cpo_save=&cpo
set cpo&vim
" ## Functions {{{1
"------------------------------------------------------------------------
" # Debug {{{2
function! lh#buffer#verbose(level)
let s:verbose = a:level
endfunction
function! s:Verbose(expr)
if exists('s:verbose') && s:verbose
echomsg a:expr
endif
endfunction
function! lh#buffer#debug(expr)
return eval(a:expr)
endfunction
"------------------------------------------------------------------------
" # Public {{{2
" Function: lh#buffer#find({filename}) {{{3
" If {filename} is opened in a window, jump to this window, otherwise return -1
" Moved from searchInRuntimeTime.vim
function! lh#buffer#find(filename)
let b = bufwinnr(a:filename)
if b == -1 | return b | endif
exe b.'wincmd w'
return b
endfunction
function! lh#buffer#Find(filename)
return lh#buffer#find(a:filename)
endfunction
" Function: lh#buffer#jump({filename},{cmd}) {{{3
function! lh#buffer#jump(filename, cmd)
if lh#buffer#find(a:filename) != -1 | return | endif
exe a:cmd . ' ' . a:filename
endfunction
function! lh#buffer#Jump(filename, cmd)
return lh#buffer#jump(a:filename, a:cmd)
endfunction
" Function: lh#buffer#scratch({bname},{where}) {{{3
function! lh#buffer#scratch(bname, where)
try
silent exe a:where.' sp '.a:bname
catch /.*/
throw "Can't open a buffer named '".a:bname."'!"
endtry
setlocal bt=nofile bh=wipe nobl noswf ro
endfunction
function! lh#buffer#Scratch(bname, where)
return lh#buffer#scratch(a:bname, a:where)
endfunction
" Function: lh#buffer#list() {{{3
function! lh#buffer#list()
let all = range(0, bufnr('$'))
" let res = lh#list#transform_if(all, [], 'v:1_', 'buflisted')
let res = lh#list#copy_if(all, [], 'buflisted')
return res
endfunction
" Ex: echo lh#list#transform(lh#buffer#list(), [], "bufname")
"=============================================================================
let &cpo=s:cpo_save
"=============================================================================
" vim600: set fdm=marker:
"=============================================================================
" $Id: dialog.vim 246 2010-09-19 22:40:58Z luc.hermitte $
" File: autoload/lh/buffer/dialog.vim {{{1
" Author: Luc Hermitte <EMAIL:hermitte {at} free {dot} fr>
" <URL:http://code.google.com/p/lh-vim/>
" Version: 2.2.1
" Created: 21st Sep 2007
" Last Update: $Date: 2010-09-19 18:40:58 -0400 (Sun, 19 Sep 2010) $
"------------------------------------------------------------------------
" Description: description
"
"------------------------------------------------------------------------
" Installation:
" Drop it into {rtp}/autoload/lh/
" Vim 7+ required.
" History:
" v 1.0.0 First Version
" (*) Functions imported from Mail_mutt_alias.vim
" TODO:
" (*) --abort-- line
" (*) custom messages
" (*) do not mess with search history
" (*) support any &magic
" (*) syntax
" (*) add number/letters
" (*) tag with '[x] ' instead of '* '
" }}}1
"=============================================================================
"=============================================================================
let s:cpo_save=&cpo
set cpo&vim
"=============================================================================
" ## Globals {{{1
let s:LHdialog = {}
"=============================================================================
" ## Functions {{{1
" # Debug {{{2
function! lh#buffer#dialog#verbose(level)
let s:verbose = a:level
endfunction
function! s:Verbose(expr)
if exists('s:verbose') && s:verbose
echomsg a:expr
endif
endfunction
function! lh#buffer#dialog#debug(expr)
return eval(a:expr)
endfunction
"=============================================================================
" # Dialog functions {{{2
"------------------------------------------------------------------------
function! s:Mappings(abuffer)
" map <enter> to edit a file, also dbl-click
exe "nnoremap <silent> <buffer> <esc> :silent call ".a:abuffer.action."(-1, ".a:abuffer.id.")<cr>"
exe "nnoremap <silent> <buffer> q :call lh#buffer#dialog#select(-1, ".a:abuffer.id.")<cr>"
exe "nnoremap <silent> <buffer> <cr> :call lh#buffer#dialog#select(line('.'), ".a:abuffer.id.")<cr>"
" nnoremap <silent> <buffer> <2-LeftMouse> :silent call <sid>GrepEditFileLine(line("."))<cr>
" nnoremap <silent> <buffer> Q :call <sid>Reformat()<cr>
" nnoremap <silent> <buffer> <Left> :set tabstop-=1<cr>
" nnoremap <silent> <buffer> <Right> :set tabstop+=1<cr>
if a:abuffer.support_tagging
nnoremap <silent> <buffer> t :silent call <sid>ToggleTag(line("."))<cr>
nnoremap <silent> <buffer> <space> :silent call <sid>ToggleTag(line("."))<cr>
endif
nnoremap <silent> <buffer> <tab> :silent call <sid>NextChoice('')<cr>
nnoremap <silent> <buffer> <S-tab> :silent call <sid>NextChoice('b')<cr>
exe "nnoremap <silent> <buffer> h :silent call <sid>ToggleHelp(".a:abuffer.id.")<cr>"
endfunction
"----------------------------------------
" Tag / untag the current choice {{{
function! s:ToggleTag(lineNum)
if a:lineNum > s:Help_NbL()
" If tagged
if (getline(a:lineNum)[0] == '*')
let b:NbTags = b:NbTags - 1
silent exe a:lineNum.'s/^\* / /e'
else
let b:NbTags = b:NbTags + 1
silent exe a:lineNum.'s/^ /* /e'
endif
" Move after the tag ; there is something with the two previous :s. They
" don't leave the cursor at the same position.
silent! normal! 3|
call s:NextChoice('') " move to the next choice
endif
endfunction
" }}}
function! s:Help_NbL()
" return 1 + nb lines of BuildHelp
return 2 + len(b:dialog['help_'.b:dialog.help_type])
endfunction
"----------------------------------------
" Go to the Next (/previous) possible choice. {{{
function! s:NextChoice(direction)
" echomsg "next!"
call search('^[ *]\s*\zs\S\+', a:direction)
endfunction
" }}}
"------------------------------------------------------------------------
function! s:RedisplayHelp(dialog)
silent! 2,$g/^@/d_
normal! gg
for help in a:dialog['help_'.a:dialog.help_type]
silent put=help
endfor
endfunction
function! lh#buffer#dialog#update(dialog)
set noro
exe (s:Help_NbL()+1).',$d_'
for choice in a:dialog.choices
silent $put=' '.choice
endfor
set ro
endfunction
function! s:Display(dialog, atitle)
set noro
0 put = a:atitle
call s:RedisplayHelp(a:dialog)
for choice in a:dialog.choices
silent $put=' '.choice
endfor
set ro
exe s:Help_NbL()+1
endfunction
function! s:ToggleHelp(bufferId)
call lh#buffer#find(a:bufferId)
call b:dialog.toggle_help()
endfunction
function! lh#buffer#dialog#toggle_help() dict
let self.help_type
\ = (self.help_type == 'short')
\ ? 'long'
\ : 'short'
call s:RedisplayHelp(self)
endfunction
function! lh#buffer#dialog#new(bname, title, where, support_tagging, action, choices)
" The ID will be the buffer id
let res = {}
let where_it_started = getpos('.')
let where_it_started[0] = bufnr('%')
let res.where_it_started = where_it_started
try
call lh#buffer#scratch(a:bname, a:where)
catch /.*/
echoerr v:exception
return res
endtry
let res.id = bufnr('%')
let b:NbTags = 0
let b:dialog = res
let s:LHdialog[res.id] = res
let res.help_long = []
let res.help_short = []
let res.help_type = 'short'
let res.support_tagging = a:support_tagging
let res.action = a:action
let res.choices = a:choices
" Long help
call lh#buffer#dialog#add_help(res, '@| <cr>, <double-click> : select this', 'long')
call lh#buffer#dialog#add_help(res, '@| <esc>, q : Abort', 'long')
if a:support_tagging
call lh#buffer#dialog#add_help(res, '@| <t>, <space> : Tag/Untag the current item', 'long')
endif
call lh#buffer#dialog#add_help(res, '@| <up>/<down>, <tab>, +/- : Move between entries', 'long')
call lh#buffer#dialog#add_help(res, '@|', 'long')
" call lh#buffer#dialog#add_help(res, '@| h : Toggle help', 'long')
call lh#buffer#dialog#add_help(res, '@+'.repeat('-', winwidth(bufwinnr(res.id))-3), 'long')
" Short Help
" call lh#buffer#dialog#add_help(res, '@| h : Toggle help', 'short')
call lh#buffer#dialog#add_help(res, '@+'.repeat('-', winwidth(bufwinnr(res.id))-3), 'short')
let res.toggle_help = function("lh#buffer#dialog#toggle_help")
let title = '@ ' . a:title
let helpstr = '| Toggle (h)elp'
let title = title
\ . repeat(' ', winwidth(bufwinnr(res.id))-strlen(title)-strlen(helpstr)-1)
\ . helpstr
call s:Display(res, title)
call s:Mappings(res)
return res
endfunction
function! lh#buffer#dialog#add_help(abuffer, text, help_type)
call add(a:abuffer['help_'.a:help_type],a:text)
endfunction
"=============================================================================
function! lh#buffer#dialog#quit()
let bufferId = b:dialog.where_it_started[0]
echohl WarningMsg
echo "Abort"
echohl None
quit
call lh#buffer#find(bufferId)
endfunction
" Function: lh#buffer#dialog#select(line, bufferId [,overriden-action])
function! lh#buffer#dialog#select(line, bufferId, ...)
if a:line == -1
call lh#buffer#dialog#quit()
return
" elseif a:line <= s:Help_NbL() + 1
elseif a:line <= s:Help_NbL()
echoerr "Unselectable item"
return
else
let dialog = s:LHdialog[a:bufferId]
let results = { 'dialog' : dialog, 'selection' : [] }
if b:NbTags == 0
" -1 because first index is 0
" let results = [ dialog.choices[a:line - s:Help_NbL() - 1] ]
let results.selection = [ a:line - s:Help_NbL() - 1 ]
else
silent g/^* /call add(results.selection, line('.')-s:Help_NbL()-1)
endif
endif
if a:0 > 0 " action overriden
exe 'call '.dialog.action.'(results, a:000)'
else
exe 'call '.dialog.action.'(results)'
endif
endfunction
function! lh#buffer#dialog#Select(line, bufferId, ...)
echomsg "lh#buffer#dialog#Select() is deprecated, use lh#buffer#dialog#select() instead"
if a:0 > 0 " action overriden
exe 'call lh#buffer#dialog#select(a:line, a:bufferId, a:1)'
else
exe 'call lh#buffer#dialog#select(a:line, a:bufferId)'
endif
endfunction
function! Action(results)
let dialog = a:results.dialog
let choices = dialog.choices
for r in a:results.selection
echomsg '-> '.choices[r]
endfor
endfunction
"=============================================================================
let &cpo=s:cpo_save
"=============================================================================
" vim600: set fdm=marker:
"=============================================================================
" $Id: command.vim 246 2010-09-19 22:40:58Z luc.hermitte $
" File: autoload/lh/command.vim {{{1
" Author: Luc Hermitte <EMAIL:hermitte {at} free {dot} fr>
" <URL:http://code.google.com/p/lh-vim/>
" Version: 2.2.1
" Created: 08th Jan 2007
" Last Update: $Date: 2010-09-19 18:40:58 -0400 (Sun, 19 Sep 2010) $ (08th Jan 2007)
"------------------------------------------------------------------------
" Description:
" Helpers to define commands that:
" - support subcommands
" - support autocompletion
"
"------------------------------------------------------------------------
" Installation:
" Drop it into {rtp}/autoload/lh/
" Vim 7+ required.
" History:
" v2.0.0:
" Code move from other plugins
" TODO: missing features
" }}}1
"=============================================================================
"=============================================================================
let s:cpo_save=&cpo
set cpo&vim
" ## Debug {{{1
function! lh#command#verbose(level)
let s:verbose = a:level
endfunction
function! s:Verbose(expr)
if exists('s:verbose') && s:verbose
echomsg a:expr
endif
endfunction
function! lh#command#debug(expr)
return eval(a:expr)
endfunction
"------------------------------------------------------------------------
" ## Functions {{{1
" Tool functions {{{2
" Function: lh#command#Fargs2String(aList) {{{3
" @param[in,out] aList list of params from <f-args>
" @see tests/lh/test-Fargs2String.vim
function! lh#command#Fargs2String(aList)
if empty(a:aList) | return '' | endif
let quote_char = a:aList[0][0]
let res = a:aList[0]
call remove(a:aList, 0)
if quote_char !~ '["'."']"
return res
endif
" else
let end_string = '[^\\]\%(\\\\\)*'.quote_char.'$'
while !empty(a:aList) && res !~ end_string
let res .= ' ' . a:aList[0]
call remove(a:aList, 0)
endwhile
return res
endfunction
"------------------------------------------------------------------------
" ## Experimental Functions {{{1
" Internal functions {{{2
" Function: s:SaveData({Data}) {{{3
" @param Data Command definition
" Saves {Data} as s:Data{s:data_id++}. The definition will be used by
" automatically generated commands.
" @return s:data_id
let s:data_id = 0
function! s:SaveData(Data)
if has_key(a:Data, "command_id")
" Avoid data duplication
return a:Data.command_id
else
let s:Data{s:data_id} = a:Data
let id = s:data_id
let s:data_id += 1
let a:Data.command_id = id
return id
endif
endfunction
" BTWComplete(ArgLead, CmdLine, CursorPos): Auto-complete {{{3
function! lh#command#complete(ArgLead, CmdLine, CursorPos)
let tmp = substitute(a:CmdLine, '\s*\S*', 'Z', 'g')
let pos = strlen(tmp)
if 0
call confirm( "AL = ". a:ArgLead."\nCL = ". a:CmdLine."\nCP = ".a:CursorPos
\ . "\ntmp = ".tmp."\npos = ".pos
\, '&Ok', 1)
endif
if 2 == pos
" First argument: a command
return s:commands
elseif 3 == pos
" Second argument: first arg of the command
if -1 != match(a:CmdLine, '^BTW\s\+echo')
return s:functions . "\n" . s:variables
elseif -1 != match(a:CmdLine, '^BTW\s\+\%(help\|?\)')
elseif -1 != match(a:CmdLine, '^BTW\s\+\%(set\|add\)\%(local\)\=')
" Adds a filter
" let files = globpath(&rtp, 'compiler/BT-*')
" let files = files . globpath(&rtp, 'compiler/BT_*')
" let files = files . globpath(&rtp, 'compiler/BT/*')
let files = s:FindFilter('*')
let files = substitute(files,
\ '\(^\|\n\).\{-}compiler[\\/]BTW[-_\\/]\(.\{-}\)\.vim\>\ze\%(\n\|$\)',
\ '\1\2', 'g')
return files
elseif -1 != match(a:CmdLine, '^BTW\s\+remove\%(local\)\=')
" Removes a filter
return substitute(s:FiltersList(), ',', '\n', 'g')
endif
endif
" finally: unknown
echoerr 'BTW: unespected parameter ``'. a:ArgLead ."''"
return ''
endfunction
function! s:BTW(command, ...)
" todo: check a:0 > 1
if 'set' == a:command | let g:BTW_build_tool = a:1
if exists('b:BTW_build_tool')
let b:BTW_build_tool = a:1
endif
elseif 'setlocal' == a:command | let b:BTW_build_tool = a:1
elseif 'add' == a:command | call s:AddFilter('g', a:1)
elseif 'addlocal' == a:command | call s:AddFilter('b', a:1)
" if exists('b:BTW_filters_list') " ?????
" call s:AddFilter('b', a:1)
" endif
elseif 'remove' == a:command | call s:RemoveFilter('g', a:1)
elseif 'removelocal' == a:command | call s:RemoveFilter('b', a:1)
elseif 'rebuild' == a:command " wait for s:ReconstructToolsChain()
elseif 'echo' == a:command | exe "echo s:".a:1
" echo s:{a:f1} ## don't support echo s:f('foo')
elseif 'reloadPlugin' == a:command
let g:force_reload_BuildToolsWrapper = 1
let g:BTW_BTW_in_use = 1
exe 'so '.s:sfile
unlet g:force_reload_BuildToolsWrapper
unlet g:BTW_BTW_in_use
return
elseif a:command =~ '\%(help\|?\)'
call s:Usage()
return
endif
call s:ReconstructToolsChain()
endfunction
" ##############################################################
" Public functions {{{2
function! s:FindSubcommand(definition, subcommand)
for arg in a:definition.arguments
if arg.name == a:subcommand
return arg
endif
endfor
throw "NF"
endfunction
function! s:execute_function(definition, params)
if len(a:params) < 1
throw "(lh#command) Not enough arguments"
endif
let l:Fn = a:definition.action
echo "calling ".string(l:Fn)
echo "with ".string(a:params)
" call remove(a:params, 0)
call l:Fn(a:params)
endfunction
function! s:execute_sub_commands(definition, params)
try
if len(a:params) < 1
throw "(lh#command) Not enough arguments"
endif
let subcommand = s:FindSubcommand(a:definition, a:params[0])
call remove(a:params, 0)
call s:int_execute(subcommand, a:params)
catch /NF.*/
throw "(lh#command) Unexpected subcommand `".a:params[0]."'."
endtry
endfunction
function! s:int_execute(definition, params)
echo "params=".string(a:params)
call s:execute_{a:definition.arg_type}(a:definition, a:params)
endfunction
function! s:execute(definition, ...)
try
let params = copy(a:000)
call s:int_execute(a:definition, params)
catch /(lh#command).*/
echoerr v:exception . " in `".a:definition.name.' '.join(a:000, ' ')."'"
endtry
endfunction
function! lh#command#new(definition)
let cmd_name = a:definition.name
" Save the definition as an internal script variable
let id = s:SaveData(a:definition)
exe "command! -nargs=* ".cmd_name." :call s:execute(s:Data".id.", <f-args>)"
endfunction
" Functions }}}1
"------------------------------------------------------------------------
let &cpo=s:cpo_save
"=============================================================================
" vim600: set fdm=marker:
"=============================================================================
" $Id: common.vim 246 2010-09-19 22:40:58Z luc.hermitte $
" File: autoload/lh/common.vim {{{1
" Author: Luc Hermitte <EMAIL:hermitte {at} free {dot} fr>
" <URL:http://code.google.com/p/lh-vim/>
" Version: 2.2.1
" Created: 07th Oct 2006
" Last Update: $Date: 2010-09-19 18:40:58 -0400 (Sun, 19 Sep 2010) $ (08th Feb 2008)
"------------------------------------------------------------------------
" Description:
" Some common functions for:
" - displaying error messages
" - checking dependencies
"
"------------------------------------------------------------------------
" Installation:
" Drop it into {rtp}/autoload/lh/
" Vim 7+ required.
" History:
" v2.1.1
" - New function: lh#common#echomsg_multilines()
" - lh#common#warning_msg() supports multilines messages
"
" v2.0.0:
" - Code moved from other plugins
" }}}1
"=============================================================================
"=============================================================================
let s:cpo_save=&cpo
set cpo&vim
"------------------------------------------------------------------------
" Functions {{{1
" Function: lh#common#echomsg_multilines {{{2
function! lh#common#echomsg_multilines(text)
let lines = split(a:text, "[\n\r]")
for line in lines
echomsg line
endfor
endfunction
function! lh#common#echomsgMultilines(text)
return lh#common#echomsg_multilines(a:text)
endfunction
" Function: lh#common#error_msg {{{2
function! lh#common#error_msg(text)
if has('gui_running')
call confirm(a:text, '&Ok', '1', 'Error')
else
" echohl ErrorMsg
echoerr a:text
" echohl None
endif
endfunction
function! lh#common#ErrorMsg(text)
return lh#common#error_msg(a:text)
endfunction
" Function: lh#common#warning_msg {{{2
function! lh#common#warning_msg(text)
echohl WarningMsg
" echomsg a:text
call lh#common#echomsg_multilines(a:text)
echohl None
endfunction
function! lh#common#WarningMsg(text)
return lh#common#warning_msg(a:text)
endfunction
" Dependencies {{{2
function! lh#common#check_deps(Symbol, File, path, plugin) " {{{3
if !exists(a:Symbol)
exe "runtime ".a:path.a:File
if !exists(a:Symbol)
call lh#common#error_msg( a:plugin.': Requires <'.a:File.'>')
return 0
endif
endif
return 1
endfunction
function! lh#common#CheckDeps(Symbol, File, path, plugin) " {{{3
echomsg "lh#common#CheckDeps() is deprecated, use lh#common#check_deps() instead."
return lh#common#check_deps(a:Symbol, a:File, a:path, a:plugin)
endfunction
" Functions }}}1
"------------------------------------------------------------------------
let &cpo=s:cpo_save
"=============================================================================
" vim600: set fdm=marker:
"=============================================================================
" $Id: encoding.vim 246 2010-09-19 22:40:58Z luc.hermitte $
" File: autoload/lh/encoding.vim {{{1
" Author: Luc Hermitte <EMAIL:hermitte {at} free {dot} fr>
" <URL:http://code.google.com/p/lh-vim/>
" Version: 2.2.1
" Created: 21st Feb 2008
" Last Update: $Date: 2010-09-19 18:40:58 -0400 (Sun, 19 Sep 2010) $
"------------------------------------------------------------------------
" Description:
" Defines functions that help managing various encodings
"
"------------------------------------------------------------------------
" Installation:
" Drop it into {rtp}/autoload/lh/
" Vim 7+ required.
" History:
" v2.0.7:
" (*) lh#encoding#Iconv() copied from map-tools
" TODO: missing features
" }}}1
"=============================================================================
let s:cpo_save=&cpo
set cpo&vim
"------------------------------------------------------------------------
" Function: lh#encoding#iconv(expr, from, to) " {{{3
" Unlike |iconv()|, this wrapper returns {expr} when we know no convertion can
" be acheived.
function! lh#encoding#iconv(expr, from, to)
" call Dfunc("s:ICONV(".a:expr.','.a:from.','.a:to.')')
if has('multi_byte') &&
\ ( has('iconv') || has('iconv/dyn') ||
\ ((a:from=~'latin1\|utf-8') && (a:to=~'latin1\|utf-8')))
" call confirm('encoding: '.&enc."\nto:".a:to, "&Ok", 1)
" call Dret("s:ICONV convert=".iconv(a:expr, a:from, a:to))
return iconv(a:expr,a:from,a:to)
else
" Cannot convert
" call Dret("s:ICONV no convert=".a:expr)
return a:expr
endif
endfunction
"------------------------------------------------------------------------
let &cpo=s:cpo_save
"=============================================================================
" vim600: set fdm=marker:
"=============================================================================
" $Id: env.vim 244 2010-09-19 22:38:24Z luc.hermitte $
" File: autoload/lh/env.vim {{{1
" Author: Luc Hermitte <EMAIL:hermitte {at} free {dot} fr>
" <URL:http://code.google.com/p/lh-vim/>
" Version: 2.2.1
" Created: 19th Jul 2010
" Last Update: $Date: 2010-09-19 18:38:24 -0400 (Sun, 19 Sep 2010) $
"------------------------------------------------------------------------
" Description:
" Functions related to environment (variables)
"
"------------------------------------------------------------------------
" Installation:
" Drop this file into {rtp}/autoload/lh
" Requires Vim7+
" History:
" v2.2.1 First Version
" TODO: missing features
" }}}1
"=============================================================================
let s:cpo_save=&cpo
set cpo&vim
"------------------------------------------------------------------------
" ## Misc Functions {{{1
" # Version {{{2
let s:k_version = 221
function! lh#env#version()
return s:k_version
endfunction
" # Debug {{{2
let s:verbose = 0
function! lh#env#verbose(...)
if a:0 > 0 | let s:verbose = a:1 | endif
return s:verbose
endfunction
function! s:Verbose(expr)
if s:verbose
echomsg a:expr
endif
endfunction
function! lh#env#debug(expr)
return eval(a:expr)
endfunction
"------------------------------------------------------------------------
" ## Exported functions {{{1
function! lh#env#expand_all(string)
let res = ''
let tail = a:string
while !empty(tail)
let [ all, head, var, tail; dummy ] = matchlist(tail, '\(.\{-}\)\%(${\(.\{-}\)}\)\=\(.*\)')
if empty(var)
let res .= tail
break
else
let res .= head
let val = eval('$'.var)
let res .= val
endif
endwhile
return res
endfunction
"------------------------------------------------------------------------
" ## Internal functions {{{1
"------------------------------------------------------------------------
let &cpo=s:cpo_save
"=============================================================================
" vim600: set fdm=marker:
"=============================================================================
" $Id: event.vim 246 2010-09-19 22:40:58Z luc.hermitte $
" File: autoload/lh/event.vim {{{1
" Author: Luc Hermitte <EMAIL:hermitte {at} free {dot} fr>
" <URL:http://code.google.com/p/lh-vim/>
" Version: 2.2.1
" Created: 15th Feb 2008
" Last Update: $Date: 2010-09-19 18:40:58 -0400 (Sun, 19 Sep 2010) $
"------------------------------------------------------------------------
" Description:
" Function to help manage vim |autocommand-events|
"
"------------------------------------------------------------------------
" Installation:
" Drop it into {rtp}/autoload/lh/
" Vim 7+ required.
" History:
" v2.0.6:
" Creation
" TODO:
" }}}1
"=============================================================================
let s:cpo_save=&cpo
set cpo&vim
"------------------------------------------------------------------------
" ## Functions {{{1
" # Debug {{{2
function! lh#event#verbose(level)
let s:verbose = a:level
endfunction
function! s:Verbose(expr)
if exists('s:verbose') && s:verbose
echomsg a:expr
endif
endfunction
function! lh#event#debug(expr)
return eval(a:expr)
endfunction
"------------------------------------------------------------------------
" # Event Registration {{{2
function! s:RegisteredOnce(cmd, group)
" We can't delete the current augroup autocommand => increment a counter
if !exists('s:'.a:group) || s:{a:group} == 0
let s:{a:group} = 1
exe a:cmd
endif
endfunction
function! lh#event#register_for_one_execution_at(event, cmd, group)
let group = a:group.'_once'
let s:{group} = 0
exe 'augroup '.group
au!
exe 'au '.a:event.' '.expand('%:p').' call s:RegisteredOnce('.string(a:cmd).','.string(group).')'
augroup END
endfunction
function! lh#event#RegisterForOneExecutionAt(event, cmd, group)
return lh#event#register_for_one_execution_at(a:event, a:cmd, a:group)
endfunction
"------------------------------------------------------------------------
let &cpo=s:cpo_save
"=============================================================================
" vim600: set fdm=marker:
"=============================================================================
" $Id: function.vim 161 2010-05-07 01:04:44Z luc.hermitte $
" File: autoload/lh/function.vim {{{1
" Author: Luc Hermitte <EMAIL:hermitte {at} free {dot} fr>
" <URL:http://code.google.com/p/lh-vim/>
" Version: 2.2.0
" Created: 03rd Nov 2008
" Last Update: $Date: 2010-05-06 21:04:44 -0400 (Thu, 06 May 2010) $
"------------------------------------------------------------------------
" Description:
" Implements:
" - lh#function#bind()
" - lh#function#execute()
" - lh#function#prepare()
" - a binded function type
"
"------------------------------------------------------------------------
" Installation:
" Drop it into {rtp}/autoload/lh/
" Vim 7+ required.
" History:
" v2.2.0: first implementation
" TODO: «missing features»
" }}}1
"=============================================================================
let s:cpo_save=&cpo
set cpo&vim
"------------------------------------------------------------------------
" ## Functions {{{1
" # Debug {{{2
function! lh#function#verbose(level)
let s:verbose = a:level
endfunction
function! s:Verbose(expr)
if exists('s:verbose') && s:verbose
echomsg a:expr
endif
endfunction
function! lh#function#debug(expr)
return eval(a:expr)
endfunction
" # Function: s:Join(arguments...) {{{2
function! s:Join(args)
let res = ''
if len(a:args) > 0
let res = string(a:args[0])
let i = 1
while i != len(a:args)
let res.=','.string(a:args[i])
let i += 1
endwhile
endif
return res
endfunction
" # Function: s:DoBindList(arguments...) {{{2
function! s:DoBindList(formal, real)
let args = []
for arg in a:formal
if type(arg)==type('string') && arg =~ '^v:\d\+_$'
let new = a:real[matchstr(arg, 'v:\zs\d\+\ze_')-1]
elseif type(arg)==type('string')
let new = eval(s:DoBindEvaluatedString(arg, a:real))
else
let new = arg
endif
call add(args, new)
unlet new
unlet arg
endfor
return args
endfunction
" # Function: s:DoBindString(arguments...) {{{2
function! s:DoBindString(expr, real)
let expr = substitute(a:expr, '\<v:\(\d\+\)_\>', a:real.'[\1-1]', 'g')
return expr
endfunction
function! s:ToString(expr)
return type(a:expr) != type('')
\ ? string(a:expr)
\ : (a:expr)
endfunction
function! s:DoBindEvaluatedString(expr, real)
let expr = a:expr
let p = 0
while 1
let p = match(expr, '\<v:\d\+_\>', p)
if -1 == p | break | endif
let e = matchend(expr, '\<v:\d\+_\>', p)
let n = eval(expr[p+2 : e-2])
" let new = (type(a:real[n-1])==type('') && a:real[n-1]=~ '\<v:\d\+_\>')
" \ ? a:real[n-1]
" \ : string(a:real[n-1])
let new = s:ToString(a:real[n-1])
" let new = string(a:real[n-1]) " -> bind_counpound vars
let expr = ((p>0) ? (expr[0:p-1]) : '') . new . expr[e : -1]
" echo expr
let p += len(new)
" silent! unlet new
endwhile
return expr
endfunction
" # Function: s:Execute(arguments...) {{{2
function! s:Execute(args) dict
if type(self.function) == type(function('exists'))
let args = s:DoBindList(self.args, a:args)
" echomsg '##'.string(self.function).'('.join(args, ',').')'
let res = eval(string(self.function).'('.s:Join(args).')')
elseif type(self.function) == type('string')
let expr = s:DoBindString(self.function, 'a:args')
let res = eval(expr)
elseif type(self.function) == type({})
return self.function.execute(a:args)
else
throw "lh#functor#execute: unpected function type: ".type(self.function)
endif
return res
endfunction
" # Function: lh#function#prepare(function, arguments_list) {{{2
function! lh#function#prepare(Fn, arguments_list)
if type(a:Fn) == type(function('exists'))
let expr = string(a:Fn).'('.s:Join(a:arguments_list).')'
return expr
elseif type(a:Fn) == type('string')
if a:Fn =~ '^[a-zA-Z0-9_#]\+$'
let expr = string(function(a:Fn)).'('.s:Join(a:arguments_list).')'
return expr
else
let expr = s:DoBindString(a:Fn, 'a:000')
return expr
endif
else
throw "lh#function#prepare(): {Fn} argument of type ".type(a:Fn). " is unsupported"
endif
endfunction
" # Function: lh#function#execute(function, arguments...) {{{2
function! lh#function#execute(Fn, ...)
if type(a:Fn) == type({}) && has_key(a:Fn, 'execute')
return a:Fn.execute(a:000)
else
let expr = lh#function#prepare(a:Fn, a:000)
return eval(expr)
endif
endfunction
" # Function: lh#function#bind(function, arguments...) {{{2
function! lh#function#bind(Fn, ...)
let args = copy(a:000)
if type(a:Fn) == type('string') && a:Fn =~ '^[a-zA-Z0-9_#]\+$'
\ && exists('*'.a:Fn)
let Fn = function(a:Fn)
elseif type(a:Fn) == type({})
" echo string(a:Fn).'('.string(a:000).')'
" Rebinding another binded function
" TASSERT has_key(a:Fn, 'function')
" TASSERT has_key(a:Fn, 'execute')
" TASSERT has_key(a:Fn, 'args')
let Fn = a:Fn.function
let N = len(a:Fn.args)
if N != 0 " args to rebind
let i = 0
let t_args = [] " necessary to avoid type changes
while i != N
silent! unlet arg
let arg = a:Fn.args[i]
if arg =~ 'v:\d\+_$'
let arg2 = eval(s:DoBindString(arg, string(args)))
" echo arg."-(".string(args).")->".string(arg2)
unlet arg
let arg = arg2
unlet arg2
endif
call add(t_args, arg)
let i += 1
endwhile
unlet a:Fn.args
let a:Fn.args = t_args
else " expression to fix
" echo Fn
" echo s:DoBindString(Fn, string(args))
" echo eval(string(s:DoBindString(Fn, string(args))))
let Fn = (s:DoBindEvaluatedString(Fn, args))
endif
let args = a:Fn.args
else
let Fn = a:Fn
endif
let binded_fn = {
\ 'function': Fn,
\ 'args': args,
\ 'execute': function('s:Execute')
\}
return binded_fn
endfunction
" }}1
"------------------------------------------------------------------------
let &cpo=s:cpo_save
"=============================================================================
" vim600: set fdm=marker:
" Vim: let g:UTfiles='tests/lh/function.vim'
"=============================================================================
" $Id: tsort.vim 246 2010-09-19 22:40:58Z luc.hermitte $
" File: autoload/lh/tsort.vim {{{1
" Author: Luc Hermitte <EMAIL:hermitte {at} free {dot} fr>
" <URL:http://code.google.com/p/lh-vim/>
" Version: 2.2.1
" Created: 21st Apr 2008
" Last Update: $Date: 2010-09-19 18:40:58 -0400 (Sun, 19 Sep 2010) $
"------------------------------------------------------------------------
" Description: Library functions for Topological Sort
"
"------------------------------------------------------------------------
" Drop the file into {rtp}/autoload/lh/graph
" History: history
" TODO: missing features
" }}}1
"=============================================================================
let s:cpo_save=&cpo
set cpo&vim
"------------------------------------------------------------------------
" ## Debug {{{1
function! lh#graph#tsort#verbose(level)
let s:verbose = a:level
endfunction
function! s:Verbose(expr)
if exists('s:verbose') && s:verbose
echomsg a:expr
endif
endfunction
function! lh#graph#tsort#debug(expr)
return eval(a:expr)
endfunction
"------------------------------------------------------------------------
"## Helper functions {{{1
"# s:Successors_fully_defined(node) {{{2
function! s:Successors_fully_defined(node) dict
if has_key(self.table, a:node)
return self.table[a:node]
else
return []
endif
endfunction
"# s:Successors_lazy(node) {{{2
function! s:Successors_lazy(node) dict
if !has_key(self.table, a:node)
let nodes = self.fetch(a:node)
let self.table[a:node] = nodes
" if len(nodes) > 0
" let self.nb += 1
" endif
return nodes
else
return self.table[a:node]
endif
endfunction
"# s:PrepareDAG(dag) {{{2
function! s:PrepareDAG(dag)
if type(a:dag) == type(function('has_key'))
let dag = {
\ 'successors': function('s:Successors_lazy'),
\ 'fetch' : a:dag,
\ 'table' : {}
\}
else
let dag = {
\ 'successors': function('s:Successors_fully_defined'),
\ 'table' : deepcopy(a:dag)
\}
endif
return dag
endfunction
"## Depth-first search (recursive) {{{1
" Do not detect cyclic graphs
"# lh#graph#tsort#depth(dag, start_nodes) {{{2
function! lh#graph#tsort#depth(dag, start_nodes)
let dag = s:PrepareDAG(a:dag)
let results = []
let visited_nodes = { 'Visited':function('s:Visited')}
call s:RecursiveDTSort(dag, a:start_nodes, results, visited_nodes)
call reverse(results)
return results
endfunction