Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' of https://github.com/xolox/vim-misc
  • Loading branch information
xolox committed Aug 31, 2011
2 parents 435786b + 0b1c06e commit e374c77
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 12 deletions.
29 changes: 20 additions & 9 deletions autoload/xolox/misc/README.md
@@ -1,13 +1,24 @@
# Miscellaneous auto-load Vim scripts

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'm hoping to include this repository as a
git submodule in my other repositories so that I only have to maintain these
files in one place.

For lack of a better place: I hereby release these scripts under the MIT
license, in other words feel free to do with them as you please but don't
misrepresent this work as your own.
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:

$ git remote add -f vim-misc https://github.com/xolox/vim-misc.git
$ git merge -s ours --no-commit vim-misc/master
$ git read-tree --prefix=autoload/xolox/misc/ -u vim-misc/master
$ git commit -m "Merge vim-misc repository as subdirectory"

To update a plug-in repository to the latest versions of the miscellaneous auto-load scripts I execute the following command:

$ git pull -s subtree vim-misc master

## Contact

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>.

## License

This software is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License).
© 2011 Peter Odding &lt;<peter@peterodding.com>&gt;.


[plugins]: http://peterodding.com/code/vim/
70 changes: 70 additions & 0 deletions autoload/xolox/misc/open.vim
@@ -0,0 +1,70 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
" Last Change: June 18, 2011
" URL: http://peterodding.com/code/vim/misc/

if !exists('s:version')
let s:version = '1.0'
let s:enoimpl = "open.vim %s: %s() hasn't been implemented for your platform! If you have suggestions, please contact peter@peterodding.com."
let s:handlers = ['gnome-open', 'kde-open', 'exo-open', 'xdg-open']
endif

function! xolox#misc#open#file(path, ...)
if xolox#misc#os#is_win()
try
call xolox#shell#open_with_windows_shell(a:path)
catch /^Vim\%((\a\+)\)\=:E117/
let command = '!start CMD /C START "" %s'
silent execute printf(command, shellescape(a:path))
endtry
return
elseif has('macunix')
let cmd = 'open ' . shellescape(a:path) . ' 2>&1'
call s:handle_error(cmd, system(cmd))
return
else
for handler in s:handlers + a:000
if executable(handler)
call xolox#misc#msg#debug("open.vim %s: Using '%s' to open '%s'.", s:version, handler, a:path)
let cmd = shellescape(handler) . ' ' . shellescape(a:path) . ' 2>&1'
call s:handle_error(cmd, system(cmd))
return
endif
endfor
endif
throw printf(s:enoimpl, s:script, 'xolox#misc#open#file')
endfunction

function! xolox#misc#open#url(url)
let url = a:url
if url !~ '^\w\+://'
if url !~ '@'
let url = 'http://' . url
elseif url !~ '^mailto:'
let url = 'mailto:' . url
endif
endif
if has('unix') && !has('gui_running') && $DISPLAY == ''
for browser in ['lynx', 'links', 'w3m']
if executable(browser)
execute '!' . browser fnameescape(url)
call s:handle_error(browser . ' ' . url, '')
return
endif
endfor
endif
call xolox#misc#open#file(url, 'firefox', 'google-chrome')
endfunction

function! s:handle_error(cmd, output)
if v:shell_error
let message = "open.vim %s: Failed to execute program! (command line: %s%s)"
let output = strtrans(xolox#misc#str#trim(a:output))
if output != ''
let output = ", output: " . string(output)
endif
throw printf(message, s:version, a:cmd, output)
endif
endfunction

" vim: et ts=2 sw=2 fdm=marker
15 changes: 14 additions & 1 deletion autoload/xolox/misc/option.vim
@@ -1,8 +1,21 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
" Last Change: March 15, 2011
" Last Change: June 27, 2011
" URL: http://peterodding.com/code/vim/misc/

function! xolox#misc#option#get(name, ...)
if exists('b:' . a:name)
" Buffer local variable.
return eval('b:' . a:name)
elseif exists('g:' . a:name)
" Global variable.
return eval('g:' . a:name)
elseif exists('a:1')
" Default value.
return a:1
endif
endfunction

" Functions to parse multi-valued Vim options like &tags and &runtimepath.

function! xolox#misc#option#split(value)
Expand Down
4 changes: 2 additions & 2 deletions autoload/xolox/misc/str.vim
@@ -1,12 +1,12 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
" Last Change: March 15, 2011
" Last Change: June 14, 2011
" URL: http://peterodding.com/code/vim/misc/

" Trim whitespace from start and end of string.

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

" vim: ts=2 sw=2 et

0 comments on commit e374c77

Please sign in to comment.