Skip to content

Commit 07bec65

Browse files
committed
Added session manager; Added clojure support
1 parent a6540d4 commit 07bec65

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+5423
-17
lines changed

autoload/vimclojure.vim

+1,067
Large diffs are not rendered by default.

autoload/vimclojure/util.vim

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
" Part of Vim filetype plugin for Clojure
2+
" Language: Clojure
3+
" Maintainer: Meikel Brandmeyer <[email protected]>
4+
5+
let s:save_cpo = &cpo
6+
set cpo&vim
7+
8+
function! vimclojure#util#SynIdName()
9+
return synIDattr(synID(line("."), col("."), 0), "name")
10+
endfunction
11+
12+
function! vimclojure#util#WithSaved(closure)
13+
let v = a:closure.save()
14+
try
15+
let r = a:closure.f()
16+
finally
17+
call a:closure.restore(v)
18+
endtry
19+
return r
20+
endfunction
21+
22+
function! vimclojure#util#WithSavedPosition(closure)
23+
function a:closure.save() dict
24+
let [ _b, l, c, _o ] = getpos(".")
25+
let b = bufnr("%")
26+
return [b, l, c]
27+
endfunction
28+
29+
function a:closure.restore(value) dict
30+
let [b, l, c] = a:value
31+
32+
if bufnr("%") != b
33+
execute b "buffer!"
34+
endif
35+
call setpos(".", [0, l, c, 0])
36+
endfunction
37+
38+
return vimclojure#util#WithSaved(a:closure)
39+
endfunction
40+
41+
function! vimclojure#util#WithSavedRegister(reg, closure)
42+
let a:closure._register = a:reg
43+
44+
function a:closure.save() dict
45+
return [getreg(self._register, 1), getregtype(self._register)]
46+
endfunction
47+
48+
function a:closure.restore(value) dict
49+
call call(function("setreg"), [self._register] + a:value)
50+
endfunction
51+
52+
return vimclojure#util#WithSaved(a:closure)
53+
endfunction
54+
55+
function! vimclojure#util#WithSavedOption(option, closure)
56+
let a:closure._option = a:option
57+
58+
function a:closure.save() dict
59+
return eval("&" . self._option)
60+
endfunction
61+
62+
function a:closure.restore(value) dict
63+
execute "let &" . self._option . " = a:value"
64+
endfunction
65+
66+
return vimclojure#util#WithSaved(a:closure)
67+
endfunction
68+
69+
function! vimclojure#util#Yank(r, how)
70+
let closure = {'reg': a:r, 'yank': a:how}
71+
72+
function closure.f() dict
73+
silent execute self.yank
74+
return getreg(self.reg)
75+
endfunction
76+
77+
return vimclojure#util#WithSavedRegister(a:r, closure)
78+
endfunction
79+
80+
function! vimclojure#util#MoveBackward()
81+
call search('\S', 'Wb')
82+
endfunction
83+
84+
function! vimclojure#util#MoveForward()
85+
call search('\S', 'W')
86+
endfunction
87+
88+
" Epilog
89+
let &cpo = s:save_cpo

autoload/xolox/misc/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Miscellaneous auto-load Vim scripts
2+
3+
The git repository at <https://github.com/xolox/vim-misc> contains Vim scripts that are used by most of the [Vim plug-ins I've written] [plugins] yet don't really belong with any single one. I include this repository as a subdirectory of my plug-in repositories using the following commands:
4+
5+
$ git remote add -f vim-misc https://github.com/xolox/vim-misc.git
6+
$ git merge -s ours --no-commit vim-misc/master
7+
$ git read-tree --prefix=autoload/xolox/misc/ -u vim-misc/master
8+
$ git commit -m "Merge vim-misc repository as subdirectory"
9+
10+
To update a plug-in repository to the latest versions of the miscellaneous auto-load scripts I execute the following command:
11+
12+
$ git pull -s subtree vim-misc master
13+
14+
## Contact
15+
16+
If you have questions, bug reports, suggestions, etc. the author can be contacted at <[email protected]>. The latest version is available at <http://peterodding.com/code/vim/misc> and <https://github.com/xolox/vim-misc>.
17+
18+
## License
19+
20+
This software is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License).
21+
© 2011 Peter Odding &lt;<[email protected]>&gt;.
22+
23+
24+
[plugins]: http://peterodding.com/code/vim/

