Skip to content

Commit 96e63ff

Browse files
committed
Merge branch 'master' of https://github.com/xolox/vim-misc
2 parents 93d504a + 571abe3 commit 96e63ff

File tree

3 files changed

+76
-3
lines changed

3 files changed

+76
-3
lines changed

autoload/xolox/misc/list.vim

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Vim auto-load script
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: March 15, 2011
3+
" Last Change: August 31, 2011
44
" URL: http://peterodding.com/code/vim/misc/
55

66
" Remove duplicate values from {list} in-place (preserves order).
@@ -20,4 +20,39 @@ function! xolox#misc#list#unique(list)
2020
return a:list
2121
endfunction
2222

23+
" Binary insertion (more efficient than calling sort() after each insertion).
24+
25+
function! xolox#misc#list#binsert(list, value, ...)
26+
let idx = s:binsert_r(a:list, 0, len(a:list), a:value, exists('a:1') && a:1)
27+
return insert(a:list, a:value, idx)
28+
endfunction
29+
30+
function! s:binsert_r(list, low, high, value, ignorecase)
31+
let mid = a:low + (a:high - a:low) / 2
32+
if a:low == a:high
33+
return a:low
34+
elseif a:ignorecase ? a:value >? a:list[mid] : a:value > a:list[mid]
35+
return s:binsert_r(a:list, mid + 1, a:high, a:value, a:ignorecase)
36+
elseif a:ignorecase ? a:value <? a:list[mid] : a:value < a:list[mid]
37+
return s:binsert_r(a:list, a:low, mid, a:value, a:ignorecase)
38+
else
39+
return mid
40+
endif
41+
endfunction
42+
43+
if 0
44+
" Tests for xolox#misc#list#binsert().
45+
let s:list = ['a', 'B', 'e']
46+
function! s:test(value, expected)
47+
call xolox#misc#list#binsert(s:list, a:value, 1)
48+
if s:list != a:expected
49+
call xolox#misc#msg#warn("list.vim: Test failed! Expected %s, got %s",
50+
\ string(a:expected), string(s:list))
51+
endif
52+
endfunction
53+
call s:test('c', ['a', 'B', 'c', 'e'])
54+
call s:test('D', ['a', 'B', 'c', 'D', 'e'])
55+
call s:test('f', ['a', 'B', 'c', 'D', 'e', 'f'])
56+
endif
57+
2358
" vim: ts=2 sw=2 et

autoload/xolox/misc/option.vim

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Vim auto-load script
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: June 27, 2011
3+
" Last Change: August 31, 2011
44
" URL: http://peterodding.com/code/vim/misc/
55

66
function! xolox#misc#option#get(name, ...)
@@ -56,4 +56,29 @@ function! s:escape_tags(s)
5656
return escape(a:s, ', ')
5757
endfunction
5858

59+
function! xolox#misc#option#eval_tags(value, ...)
60+
let pathnames = []
61+
let first_only = exists('a:1') && a:1
62+
for pattern in xolox#misc#option#split_tags(a:value)
63+
" Make buffer relative pathnames absolute.
64+
if pattern =~ '^\./'
65+
let directory = xolox#misc#escape#substitute(expand('%:p:h'))
66+
let pattern = substitute(pattern, '^.\ze/', directory, '')
67+
endif
68+
" Make working directory relative pathnames absolute.
69+
if xolox#misc#path#is_relative(pattern)
70+
let pattern = xolox#misc#path#merge(getcwd(), pattern)
71+
endif
72+
" Ignore the trailing `;' for recursive upwards searching because we
73+
" always want the most specific pathname available.
74+
let pattern = substitute(pattern, ';$', '', '')
75+
" Expand the pattern.
76+
call extend(pathnames, split(expand(pattern), "\n"))
77+
if first_only && !empty(pathnames)
78+
return pathnames[0]
79+
endif
80+
endfor
81+
return firstonly ? '' : pathnames
82+
endfunction
83+
5984
" vim: ts=2 sw=2 et

autoload/xolox/misc/path.vim

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Vim auto-load script
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: March 15, 2011
3+
" Last Change: August 31, 2011
44
" URL: http://peterodding.com/code/vim/misc/
55

66
let s:windows_compatible = has('win32') || has('win64')
@@ -69,6 +69,7 @@ endfunction
6969
" Join a directory and filename into a single pathname.
7070

7171
function! xolox#misc#path#merge(parent, child, ...)
72+
" TODO Use isabs()!
7273
if type(a:parent) == type('') && type(a:child) == type('')
7374
if s:windows_compatible
7475
let parent = substitute(a:parent, '[\\/]\+$', '', '')
@@ -127,6 +128,18 @@ else
127128
endfunction
128129
endif
129130

131+
" Check whether a path is relative.
132+
133+
function! xolox#misc#path#is_relative(path)
134+
if a:path =~ '^\w\+://'
135+
return 0
136+
elseif s:windows_compatible
137+
return a:path !~ '^\(\w:\|[\\/]\)'
138+
else
139+
return a:path !~ '^/'
140+
endif
141+
endfunction
142+
130143
" Create a temporary directory and return the path.
131144

132145
function! xolox#misc#path#tempdir()

0 commit comments

Comments
 (0)