Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improved auto-detection of the appropriate browser (CLI vs. GUI)
  • Loading branch information
xolox committed May 28, 2010
1 parent 66bbffc commit dd6901c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
16 changes: 9 additions & 7 deletions README.md
@@ -1,13 +1,15 @@
The file [pyref.vim][formatted_pyref_vim] is a plug-in for the Vim text editor that maps the `<F1>`
key in Python buffers to search through the Python language and library
reference documentation for the keyword or identifier at the current cursor
position and open the first match in your web browser. This works in both
graphical Vim and console Vim.
The file [pyref.vim][formatted_pyref_vim] is a plug-in for the Vim text editor
that maps the `<F1>` key in Python buffers to search through the Python
language and library reference documentation for the keyword or identifier at
the current cursor position and open the first match in your web browser. When
no GUI is available a command-line web browser like `lynx` or `w3m` will be
used, otherwise the plug-in prefers a graphical web browser like Mozilla
Firefox or Google Chrome.

The search works by scanning through a special index file with keyword, URL
pairs separated by tabs and delimited by newlines. You can create this index
yourself using a Python script I've written (see [create-index.py][formatted_create_index_py]) or you
can download the index that I've already created (see [vimpythonindex][formatted_vimpythonindex]).
yourself using a Python script I've written (see [create-index.py][formatted_create_index_py])
or you can download the index that I've already created (see [vimpythonindex][formatted_vimpythonindex]).

[formatted_pyref_vim]: http://github.com/xolox/vim-pyref/blob/master/pyref.vim
[formatted_create_index_py]: http://github.com/xolox/vim-pyref/blob/master/create-index.py
Expand Down
15 changes: 11 additions & 4 deletions pyref.vim
Expand Up @@ -72,10 +72,17 @@ if !exists('pyref_browser')
" On Windows the default web browser is accessible using the START command.
let pyref_browser = 'CMD /C START ""'
else
" On UNIX we decide whether to use a CLI or GUI web browser based on
" whether the $DISPLAY environment variable is set.
if $DISPLAY == ''
let s:known_browsers = ['lynx', 'links', 'w3m']
else
" Note: Don't use `xdg-open' here, it ignores fragment identifiers :-S
let s:known_browsers = ['gnome-open', 'firefox', 'google-chrome', 'konqueror']
endif
" Otherwise we search for a sensible default browser.
let s:search_path = substitute(substitute($PATH, ',', '\\,', 'g'), ':', ',', 'g')
" Note: Don't use `xdg-open' here, it ignores fragment identifiers :-S
for s:browser in ['gnome-open', 'firefox', 'google-chrome']
for s:browser in s:known_browsers
" Use globpath()'s third argument where possible (since Vim 7.3?).
try
let s:matches = split(globpath(s:search_path, s:browser, 1), '\n')
Expand All @@ -87,7 +94,7 @@ if !exists('pyref_browser')
break
endif
endfor
unlet s:search_path s:browser s:matches
unlet s:search_path s:known_browsers s:browser s:matches
if !exists('pyref_browser')
let message = "pyref.vim: Failed to find a default web browser!"
echoerr message . "\nPlease set the global variable `pyref_browser' manually."
Expand Down Expand Up @@ -188,7 +195,7 @@ endfunction

function! s:OpenBrowser(url)
let browser = g:pyref_browser
if browser =~ '\<\(lynx\|links\)\>'
if browser =~ '\<\(lynx\|links\|w3m\)\>'
execute '!' . browser fnameescape(a:url)
else
if browser !~ '^CMD /C START'
Expand Down

0 comments on commit dd6901c

Please sign in to comment.