Skip to content

Commit e374c77

Browse files
committed
Merge branch 'master' of https://github.com/xolox/vim-misc
2 parents 435786b + 0b1c06e commit e374c77

File tree

4 files changed

+106
-12
lines changed

4 files changed

+106
-12
lines changed

autoload/xolox/misc/README.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
# Miscellaneous auto-load Vim scripts
22

3-
The git repository at <http://github.com/xolox/vim-misc> contains Vim scripts
4-
that are used by most of the [Vim plug-ins I've written] [plugins] yet don't
5-
really belong with any single one. I'm hoping to include this repository as a
6-
git submodule in my other repositories so that I only have to maintain these
7-
files in one place.
8-
9-
For lack of a better place: I hereby release these scripts under the MIT
10-
license, in other words feel free to do with them as you please but don't
11-
misrepresent this work as your own.
3+
The git repository at <http://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 <peter@peterodding.com>. The latest version is available at <http://peterodding.com/code/vim/misc> and <http://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;<peter@peterodding.com>&gt;.
22+
1223

1324
[plugins]: http://peterodding.com/code/vim/

autoload/xolox/misc/open.vim

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
" Vim auto-load script
2+
" Author: Peter Odding <peter@peterodding.com>
3+
" Last Change: June 18, 2011
4+
" URL: http://peterodding.com/code/vim/misc/
5+
6+
if !exists('s:version')
7+
let s:version = '1.0'
8+
let s:enoimpl = "open.vim %s: %s() hasn't been implemented for your platform! If you have suggestions, please contact peter@peterodding.com."
9+
let s:handlers = ['gnome-open', 'kde-open', 'exo-open', 'xdg-open']
10+
endif
11+
12+
function! xolox#misc#open#file(path, ...)
13+
if xolox#misc#os#is_win()
14+
try
15+
call xolox#shell#open_with_windows_shell(a:path)
16+
catch /^Vim\%((\a\+)\)\=:E117/
17+
let command = '!start CMD /C START "" %s'
18+
silent execute printf(command, shellescape(a:path))
19+
endtry
20+
return
21+
elseif has('macunix')
22+
let cmd = 'open ' . shellescape(a:path) . ' 2>&1'
23+
call s:handle_error(cmd, system(cmd))
24+
return
25+
else
26+
for handler in s:handlers + a:000
27+
if executable(handler)
28+
call xolox#misc#msg#debug("open.vim %s: Using '%s' to open '%s'.", s:version, handler, a:path)
29+
let cmd = shellescape(handler) . ' ' . shellescape(a:path) . ' 2>&1'
30+
call s:handle_error(cmd, system(cmd))
31+
return
32+
endif
33+
endfor
34+
endif
35+
throw printf(s:enoimpl, s:script, 'xolox#misc#open#file')
36+
endfunction
37+
38+
function! xolox#misc#open#url(url)
39+
let url = a:url
40+
if url !~ '^\w\+://'
41+
if url !~ '@'
42+
let url = 'http://' . url
43+
elseif url !~ '^mailto:'
44+
let url = 'mailto:' . url
45+
endif
46+
endif
47+
if has('unix') && !has('gui_running') && $DISPLAY == ''
48+
for browser in ['lynx', 'links', 'w3m']
49+
if executable(browser)
50+
execute '!' . browser fnameescape(url)
51+
call s:handle_error(browser . ' ' . url, '')
52+
return
53+
endif
54+
endfor
55+
endif
56+
call xolox#misc#open#file(url, 'firefox', 'google-chrome')
57+
endfunction
58+
59+
function! s:handle_error(cmd, output)
60+
if v:shell_error
61+
let message = "open.vim %s: Failed to execute program! (command line: %s%s)"
62+
let output = strtrans(xolox#misc#str#trim(a:output))
63+
if output != ''
64+
let output = ", output: " . string(output)
65+
endif
66+
throw printf(message, s:version, a:cmd, output)
67+
endif
68+
endfunction
69+
70+
" vim: et ts=2 sw=2 fdm=marker

autoload/xolox/misc/option.vim

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

6+
function! xolox#misc#option#get(name, ...)
7+
if exists('b:' . a:name)
8+
" Buffer local variable.
9+
return eval('b:' . a:name)
10+
elseif exists('g:' . a:name)
11+
" Global variable.
12+
return eval('g:' . a:name)
13+
elseif exists('a:1')
14+
" Default value.
15+
return a:1
16+
endif
17+
endfunction
18+
619
" Functions to parse multi-valued Vim options like &tags and &runtimepath.
720

821
function! xolox#misc#option#split(value)

autoload/xolox/misc/str.vim

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

66
" Trim whitespace from start and end of string.
77

88
function! xolox#misc#str#trim(s)
9-
return substitute(a:s, '^\s*\(.\{-}\)\s*$', '\1', '')
9+
return substitute(a:s, '^\_s*\(.\{-}\)\_s*$', '\1', '')
1010
endfunction
1111

1212
" vim: ts=2 sw=2 et

0 commit comments

Comments
 (0)