aboutsummaryrefslogtreecommitdiffstats
path: root/autoload/xolox
diff options
context:
space:
mode:
authorPeter Odding <peter@peterodding.com>2011-08-31 23:23:52 +0200
committerPeter Odding <peter@peterodding.com>2011-08-31 23:23:52 +0200
commit2860329687750c271135e28e24fe5fc9034c9c74 (patch)
tree8d140c8846c98f2febe19c00a823e74b27849f8a /autoload/xolox
parent4e1131e152693b2ac4b17941851319124b390f2c (diff)
parent571abe35c99566996381b716c6f87756fef34748 (diff)
downloadvim-easytags-2860329687750c271135e28e24fe5fc9034c9c74.tar.gz
Merge branch 'master' of https://github.com/xolox/vim-misc
Diffstat (limited to 'autoload/xolox')
-rw-r--r--autoload/xolox/misc/list.vim37
-rw-r--r--autoload/xolox/misc/option.vim27
-rw-r--r--autoload/xolox/misc/path.vim15
3 files changed, 76 insertions, 3 deletions
diff --git a/autoload/xolox/misc/list.vim b/autoload/xolox/misc/list.vim
index 8857af1..44d6b20 100644
--- a/autoload/xolox/misc/list.vim
+++ b/autoload/xolox/misc/list.vim
@@ -1,6 +1,6 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: March 15, 2011
+" Last Change: August 31, 2011
" URL: http://peterodding.com/code/vim/misc/
" Remove duplicate values from {list} in-place (preserves order).
@@ -20,4 +20,39 @@ function! xolox#misc#list#unique(list)
return a:list
endfunction
+" Binary insertion (more efficient than calling sort() after each insertion).
+
+function! xolox#misc#list#binsert(list, value, ...)
+ let idx = s:binsert_r(a:list, 0, len(a:list), a:value, exists('a:1') && a:1)
+ return insert(a:list, a:value, idx)
+endfunction
+
+function! s:binsert_r(list, low, high, value, ignorecase)
+ let mid = a:low + (a:high - a:low) / 2
+ if a:low == a:high
+ return a:low
+ elseif a:ignorecase ? a:value >? a:list[mid] : a:value > a:list[mid]
+ return s:binsert_r(a:list, mid + 1, a:high, a:value, a:ignorecase)
+ elseif a:ignorecase ? a:value <? a:list[mid] : a:value < a:list[mid]
+ return s:binsert_r(a:list, a:low, mid, a:value, a:ignorecase)
+ else
+ return mid
+ endif
+endfunction
+
+if 0
+ " Tests for xolox#misc#list#binsert().
+ let s:list = ['a', 'B', 'e']
+ function! s:test(value, expected)
+ call xolox#misc#list#binsert(s:list, a:value, 1)
+ if s:list != a:expected
+ call xolox#misc#msg#warn("list.vim: Test failed! Expected %s, got %s",
+ \ string(a:expected), string(s:list))
+ endif
+ endfunction
+ call s:test('c', ['a', 'B', 'c', 'e'])
+ call s:test('D', ['a', 'B', 'c', 'D', 'e'])
+ call s:test('f', ['a', 'B', 'c', 'D', 'e', 'f'])
+endif
+
" vim: ts=2 sw=2 et
diff --git a/autoload/xolox/misc/option.vim b/autoload/xolox/misc/option.vim
index 8727ea1..efaf1bc 100644
--- a/autoload/xolox/misc/option.vim
+++ b/autoload/xolox/misc/option.vim
@@ -1,6 +1,6 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: June 27, 2011
+" Last Change: August 31, 2011
" URL: http://peterodding.com/code/vim/misc/
function! xolox#misc#option#get(name, ...)
@@ -56,4 +56,29 @@ function! s:escape_tags(s)
return escape(a:s, ', ')
endfunction
+function! xolox#misc#option#eval_tags(value, ...)
+ let pathnames = []
+ let first_only = exists('a:1') && a:1
+ for pattern in xolox#misc#option#split_tags(a:value)
+ " Make buffer relative pathnames absolute.
+ if pattern =~ '^\./'
+ let directory = xolox#misc#escape#substitute(expand('%:p:h'))
+ let pattern = substitute(pattern, '^.\ze/', directory, '')
+ endif
+ " Make working directory relative pathnames absolute.
+ if xolox#misc#path#is_relative(pattern)
+ let pattern = xolox#misc#path#merge(getcwd(), pattern)
+ endif
+ " Ignore the trailing `;' for recursive upwards searching because we
+ " always want the most specific pathname available.
+ let pattern = substitute(pattern, ';$', '', '')
+ " Expand the pattern.
+ call extend(pathnames, split(expand(pattern), "\n"))
+ if first_only && !empty(pathnames)
+ return pathnames[0]
+ endif
+ endfor
+ return firstonly ? '' : pathnames
+endfunction
+
" vim: ts=2 sw=2 et
diff --git a/autoload/xolox/misc/path.vim b/autoload/xolox/misc/path.vim
index 2b4510f..ee0f2e2 100644
--- a/autoload/xolox/misc/path.vim
+++ b/autoload/xolox/misc/path.vim
@@ -1,6 +1,6 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: March 15, 2011
+" Last Change: August 31, 2011
" URL: http://peterodding.com/code/vim/misc/
let s:windows_compatible = has('win32') || has('win64')
@@ -69,6 +69,7 @@ endfunction
" Join a directory and filename into a single pathname.
function! xolox#misc#path#merge(parent, child, ...)
+ " TODO Use isabs()!
if type(a:parent) == type('') && type(a:child) == type('')
if s:windows_compatible
let parent = substitute(a:parent, '[\\/]\+$', '', '')
@@ -127,6 +128,18 @@ else
endfunction
endif
+" Check whether a path is relative.
+
+function! xolox#misc#path#is_relative(path)
+ if a:path =~ '^\w\+://'
+ return 0
+ elseif s:windows_compatible
+ return a:path !~ '^\(\w:\|[\\/]\)'
+ else
+ return a:path !~ '^/'
+ endif
+endfunction
+
" Create a temporary directory and return the path.
function! xolox#misc#path#tempdir()