├── .gitignore ├── INSTALL.md ├── README.md ├── TODO.md ├── addon-info.json ├── autoload └── xolox │ └── pyref.vim ├── doc └── pyref.txt ├── misc └── pyref │ ├── index │ └── spider.py └── plugin └── pyref.vim /.gitignore: -------------------------------------------------------------------------------- 1 | doc/tags 2 | -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | *Please note that the vim-pyref plug-in requires my vim-misc plug-in which is separately distributed.* 2 | 3 | Unzip the most recent ZIP archives of the [vim-pyref] [download-pyref] and [vim-misc] [download-misc] plug-ins inside your Vim profile directory (usually this is `~/.vim` on UNIX and `%USERPROFILE%\vimfiles` on Windows), restart Vim and execute the command `:helptags ~/.vim/doc` (use `:helptags ~\vimfiles\doc` instead on Windows). 4 | 5 | If you prefer you can also use [Pathogen] [pathogen], [Vundle] [vundle] or a similar tool to install & update the [vim-pyref] [github-pyref] and [vim-misc] [github-misc] plug-ins using a local clone of the git repository. 6 | 7 | 8 | [download-misc]: http://peterodding.com/code/vim/downloads/misc.zip 9 | [download-pyref]: http://peterodding.com/code/vim/downloads/pyref.zip 10 | [github-misc]: http://github.com/xolox/vim-misc 11 | [github-pyref]: http://github.com/xolox/vim-pyref 12 | [pathogen]: http://www.vim.org/scripts/script.php?script_id=2332 13 | [vundle]: https://github.com/gmarik/vundle 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Context-sensitive documentation
for Python source code in Vim 2 | 3 | The `pyref.vim` script is a plug-in for the [Vim text editor](http://www.vim.org/) that helps you look up the documentation for keywords and identifiers from the following sources using your web browser: 4 | 5 | * [Python language reference](http://docs.python.org/reference/) 6 | * [Python library reference](http://docs.python.org/library/) 7 | * [Django documentation](http://docs.djangoproject.com/) 8 | 9 | The `:PyRef` command looks up the identifier given as an argument while the `` mapping (only available in Python buffers) looks up the item under the text cursor. The lookup works by scanning through a special index file which is included in the ZIP archive below, but you can also create/update the index yourself using the Python script [spider.py](http://github.com/xolox/vim-pyref/blob/master/spider.py). 10 | 11 | ## Install & usage 12 | 13 | *Please note that the vim-pyref plug-in requires my vim-misc plug-in which is separately distributed.* 14 | 15 | Unzip the most recent ZIP archives of the [vim-pyref] [download-pyref] and [vim-misc] [download-misc] plug-ins inside your Vim profile directory (usually this is `~/.vim` on UNIX and `%USERPROFILE%\vimfiles` on Windows), restart Vim and execute the command `:helptags ~/.vim/doc` (use `:helptags ~\vimfiles\doc` instead on Windows). 16 | 17 | If you prefer you can also use [Pathogen] [pathogen], [Vundle] [vundle] or a similar tool to install & update the [vim-pyref] [github-pyref] and [vim-misc] [github-misc] plug-ins using a local clone of the git repository. 18 | 19 | Now try it out: Open a Python script and press the `` key on something interesting. If it doesn't work or you want to change how it works, see the options documented below. 20 | 21 | [download-misc]: http://peterodding.com/code/vim/downloads/misc.zip 22 | [download-pyref]: http://peterodding.com/code/vim/downloads/pyref.zip 23 | [github-misc]: http://github.com/xolox/vim-misc 24 | [github-pyref]: http://github.com/xolox/vim-pyref 25 | [pathogen]: http://www.vim.org/scripts/script.php?script_id=2332 26 | [vundle]: https://github.com/gmarik/vundle 27 | 28 | ### The `g:pyref_mapping` option 29 | 30 | If you press `` and nothing happens you're probably using a terminal that doesn't pass `` through to Vim. In this case you can change the key mapping by setting the global variable `g:pyref_mapping` according to the syntax expected by Vim's `:imap` and `:nmap` commands: 31 | 32 | :let g:pyref_mapping = 'K' 33 | 34 | Note that setting `g:pyref_mapping` won't change the key mapping in existing buffers. 35 | 36 | ### The `g:pyref_python` option 37 | 38 | This option is useful when you don't always have a reliable internet connection available while coding. Most Linux distributions have an installable package containing the Python documentation, for example on [Ubuntu](http://packages.ubuntu.com/python2.6-doc) and [Debian](http://packages.debian.org/python2.6-doc) you can execute the following command to install the documentation: 39 | 40 | $ sudo apt-get install python2.6-doc 41 | 42 | The above package puts the documentation in `/usr/share/doc/python2.6/html/` which happens to be the default path checked by the `pyref.vim` script. If you've installed the documentation in a different location you can change the global variable `g:pyref_python`, e.g.: 43 | 44 | :let g:pyref_python = $HOME . '/docs/python' 45 | 46 | ### The `g:pyref_django` option 47 | 48 | This option works like `g:pyref_python` but allows you to configure the path to your local Django documentation. On [Ubuntu](http://packages.ubuntu.com/python-django-doc) and [Debian](http://packages.debian.org/python-django-doc) you can execute the following command to install the Django documentation: 49 | 50 | $ sudo apt-get install python-django-doc 51 | 52 | In this case you shouldn't have to change anything because `pyref.vim` is already configured to be compatible with the `python-django-doc` package. 53 | 54 | ### The `g:pyref_index` option 55 | 56 | If you don't like the default location of the index file you can change it by setting the global variable `g:pyref_index`. A leading `~` in the `g:pyref_index` variable is expanded to your current home directory (`$HOME` on UNIX, `%USERPROFILE%` on Windows). Be aware that when you change the `g:pyref_index` option automatic updates using the [getscript plug-in](http://vimdoc.sourceforge.net/htmldoc/pi_getscript.html#getscript) won't update the index file anymore! 57 | 58 | ### General note about options 59 | 60 | You can change the above options permanently by putting the relevant `:let` statements in your [vimrc script](http://vimdoc.sourceforge.net/htmldoc/starting.html#vimrc). 61 | 62 | ## Contact 63 | 64 | If you have questions, bug reports, suggestions, etc. the author can be contacted at . The latest version is available at and . If you like the script please vote for it on [Vim Online](http://www.vim.org/scripts/script.php?script_id=3104). 65 | 66 | ## License 67 | 68 | This software is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License). 69 | © 2013 Peter Odding <>. 70 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | # To-do list 2 | 3 | * Switch to `python-doc` package instead of `python2.6-doc`? 4 | -------------------------------------------------------------------------------- /addon-info.json: -------------------------------------------------------------------------------- 1 | {"vim_script_nr": 3104, "dependencies": {"vim-misc": {}}, "homepage": "http://peterodding.com/code/vim/pyref", "name": "vim-pyref"} -------------------------------------------------------------------------------- /autoload/xolox/pyref.vim: -------------------------------------------------------------------------------- 1 | " Vim auto-load script 2 | " Author: Peter Odding 3 | " Last Change: August 20, 2013 4 | " URL: http://peterodding.com/code/vim/pyref/ 5 | 6 | let g:xolox#pyref#version = '0.7.16' 7 | let s:script = expand(':p:~') 8 | 9 | function! xolox#pyref#enable() " {{{1 10 | let command = '%s %s %s:call xolox#pyref#at_cursor()' 11 | let mapping = exists('g:pyref_mapping') ? g:pyref_mapping : '' 12 | execute printf(command, 'nmap', mapping, '') 13 | if mapping =~ '^<[^>]\+>' 14 | execute printf(command, 'imap', mapping, '') 15 | endif 16 | endfunction 17 | 18 | function! xolox#pyref#at_cursor() " {{{1 19 | try 20 | let isk_save = &isk 21 | let &isk = '@,48-57,_,192-255,.' 22 | let ident = expand('') 23 | finally 24 | let &isk = isk_save 25 | endtry 26 | call xolox#pyref#lookup(ident) 27 | endfunction 28 | 29 | function! xolox#pyref#complete(arglead, cmdline, cursorpos) " {{{1 30 | let entries = map(s:read_index(), 'matchstr(v:val, ''^\S\+'')') 31 | let pattern = xolox#misc#escape#pattern(a:arglead) 32 | call filter(entries, 'v:val =~ pattern') 33 | if len(entries) > &lines 34 | let entries = entries[0 : &lines - 1] 35 | call add(entries, '...') 36 | endif 37 | return entries 38 | endfunction 39 | 40 | function! xolox#pyref#lookup(identifier) " {{{1 41 | 42 | let ident = xolox#misc#str#trim(a:identifier) 43 | 44 | " Do something useful when there's nothing at the current position. 45 | if ident == '' 46 | call s:show_match('http://docs.python.org/contents.html') 47 | return 48 | endif 49 | 50 | " Escape any dots in the expression so it can be used as a pattern. 51 | let pattern = substitute(ident, '\.', '\\.', 'g') 52 | let lines = s:read_index() 53 | 54 | " Search for an exact match of a module name or identifier in the index. 55 | if s:try_lookup(lines, '^\C\(module-\|exceptions\.\)\?' . pattern . '\t') 56 | return 57 | endif 58 | 59 | " Search for a substring match on word boundaries. 60 | if s:try_lookup(lines, '\C\<' . pattern . '\>.*\t') 61 | return 62 | endif 63 | 64 | " Try to match a method name of one of the standard Python types: strings, 65 | " lists, dictionaries and files (not exactly ideal but better than nothing). 66 | for [url, method_pattern] in [ 67 | \ ['library/stdtypes.html#str.%s', '\C\.\@<=\(capitalize\|center\|count\|decode\|encode\|endswith\|expandtabs\|find\|format\|index\|isalnum\|isalpha\|isdigit\|islower\|isspace\|istitle\|isupper\|join\|ljust\|lower\|lstrip\|partition\|replace\|rfind\|rindex\|rjust\|rpartition\|rsplit\|rstrip\|split\|splitlines\|startswith\|strip\|swapcase\|title\|translate\|upper\|zfill\)$'], 68 | \ ['tutorial/datastructures.html#more-on-lists', '\C\.\@<=\(append\|count\|extend\|index\|insert\|pop\|remove\|reverse\|sort\)$'], 69 | \ ['library/stdtypes.html#dict.%s', '\C\.\@<=\(clear\|copy\|fromkeys\|get\|has_key\|items\|iteritems\|iterkeys\|itervalues\|keys\|pop\|popitem\|setdefault\|update\|values\)$'], 70 | \ ['library/stdtypes.html#file.%s', '\C\.\@<=\(close\|closed\|encoding\|errors\|fileno\|flush\|isatty\|mode\|name\|newlines\|next\|read\|readinto\|readline\|readlines\|seek\|softspace\|tell\|truncate\|write\|writelines\|xreadlines\)$']] 71 | let method = matchstr(ident, method_pattern) 72 | if method != '' 73 | if url =~ '%s' 74 | let url = printf(url, method) 75 | endif 76 | call s:show_match('http://docs.python.org/' . url) 77 | return 78 | endif 79 | endfor 80 | 81 | " Search for a substring match in the index. 82 | if s:try_lookup(lines, '\C' . pattern . '.*\t') 83 | return 84 | endif 85 | 86 | " Split the expression on all dots and search for a progressively smaller 87 | " suffix to resolve object attributes like "self.parser.add_option" to 88 | " global identifiers like "optparse.OptionParser.add_option". This relies 89 | " on the uniqueness of the method names in the standard library. 90 | let parts = split(ident, '\.') 91 | while len(parts) > 1 92 | call remove(parts, 0) 93 | let pattern = '\C\<' . join(parts, '\.') . '$' 94 | if s:try_lookup(lines, pattern) 95 | return 96 | endif 97 | endwhile 98 | 99 | " As a last resort, try Google's "I'm Feeling Lucky" search. 100 | call xolox#misc#open#url('http://google.com/search?btnI&q=python+' . ident) 101 | 102 | endfunction 103 | 104 | function! s:try_lookup(lines, pattern) " {{{1 105 | call xolox#misc#msg#debug("pyref.vim %s: Trying to match pattern %s", g:xolox#pyref#version, a:pattern) 106 | let index = match(a:lines, a:pattern) 107 | if index >= 0 108 | let url = split(a:lines[index], '\t')[1] 109 | call s:show_match(url) 110 | return 1 111 | endif 112 | endfunction 113 | 114 | function! s:show_match(url) " {{{1 115 | let python_docs = xolox#misc#option#get('pyref_python') 116 | let django_docs = xolox#misc#option#get('pyref_django') 117 | let url = a:url 118 | if url =~ '^http://docs\.python\.org/' && isdirectory(python_docs) 119 | let url = substitute(url, '^http://docs\.python\.org', 'file://' . python_docs, '') 120 | elseif url =~ '^http://docs\.djangoproject\.com/en/1\.1/' && isdirectory(django_docs) 121 | let url = substitute(url, '/#', '.html#', '') 122 | let url = substitute(url, '^http://docs\.djangoproject\.com/en/1\.1', 'file://' . django_docs, '') 123 | endif 124 | call xolox#misc#open#url(url) 125 | endfunction 126 | 127 | function! s:find_index() " {{{1 128 | let abspath = fnamemodify(g:pyref_index, ':p') 129 | if !filereadable(abspath) 130 | let msg = "pyref.vim %s: The index file doesn't exist or isn't readable! (%s)" 131 | call xolox#misc#msg#warn(msg, g:xolox#pyref#version, index) 132 | return 133 | endif 134 | return abspath 135 | endfunction 136 | 137 | function! s:read_index() " {{{1 138 | let indexfile = s:find_index() 139 | try 140 | return readfile(indexfile) 141 | catch 142 | call xolox#misc#msg#warn("pyref.vim %s: Failed to read index file! (%s)", g:xolox#pyref#version, indexfile) 143 | return [] 144 | endtry 145 | endfunction 146 | 147 | " vim: ts=2 sw=2 et nowrap 148 | -------------------------------------------------------------------------------- /doc/pyref.txt: -------------------------------------------------------------------------------- 1 | *pyref.txt* Context-sensitive documentation for Python source code in Vim 2 | 3 | =============================================================================== 4 | Contents ~ 5 | 6 | 1. Introduction |pyref-introduction| 7 | 2. Install & usage |pyref-install-usage| 8 | 1. The |g:pyref_mapping| option 9 | 2. The |g:pyref_python| option 10 | 3. The |g:pyref_django| option 11 | 4. The |g:pyref_index| option 12 | 5. General note about options |pyref-general-note-about-options| 13 | 3. Contact |pyref-contact| 14 | 4. License |pyref-license| 15 | 5. References |pyref-references| 16 | 17 | =============================================================================== 18 | *pyref-introduction* 19 | Introduction ~ 20 | 21 | The 'pyref.vim' script is a plug-in for the Vim text editor that helps you look 22 | up the documentation for keywords and identifiers from the following sources 23 | using your web browser: 24 | 25 | - Python language reference [1] 26 | - Python library reference [2] 27 | - Django documentation [3] 28 | 29 | The ':PyRef' command looks up the identifier given as an argument while the 30 | '' mapping (only available in Python buffers) looks up the item under the 31 | text cursor. The lookup works by scanning through a special index file which is 32 | included in the ZIP archive below, but you can also create/update the index 33 | yourself using the Python script spider.py [4]. 34 | 35 | =============================================================================== 36 | *pyref-install-usage* 37 | Install & usage ~ 38 | 39 | _Please note that the vim-pyref plug-in requires my vim-misc plug-in which is 40 | separately distributed._ 41 | 42 | Unzip the most recent ZIP archives of the vim-pyref [5] and vim-misc [6] plug- 43 | ins inside your Vim profile directory (usually this is '~/.vim' on UNIX and 44 | '%USERPROFILE%\vimfiles' on Windows), restart Vim and execute the command 45 | ':helptags ~/.vim/doc' (use ':helptags ~\vimfiles\doc' instead on Windows). 46 | 47 | If you prefer you can also use Pathogen [7], Vundle [8] or a similar tool to 48 | install & update the vim-pyref [9] and vim-misc [10] plug-ins using a local 49 | clone of the git repository. 50 | 51 | Now try it out: Open a Python script and press the '' key on something 52 | interesting. If it doesn't work or you want to change how it works, see the 53 | options documented below. 54 | 55 | ------------------------------------------------------------------------------- 56 | The *g:pyref_mapping* option 57 | 58 | If you press '' and nothing happens you're probably using a terminal that 59 | doesn't pass '' through to Vim. In this case you can change the key mapping 60 | by setting the global variable |g:pyref_mapping| according to the syntax 61 | expected by Vim's ':imap' and ':nmap' commands: 62 | > 63 | :let g:pyref_mapping = 'K' 64 | < 65 | Note that setting |g:pyref_mapping| won't change the key mapping in existing 66 | buffers. 67 | 68 | ------------------------------------------------------------------------------- 69 | The *g:pyref_python* option 70 | 71 | This option is useful when you don't always have a reliable internet connection 72 | available while coding. Most Linux distributions have an installable package 73 | containing the Python documentation, for example on Ubuntu [11] and Debian [12] 74 | you can execute the following command to install the documentation: 75 | > 76 | $ sudo apt-get install python2.6-doc 77 | < 78 | The above package puts the documentation in '/usr/share/doc/python2.6/html/' 79 | which happens to be the default path checked by the 'pyref.vim' script. If 80 | you've installed the documentation in a different location you can change the 81 | global variable |g:pyref_python|, e.g.: 82 | > 83 | :let g:pyref_python = $HOME . '/docs/python' 84 | < 85 | ------------------------------------------------------------------------------- 86 | The *g:pyref_django* option 87 | 88 | This option works like |g:pyref_python| but allows you to configure the path to 89 | your local Django documentation. On Ubuntu [13] and Debian [14] you can execute 90 | the following command to install the Django documentation: 91 | > 92 | $ sudo apt-get install python-django-doc 93 | < 94 | In this case you shouldn't have to change anything because 'pyref.vim' is 95 | already configured to be compatible with the 'python-django-doc' package. 96 | 97 | ------------------------------------------------------------------------------- 98 | The *g:pyref_index* option 99 | 100 | If you don't like the default location of the index file you can change it by 101 | setting the global variable |g:pyref_index|. A leading '~' in the 102 | |g:pyref_index| variable is expanded to your current home directory ('$HOME' on 103 | UNIX, '%USERPROFILE%' on Windows). Be aware that when you change the 104 | |g:pyref_index| option automatic updates using the |getscript| plug-in won't 105 | update the index file anymore! 106 | 107 | ------------------------------------------------------------------------------- 108 | *pyref-general-note-about-options* 109 | General note about options ~ 110 | 111 | You can change the above options permanently by putting the relevant ':let' 112 | statements in your |vimrc| script. 113 | 114 | =============================================================================== 115 | *pyref-contact* 116 | Contact ~ 117 | 118 | If you have questions, bug reports, suggestions, etc. the author can be 119 | contacted at peter@peterodding.com. The latest version is available at 120 | http://peterodding.com/code/vim/pyref/ and http://github.com/xolox/vim-pyref. 121 | If you like the script please vote for it on Vim Online [15]. 122 | 123 | =============================================================================== 124 | *pyref-license* 125 | License ~ 126 | 127 | This software is licensed under the MIT license [16]. Š 2013 Peter Odding 128 | . 129 | 130 | =============================================================================== 131 | *pyref-references* 132 | References ~ 133 | 134 | [1] http://docs.python.org/reference/ 135 | [2] http://docs.python.org/library/ 136 | [3] http://docs.djangoproject.com/ 137 | [4] http://github.com/xolox/vim-pyref/blob/master/spider.py 138 | [5] http://peterodding.com/code/vim/downloads/pyref.zip 139 | [6] http://peterodding.com/code/vim/downloads/misc.zip 140 | [7] http://www.vim.org/scripts/script.php?script_id=2332 141 | [8] https://github.com/gmarik/vundle 142 | [9] http://github.com/xolox/vim-pyref 143 | [10] http://github.com/xolox/vim-misc 144 | [11] http://packages.ubuntu.com/python2.6-doc 145 | [12] http://packages.debian.org/python2.6-doc 146 | [13] http://packages.ubuntu.com/python-django-doc 147 | [14] http://packages.debian.org/python-django-doc 148 | [15] http://www.vim.org/scripts/script.php?script_id=3104 149 | [16] http://en.wikipedia.org/wiki/MIT_License 150 | 151 | vim: ft=help 152 | -------------------------------------------------------------------------------- /misc/pyref/spider.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright 2010 Peter Odding 4 | # This program is licensed under the MIT license. 5 | 6 | # This Python script indexes a local/remote tree of Python HTML documentation 7 | # and creates/updates an index file that maps identifiers to their associated 8 | # URL in the documentation. Each line starts with a keyword or an identifier 9 | # followed by a tab and ends with the associated URL. The index file is used by 10 | # the pyref.vim plug-in for Vim to provide context sensitive documentation. 11 | # For more information visit http://peterodding.com/code/vim/pyref/ 12 | 13 | import os 14 | import re 15 | import sys 16 | import time 17 | import urllib 18 | 19 | DEBUG = False 20 | 21 | indexfile = os.path.expanduser('~/.vim/misc/pyref_index') 22 | scriptname = os.path.split(sys.argv[0])[1] 23 | 24 | def message(text, *args): 25 | text = '%s: ' + text + '\n' 26 | text %= (scriptname,) + args 27 | sys.stderr.write(text) 28 | 29 | def verbose(text, *args): 30 | if DEBUG: 31 | message(text, *args) 32 | 33 | def error(text, *args): 34 | message(text, *args) 35 | sys.exit(1) 36 | 37 | # Make sure the Beautiful Soup HTML parser is available. 38 | try: 39 | from BeautifulSoup import BeautifulSoup 40 | except ImportError: 41 | error("""You'll need to install the Beautiful Soup HTML parser. If you're running 42 | Debian/Ubuntu try the following: sudo apt-get install python-beautifulsoup""") 43 | 44 | # Make sure the user provided a location to spider. 45 | if len(sys.argv) < 2: 46 | error("Please provide the URL to spider as a command line argument.") 47 | 48 | # Validate/munge the location so it points to an index.html page. 49 | root = sys.argv[1].replace('file://', '') 50 | if not root.startswith('http://'): 51 | root = os.path.realpath(root) 52 | if os.path.isdir(root): 53 | page = os.path.join(root, 'index.html') 54 | if os.path.isfile(root): 55 | root = page 56 | else: 57 | error("Failed to determine index page in %r!", root) 58 | elif not os.path.isfile(root): 59 | error("The location %r doesn't seem to exist!", root) 60 | root = 'file://' + root 61 | first_page = root 62 | root = os.path.split(root)[0] 63 | 64 | # If the index file already exists, read it so we can merge the results. 65 | anchors = {} 66 | if os.path.isfile(indexfile): 67 | message("Reading existing entries from %s", indexfile) 68 | handle = open(indexfile) 69 | nfiltered = 0 70 | for line in handle: 71 | anchor, target = line.strip().split('\t') 72 | if target.startswith(root): 73 | nfiltered += 1 74 | else: 75 | anchors[anchor] = target 76 | handle.close() 77 | message("Read %i and filtered %i entries", len(anchors), nfiltered) 78 | 79 | # Start from the given location and collect anchors from all related pages. 80 | queued_pages = [first_page] 81 | visited_pages = {} 82 | while queued_pages: 83 | location = queued_pages.pop() 84 | # Fetch the selected page. 85 | try: 86 | verbose("Fetching %r", location) 87 | handle = urllib.urlopen(location) 88 | contents = handle.read() 89 | handle.close() 90 | if not location.startswith('file://'): 91 | # Rate limit fetching of remote pages. 92 | time.sleep(1) 93 | except: 94 | verbose("Failed to fetch %r!", location) 95 | continue 96 | # Mark the current page as visited so we don't fetch it again. 97 | visited_pages[location] = True 98 | # Parse the page's HTML to extract links and anchors. 99 | verbose("Parsing %r", location) 100 | tagsoup = BeautifulSoup(contents) 101 | npages = 0 102 | for tag in tagsoup.findAll('a', href=True): 103 | target = tag['href'] 104 | # Strip anchors and ignore anchor-only links. 105 | target = re.sub('#.*$', '', target) 106 | if target: 107 | # Convert the link target to an absolute, canonical URL? 108 | if not re.match(r'^\w+://', target): 109 | target = os.path.join(os.path.split(location)[0], target) 110 | scheme, target = target.split('://') 111 | target = scheme + '://' + os.path.normpath(target) 112 | # Ignore links pointing outside the root URL and don't process any page more than once. 113 | if target.startswith(root) and target not in visited_pages and target not in queued_pages: 114 | queued_pages.append(target) 115 | npages += 1 116 | nidents = 0 117 | for tag in tagsoup.findAll(True, id=True): 118 | anchor = tag['id'] 119 | if anchor not in anchors: 120 | anchors[anchor] = '%s#%s' % (location, anchor) 121 | nidents += 1 122 | else: 123 | verbose("Ignoring identifier %r duplicate target %r!", anchor, location) 124 | message("Extracted %i related pages, %i anchors from %r..", npages, nidents, location) 125 | 126 | message("Scanned %i pages, extracted %i anchors", len(visited_pages), len(anchors)) 127 | 128 | # Write the tab delimited list of (keyword, URL) pairs to the index file. 129 | message("Writing index file %r", indexfile) 130 | handle = open(indexfile, 'w') 131 | bytes_written = 0 132 | for anchor in sorted(anchors.keys()): 133 | line = '%s\t%s\n' % (anchor, anchors[anchor]) 134 | handle.write(line) 135 | bytes_written += len(line) 136 | handle.close() 137 | message("Done, wrote %i KB to %r", bytes_written / 1024, indexfile) 138 | 139 | # vim: ts=2 sw=2 et 140 | -------------------------------------------------------------------------------- /plugin/pyref.vim: -------------------------------------------------------------------------------- 1 | " Vim plug-in 2 | " Author: Peter Odding 3 | " Last Change: August 19, 2013 4 | " URL: http://peterodding.com/code/vim/pyref/ 5 | 6 | " Support for automatic update using the GLVS plug-in. 7 | " GetLatestVimScripts: 3104 1 :AutoInstall: pyref.zip 8 | 9 | " Don't source the plug-in when it's already been loaded or &compatible is set. 10 | if &cp || exists('g:loaded_pyref') 11 | finish 12 | else 13 | let g:loaded_pyref = 1 14 | endif 15 | 16 | " Make sure vim-misc is installed. 17 | try 18 | " The point of this code is to do something completely innocent while making 19 | " sure the vim-misc plug-in is installed. We specifically don't use Vim's 20 | " exists() function because it doesn't load auto-load scripts that haven't 21 | " already been loaded yet (last tested on Vim 7.3). 22 | call type(g:xolox#misc#version) 23 | catch 24 | echomsg "Warning: The vim-pyref plug-in requires the vim-misc plug-in which seems not to be installed! For more information please review the installation instructions in the readme (also available on the homepage and on GitHub). The vim-pyref plug-in will now be disabled." 25 | let g:loaded_pyref = 1 26 | finish 27 | endtry 28 | 29 | " Make sure the default paths below are compatible with Pathogen. 30 | let s:plugindir = expand(':p:h') . '/../misc/pyref' 31 | 32 | " Default location of index file, should be fine in most cases. 33 | if !exists('g:pyref_index') 34 | let g:pyref_index = s:plugindir . '/index' 35 | endif 36 | 37 | " Local Python documentation as installed by e.g. sudo apt-get install python2.6-doc 38 | if !exists('g:pyref_python') 39 | let g:pyref_python = '/usr/share/doc/python2.6/html' 40 | endif 41 | 42 | " Local Django documentation as installed by e.g. sudo apt-get install python-django-doc 43 | if !exists('g:pyref_django') 44 | let g:pyref_django = '/usr/share/doc/python-django-doc/html' 45 | endif 46 | 47 | " Automatic command to enable key mapping in Python buffers. 48 | augroup PluginPyRef 49 | autocmd! FileType python call xolox#pyref#enable() 50 | augroup END 51 | 52 | " User command that looks up given argument and supports completion. 53 | command! -nargs=? -complete=customlist,xolox#pyref#complete PyRef call xolox#pyref#lookup() 54 | 55 | " vim: ts=2 sw=2 et 56 | --------------------------------------------------------------------------------