From 754ebd0b083b9fa185f886d42d9f796761d28311 Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Wed, 25 May 2011 22:06:22 +0200 Subject: Include open-associated-programs script --- open.vim | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 open.vim diff --git a/open.vim b/open.vim new file mode 100644 index 0000000..60d75e7 --- /dev/null +++ b/open.vim @@ -0,0 +1,71 @@ +" Vim auto-load script +" Author: Peter Odding +" Last Change: May 25, 2011 +" URL: http://peterodding.com/code/vim/misc/ + +if !exists('s:script') + let s:script = expand(':p:~') + let s:enoimpl = "%s: %s() hasn't been implemented for your platform!" + let s:enoimpl .= " 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("%s: Using `%s' to open %s", s:script, 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 = "%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:script, a:cmd, output) + endif +endfunction + +" vim: et ts=2 sw=2 fdm=marker -- cgit v1.2.3 From bc108a798eef89cbfe3c0daaa1729f77a0c18b3e Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Tue, 14 Jun 2011 16:49:14 +0200 Subject: Bug fix: Trim leading/trailing empty lines --- str.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/str.vim b/str.vim index 19bfe09..74a05aa 100644 --- a/str.vim +++ b/str.vim @@ -1,12 +1,12 @@ " Vim auto-load script " Author: Peter Odding -" 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 -- cgit v1.2.3 From 0eb0758ac7f76092ec5c74e402c5ec0e99a19b57 Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Tue, 14 Jun 2011 16:49:26 +0200 Subject: Update readme --- README.md | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d305ddd..3ef87b8 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,20 @@ # Miscellaneous auto-load Vim scripts -The git repository at 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 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" + +## Contact + +If you have questions, bug reports, suggestions, etc. the author can be contacted at . The latest version is available at and . + +## License + +This software is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License). +© 2011 Peter Odding <>. + [plugins]: http://peterodding.com/code/vim/ -- cgit v1.2.3 From 16e04cb66bef0d4e915caf7df667b753a031278e Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Tue, 14 Jun 2011 16:54:46 +0200 Subject: Don't forget merge instructions --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 3ef87b8..9111126 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,10 @@ The git repository at contains Vim scripts th $ 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 . The latest version is available at and . -- cgit v1.2.3 From 38996d3c8d7d55617a840d3cb22ad650bc7b60e0 Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Sat, 18 Jun 2011 04:35:27 +0200 Subject: open.vim: Define version as variable, include version in messages --- open.vim | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/open.vim b/open.vim index 60d75e7..30d2aa3 100644 --- a/open.vim +++ b/open.vim @@ -1,12 +1,11 @@ " Vim auto-load script " Author: Peter Odding -" Last Change: May 25, 2011 +" Last Change: June 18, 2011 " URL: http://peterodding.com/code/vim/misc/ -if !exists('s:script') - let s:script = expand(':p:~') - let s:enoimpl = "%s: %s() hasn't been implemented for your platform!" - let s:enoimpl .= " If you have suggestions, please contact peter@peterodding.com." +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 @@ -26,7 +25,7 @@ function! xolox#misc#open#file(path, ...) else for handler in s:handlers + a:000 if executable(handler) - call xolox#misc#msg#debug("%s: Using `%s' to open %s", s:script, handler, a:path) + 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 @@ -59,12 +58,12 @@ endfunction function! s:handle_error(cmd, output) if v:shell_error - let message = "%s: Failed to execute program! (command line: %s%s)" + 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:script, a:cmd, output) + throw printf(message, s:version, a:cmd, output) endif endfunction -- cgit v1.2.3 From e228b0e4e2cece3bbcbd3a752e7c718a455ab7c6 Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Sun, 26 Jun 2011 21:53:16 +0200 Subject: Option handling with xolox#misc#option#get({name}, {default}) --- option.vim | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/option.vim b/option.vim index f785e1b..8c6d63d 100644 --- a/option.vim +++ b/option.vim @@ -1,8 +1,18 @@ " Vim auto-load script " Author: Peter Odding -" 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) -- cgit v1.2.3