aboutsummaryrefslogtreecommitdiffstats
path: root/autoload/xolox/misc/list.vim
diff options
context:
space:
mode:
Diffstat (limited to 'autoload/xolox/misc/list.vim')
-rw-r--r--autoload/xolox/misc/list.vim24
1 files changed, 16 insertions, 8 deletions
diff --git a/autoload/xolox/misc/list.vim b/autoload/xolox/misc/list.vim
index ee243d4..13dfb43 100644
--- a/autoload/xolox/misc/list.vim
+++ b/autoload/xolox/misc/list.vim
@@ -1,19 +1,27 @@
-" Vim auto-load script
+" List handling functions.
+"
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: August 31, 2011
+" Last Change: May 19, 2013
" URL: http://peterodding.com/code/vim/misc/
-" Remove duplicate values from {list} in-place (preserves order).
-
-function! xolox#misc#list#unique(list)
+function! xolox#misc#list#unique(list) " {{{1
+ " Remove duplicate values from the given list in-place (preserves order).
call reverse(a:list)
call filter(a:list, 'count(a:list, v:val) == 1')
return reverse(a:list)
endfunction
-" Binary insertion (more efficient than calling sort() after each insertion).
-
-function! xolox#misc#list#binsert(list, value, ...)
+function! xolox#misc#list#binsert(list, value, ...) " {{{1
+ " Performs in-place binary insertion, which depending on your use case can
+ " be more efficient than calling Vim's [sort()] [sort] function after each
+ " insertion (in cases where a single, final sort is not an option). Expects
+ " three arguments:
+ "
+ " 1. A list
+ " 2. A value to insert
+ " 3. 1 (true) when case should be ignored, 0 (false) otherwise
+ "
+ " [sort]: http://vimdoc.sourceforge.net/htmldoc/eval.html#sort()
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