Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

move python documentation script into separate file

  • Loading branch information...
commit 4e9771f6978316bc26a2bbf3898d1f71effc3fda 1 parent c87ce67
Will Pragnell authored
Showing with 76 additions and 64 deletions.
  1. +18 −64 ftplugin/reprocessed.vim
  2. +58 −0 python/processing_doc.py
82 ftplugin/reprocessed.vim
View
@@ -33,69 +33,23 @@ if has("python")
endif
function! ProcessingDoc()
-python << ENDPY
-import vim
-import re
-import webbrowser
-from os import path
-
-def launchDocFile(filename):
- docfile = path.join(basepath, filename)
- if path.exists(docfile) and path.isfile(docfile):
- webbrowser.open("file://" + docfile)
- return True
- return False
-
-def launchDocWeb(filename):
- docfile = "http://processing.org/reference/"
- webbrowser.open(docfile+filename)
- return True
-
-def wordStart(line, column):
- start = column
- for i in reversed(range(column)):
- if line[i].isalnum():
- start = i
- else:
- break
- return start
-
-if vim.eval("g:processing_doc_style") == "local":
- basepath = path.abspath(vim.eval("g:processing_doc_path"))
- launchDoc = launchDocFile
-else:
- launchDoc = launchDocWeb
-
-(row, col) = vim.current.window.cursor
-line = vim.current.line
-
-col = wordStart(line, col)
-if re.match(r"\w+\s*\(", line[col:]):
- if col < 4:
- isFunction = True
- else:
- col -= 4
- if re.match(r"new\s*\w+\s*\(", line[col:]):
- isFunction = False
- else:
- isFunction = True
-else:
- isFunction = False
-
-word = vim.eval('expand("<cword>")')
-
-if word:
- if isFunction:
- success = launchDoc(word + "_.html") or launchDoc(word + ".html")
- else:
- success = launchDoc(word + ".html") or launchDoc(word + "_.html")
- if not success:
- print "Identifier", '"' + word + '"', "not found in local documentation."
-
-ENDPY
+ if !exists("s:processing_doc_py_path")
+ let paths = substitute(escape(&runtimepath, ' '), '\(,\|$\)', '/**\1', 'g')
+ let s:processing_doc_py_path = findfile('processing_doc.py', paths)
+ if !filereadable(s:processing_doc_py_path)
+ echohl WarningMsg
+ echom "Could not find processing_doc.py in your vim runtime path"
+ echohl None
+ unlet s:processing_doc_py_path
+ return
+ endif
+ endif
+ execute "pyfile ".s:processing_doc_py_path
endfunction
-
-nnoremap <silent> <buffer> K :call ProcessingDoc()<CR>
-
-endif "has("python")
+ nnoremap <silent> <buffer> K :call ProcessingDoc()<cr>
+else
+ echohl WarningMsg
+ echom "reprocessed.vim processing documentation lookup requires vim to be compiled with python support"
+ echohl None
+endif
58 python/processing_doc.py
View
@@ -0,0 +1,58 @@
+import vim
+import re
+import webbrowser
+from os import path
+
+def launchDocFile(filename):
+ docfile = path.join(basepath, filename)
+ if path.exists(docfile) and path.isfile(docfile):
+ webbrowser.open("file://" + docfile)
+ return True
+ return False
+
+def launchDocWeb(filename):
+ docfile = "http://processing.org/reference/"
+ webbrowser.open(docfile+filename)
+ return True
+
+def wordStart(line, column):
+ start = column
+ for i in reversed(range(column)):
+ if line[i].isalnum():
+ start = i
+ else:
+ break
+ return start
+
+if vim.eval("g:processing_doc_style") == "local":
+ basepath = path.abspath(vim.eval("g:processing_doc_path"))
+ launchDoc = launchDocFile
+else:
+ launchDoc = launchDocWeb
+
+(row, col) = vim.current.window.cursor
+line = vim.current.line
+
+col = wordStart(line, col)
+if re.match(r"\w+\s*\(", line[col:]):
+ if col < 4:
+ isFunction = True
+ else:
+ col -= 4
+ if re.match(r"new\s*\w+\s*\(", line[col:]):
+ isFunction = False
+ else:
+ isFunction = True
+else:
+ isFunction = False
+
+word = vim.eval('expand("<cword>")')
+
+if word:
+ if isFunction:
+ success = launchDoc(word + "_.html") or launchDoc(word + ".html")
+ else:
+ success = launchDoc(word + ".html") or launchDoc(word + "_.html")
+ if not success:
+ print "Identifier", '"' + word + '"', "not found in local documentation."
+
Please sign in to comment.
Something went wrong with that request. Please try again.