autoload/xolox/misc/buffer.vim

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
" Vim auto-load script
2+
" Author: Peter Odding <[email protected]>
3+
" Last Change: September 4, 2011
4+
" URL: http://peterodding.com/code/vim/misc/
5+
6+
function! xolox#misc#buffer#is_empty()
7+
" Check if the current buffer is an empty, unchanged buffer which can be reused.
8+
return !&modified && expand('%') == '' && line('$') <= 1 && getline(1) == ''
9+
endfunction
10+
11+
function! xolox#misc#buffer#prepare(bufname)
12+
let bufname = '[' . a:bufname . ']'
13+
let buffers = tabpagebuflist()
14+
call map(buffers, 'fnamemodify(bufname(v:val), ":t:r")')
15+
let idx = index(buffers, bufname)
16+
if idx >= 0
17+
execute (idx + 1) . 'wincmd w'
18+
elseif !(xolox#misc#buffer#is_empty() || expand('%:t') == bufname)
19+
vsplit
20+
endif
21+
silent execute 'edit' fnameescape(bufname)
22+
lcd " clear working directory
23+
setlocal buftype=nofile bufhidden=hide noswapfile
24+
let &l:statusline = bufname
25+
call xolox#misc#buffer#unlock()
26+
silent %delete
27+
endfunction
28+
29+
function! xolox#misc#buffer#lock()
30+
" Lock a special buffer so it can no longer be edited.
31+
setlocal readonly nomodifiable nomodified
32+
endfunction
33+
34+
function! xolox#misc#buffer#unlock()
35+
" Unlock a special buffer so that its content can be updated.
36+
setlocal noreadonly modifiable
37+
endfunction

autoload/xolox/misc/complete.vim

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
" Vim auto-load script
2+
" Author: Peter Odding <[email protected]>
3+
" Last Change: March 15, 2011
4+
" URL: http://peterodding.com/code/vim/misc/
5+
6+
" Keyword completion from the current buffer for user defined commands.
7+
8+
function! xolox#misc#complete#keywords(arglead, cmdline, cursorpos)
9+
let words = {}
10+
for line in getline(1, '$')
11+
for word in split(line, '\W\+')
12+
let words[word] = 1
13+
endfor
14+
endfor
15+
return sort(keys(filter(words, 'v:key =~# a:arglead')))
16+
endfunction
17+
18+
" vim: ts=2 sw=2 et

autoload/xolox/misc/escape.vim

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
" Vim auto-load script
2+
" Author: Peter Odding <[email protected]>
3+
" Last Change: November 21, 2011
4+
" URL: http://peterodding.com/code/vim/misc/
5+
6+
" Convert a string into a :substitute pattern that matches the string literally.
7+
8+
function! xolox#misc#escape#pattern(string)
9+
if type(a:string) == type('')
10+
let string = escape(a:string, '^$.*\~[]')
11+
return substitute(string, '\n', '\\n', 'g')
12+
endif
13+
return ''
14+
endfunction
15+
16+
" Convert a string into a :substitute replacement that inserts the string literally.
17+
18+
function! xolox#misc#escape#substitute(string)
19+
if type(a:string) == type('')
20+
let string = escape(a:string, '\&~%')
21+
return substitute(string, '\n', '\\r', 'g')
22+
endif
23+
return ''
24+
endfunction
25+
26+
" Convert a string into a quoted command line argument. I was going to add a
27+
" long rant here about &shellslash, but really, it won't make any difference.
28+
" Let's just suffice to say that I have yet to encounter a single person out
29+
" there who uses this option for its intended purpose (running a UNIX-style
30+
" shell on Windows).
31+
32+
function! xolox#misc#escape#shell(string)
33+
if xolox#misc#os#is_win()
34+
try
35+
let ssl_save = &shellslash
36+
set noshellslash
37+
return shellescape(a:string)
38+
finally
39+
let &shellslash = ssl_save
40+
endtry
41+
else
42+
return shellescape(a:string)
43+
endif
44+
endfunction
45+
46+
" vim: ts=2 sw=2 et

autoload/xolox/misc/list.vim

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
" Vim auto-load script
2+
" Author: Peter Odding <[email protected]>
3+
" Last Change: August 31, 2011
4+
" URL: http://peterodding.com/code/vim/misc/
5+
6+
" Remove duplicate values from {list} in-place (preserves order).
7+
8+
function! xolox#misc#list#unique(list)
9+
call reverse(a:list)
10+
call filter(a:list, 'count(a:list, v:val) == 1')
11+
return reverse(a:list)
12+
endfunction
13+
14+
" Binary insertion (more efficient than calling sort() after each insertion).
15+
16+
function! xolox#misc#list#binsert(list, value, ...)
17+
let idx = s:binsert_r(a:list, 0, len(a:list), a:value, exists('a:1') && a:1)
18+
return insert(a:list, a:value, idx)
19+
endfunction
20+
21+
function! s:binsert_r(list, low, high, value, ignorecase)
22+
let mid = a:low + (a:high - a:low) / 2
23+
if a:low == a:high
24+
return a:low
25+
elseif a:ignorecase ? a:value >? a:list[mid] : a:value > a:list[mid]
26+
return s:binsert_r(a:list, mid + 1, a:high, a:value, a:ignorecase)
27+
elseif a:ignorecase ? a:value <? a:list[mid] : a:value < a:list[mid]
28+
return s:binsert_r(a:list, a:low, mid, a:value, a:ignorecase)
29+
else
30+
return mid
31+
endif
32+
endfunction
33+
34+
if 0
35+
" Tests for xolox#misc#list#binsert().
36+
let s:list = ['a', 'B', 'e']
37+
function! s:test(value, expected)
38+
call xolox#misc#list#binsert(s:list, a:value, 1)
39+
if s:list != a:expected
40+
call xolox#misc#msg#warn("list.vim: Test failed! Expected %s, got %s",
41+
\ string(a:expected), string(s:list))
42+
endif
43+
endfunction
44+
call s:test('c', ['a', 'B', 'c', 'e'])
45+
call s:test('D', ['a', 'B', 'c', 'D', 'e'])
46+
call s:test('f', ['a', 'B', 'c', 'D', 'e', 'f'])
47+
endif
48+
49+
" vim: ts=2 sw=2 et

