aboutsummaryrefslogtreecommitdiffstats
path: root/autoload/xolox
diff options
context:
space:
mode:
authorPeter Odding <peter@peterodding.com>2011-06-26 21:54:20 +0200
committerPeter Odding <peter@peterodding.com>2011-06-26 21:54:20 +0200
commit4cf1efd96f9788e3221234cf14fa9e3ac89cedb9 (patch)
tree940accf6c142040a757b3bec54911900c46f1a78 /autoload/xolox
parente8db2a2bba0e4718ae1887424e831fb24874506f (diff)
parente228b0e4e2cece3bbcbd3a752e7c718a455ab7c6 (diff)
downloadvim-easytags-4cf1efd96f9788e3221234cf14fa9e3ac89cedb9.tar.gz
Merge branch 'master' of https://github.com/xolox/vim-misc
Diffstat (limited to 'autoload/xolox')
-rw-r--r--autoload/xolox/misc/README.md29
-rw-r--r--autoload/xolox/misc/open.vim70
-rw-r--r--autoload/xolox/misc/option.vim12
-rw-r--r--autoload/xolox/misc/str.vim4
4 files changed, 103 insertions, 12 deletions
diff --git a/autoload/xolox/misc/README.md b/autoload/xolox/misc/README.md
index d305ddd..9111126 100644
--- a/autoload/xolox/misc/README.md
+++ b/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/
diff --git a/autoload/xolox/misc/open.vim b/autoload/xolox/misc/open.vim
new file mode 100644
index 0000000..30d2aa3
--- /dev/null
+++ b/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
diff --git a/autoload/xolox/misc/option.vim b/autoload/xolox/misc/option.vim
index f785e1b..8c6d63d 100644
--- a/autoload/xolox/misc/option.vim
+++ b/autoload/xolox/misc/option.vim
@@ -1,8 +1,18 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: March 15, 2011
+" Last Change: June 26, 2011
" URL: http://peterodding.com/code/vim/misc/
+function! xolox#misc#option#get(name, default)
+ if exists('g:' . a:name)
+ return eval('g:' . a:name)
+ elseif exists('b:' . a:name)
+ return eval('b:' . a:name)
+ else
+ return a:default
+ endif
+endfunction
+
" Functions to parse multi-valued Vim options like &tags and &runtimepath.
function! xolox#misc#option#split(value)
diff --git a/autoload/xolox/misc/str.vim b/autoload/xolox/misc/str.vim
index 19bfe09..74a05aa 100644
--- a/autoload/xolox/misc/str.vim
+++ b/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