autoload/xolox/misc/msg.vim

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
" Vim auto-load script
2+
" Author: Peter Odding <[email protected]>
3+
" Last Change: March 15, 2011
4+
" URL: http://peterodding.com/code/vim/misc/
5+
6+
if !exists('g:xolox_message_buffer')
7+
" For when I lose my :messages history :-\
8+
let g:xolox_message_buffer = 100
9+
endif
10+
11+
if !exists('g:xolox_messages')
12+
let g:xolox_messages = []
13+
endif
14+
15+
" Show a formatted informational message to the user.
16+
17+
function! xolox#misc#msg#info(...)
18+
call s:show_message('title', a:000)
19+
endfunction
20+
21+
" Show a formatted warning message to the user.
22+
23+
function! xolox#misc#msg#warn(...)
24+
call s:show_message('warningmsg', a:000)
25+
endfunction
26+
27+
" Show a formatted debugging message to the user?
28+
29+
function! xolox#misc#msg#debug(...)
30+
if &vbs >= 1
31+
call s:show_message('question', a:000)
32+
endif
33+
endfunction
34+
35+
" The implementation of info() and warn().
36+
37+
function! s:show_message(hlgroup, args)
38+
let nargs = len(a:args)
39+
if nargs == 1
40+
let message = a:args[0]
41+
elseif nargs >= 2
42+
let message = call('printf', a:args)
43+
endif
44+
if exists('message')
45+
try
46+
" Temporarily disable Vim's |hit-enter| prompt and mode display.
47+
if !exists('s:more_save')
48+
let s:more_save = &more
49+
let s:ruler_save = &ruler
50+
let s:smd_save = &showmode
51+
endif
52+
set nomore noshowmode
53+
if winnr('$') == 1 | set noruler | endif
54+
augroup PluginXoloxHideMode
55+
autocmd! CursorHold,CursorHoldI * call s:clear_message()
56+
augroup END
57+
execute 'echohl' a:hlgroup
58+
" Redraw to avoid |hit-enter| prompt.
59+
redraw | echomsg message
60+
if g:xolox_message_buffer > 0
61+
call add(g:xolox_messages, message)
62+
if len(g:xolox_messages) > g:xolox_message_buffer
63+
call remove(g:xolox_messages, 0)
64+
endif
65+
endif
66+
finally
67+
" Always clear message highlighting, even when interrupted by Ctrl-C.
68+
echohl none
69+
endtry
70+
endif
71+
endfunction
72+
73+
function! s:clear_message()
74+
echo ''
75+
let &more = s:more_save
76+
let &showmode = s:smd_save
77+
let &ruler = s:ruler_save
78+
unlet s:more_save s:ruler_save s:smd_save
79+
autocmd! PluginXoloxHideMode
80+
augroup! PluginXoloxHideMode
81+
endfunction
82+
83+
" vim: ts=2 sw=2 et

0 commit comments

Comments
 (0)