vimrc cleanup, new versions
git-svn-id: http://photonzero.com/dotfiles/trunk@31 23f722f6-122a-0410-8cef-c75bd312dd78
This commit is contained in:
parent
143fd36427
commit
6becfb4ec2
7 changed files with 725 additions and 501 deletions
|
|
@ -1,17 +1,22 @@
|
|||
"pythoncomplete.vim - Omni Completion for python
|
||||
" Maintainer: Aaron Griffin <aaronmgriffin@gmail.com>
|
||||
" Version: 0.8
|
||||
" Last Updated: 8 Oct 2007
|
||||
" Version: 0.9
|
||||
" Last Updated: 18 Jun 2009
|
||||
"
|
||||
" Changes
|
||||
" TODO:
|
||||
" User defined docstrings aren't handled right...
|
||||
" 'info' item output can use some formatting work
|
||||
" Add an "unsafe eval" mode, to allow for return type evaluation
|
||||
" Complete basic syntax along with import statements
|
||||
" i.e. "import url<c-x,c-o>"
|
||||
" Continue parsing on invalid line??
|
||||
"
|
||||
" v 0.9
|
||||
" * Fixed docstring parsing for classes and functions
|
||||
" * Fixed parsing of *args and **kwargs type arguments
|
||||
" * Better function param parsing to handle things like tuples and
|
||||
" lambda defaults args
|
||||
"
|
||||
" v 0.8
|
||||
" * Fixed an issue where the FIRST assignment was always used instead of
|
||||
" using a subsequent assignment for a variable
|
||||
|
|
@ -69,7 +74,7 @@ function! pythoncomplete#Complete(findstart, base)
|
|||
while idx > 0
|
||||
let idx -= 1
|
||||
let c = line[idx]
|
||||
if c =~ '\w' || c =~ '\.' || c == '('
|
||||
if c =~ '\w' || c =~ '\.'
|
||||
let cword = c . cword
|
||||
continue
|
||||
elseif strlen(cword) > 0 || idx == 0
|
||||
|
|
@ -212,7 +217,7 @@ class Completer(object):
|
|||
if len(stmt) > 0 and stmt[-1] == '(':
|
||||
result = eval(_sanitize(stmt[:-1]), self.compldict)
|
||||
doc = result.__doc__
|
||||
if doc == None: doc = ''
|
||||
if doc is None: doc = ''
|
||||
args = self.get_arguments(result)
|
||||
return [{'word':self._cleanstr(args),'info':self._cleanstr(doc)}]
|
||||
elif ridx == -1:
|
||||
|
|
@ -229,18 +234,18 @@ class Completer(object):
|
|||
|
||||
try: maindoc = result.__doc__
|
||||
except: maindoc = ' '
|
||||
if maindoc == None: maindoc = ' '
|
||||
if maindoc is None: maindoc = ' '
|
||||
for m in all:
|
||||
if m == "_PyCmplNoType": continue #this is internal
|
||||
try:
|
||||
dbg('possible completion: %s' % m)
|
||||
if m.find(match) == 0:
|
||||
if result == None: inst = all[m]
|
||||
if result is None: inst = all[m]
|
||||
else: inst = getattr(result,m)
|
||||
try: doc = inst.__doc__
|
||||
except: doc = maindoc
|
||||
typestr = str(inst)
|
||||
if doc == None or doc == '': doc = maindoc
|
||||
if doc is None or doc == '': doc = maindoc
|
||||
|
||||
wrd = m[len(match):]
|
||||
c = {'word':wrd, 'abbr':m, 'info':self._cleanstr(doc)}
|
||||
|
|
@ -266,9 +271,9 @@ class Completer(object):
|
|||
return []
|
||||
|
||||
class Scope(object):
|
||||
def __init__(self,name,indent):
|
||||
def __init__(self,name,indent,docstr=''):
|
||||
self.subscopes = []
|
||||
self.docstr = ''
|
||||
self.docstr = docstr
|
||||
self.locals = []
|
||||
self.parent = None
|
||||
self.name = name
|
||||
|
|
@ -287,6 +292,7 @@ class Scope(object):
|
|||
while d.find(' ') > -1: d = d.replace(' ',' ')
|
||||
while d[0] in '"\'\t ': d = d[1:]
|
||||
while d[-1] in '"\'\t ': d = d[:-1]
|
||||
dbg("Scope(%s)::docstr = %s" % (self,d))
|
||||
self.docstr = d
|
||||
|
||||
def local(self,loc):
|
||||
|
|
@ -295,7 +301,7 @@ class Scope(object):
|
|||
|
||||
def copy_decl(self,indent=0):
|
||||
""" Copy a scope's declaration only, at the specified indent level - not local variables """
|
||||
return Scope(self.name,indent)
|
||||
return Scope(self.name,indent,self.docstr)
|
||||
|
||||
def _checkexisting(self,test):
|
||||
"Convienance function... keep out duplicates"
|
||||
|
|
@ -306,9 +312,8 @@ class Scope(object):
|
|||
self.locals.remove(l)
|
||||
|
||||
def get_code(self):
|
||||
# we need to start with this, to fix up broken completions
|
||||
# hopefully this name is unique enough...
|
||||
str = '"""'+self.docstr+'"""\n'
|
||||
str = ""
|
||||
if len(self.docstr) > 0: str += '"""'+self.docstr+'"""\n'
|
||||
for l in self.locals:
|
||||
if l.startswith('import'): str += l+'\n'
|
||||
str += 'class _PyCmplNoType:\n def __getattr__(self,name):\n return None\n'
|
||||
|
|
@ -335,11 +340,11 @@ class Scope(object):
|
|||
return ' '*(self.indent+1)
|
||||
|
||||
class Class(Scope):
|
||||
def __init__(self, name, supers, indent):
|
||||
Scope.__init__(self,name,indent)
|
||||
def __init__(self, name, supers, indent, docstr=''):
|
||||
Scope.__init__(self,name,indent, docstr)
|
||||
self.supers = supers
|
||||
def copy_decl(self,indent=0):
|
||||
c = Class(self.name,self.supers,indent)
|
||||
c = Class(self.name,self.supers,indent, self.docstr)
|
||||
for s in self.subscopes:
|
||||
c.add(s.copy_decl(indent+1))
|
||||
return c
|
||||
|
|
@ -356,11 +361,11 @@ class Class(Scope):
|
|||
|
||||
|
||||
class Function(Scope):
|
||||
def __init__(self, name, params, indent):
|
||||
Scope.__init__(self,name,indent)
|
||||
def __init__(self, name, params, indent, docstr=''):
|
||||
Scope.__init__(self,name,indent, docstr)
|
||||
self.params = params
|
||||
def copy_decl(self,indent=0):
|
||||
return Function(self.name,self.params,indent)
|
||||
return Function(self.name,self.params,indent, self.docstr)
|
||||
def get_code(self):
|
||||
str = "%sdef %s(%s):\n" % \
|
||||
(self.currentindent(),self.name,','.join(self.params))
|
||||
|
|
@ -376,7 +381,7 @@ class PyParser:
|
|||
def _parsedotname(self,pre=None):
|
||||
#returns (dottedname, nexttoken)
|
||||
name = []
|
||||
if pre == None:
|
||||
if pre is None:
|
||||
tokentype, token, indent = self.next()
|
||||
if tokentype != NAME and token != '*':
|
||||
return ('', token)
|
||||
|
|
@ -410,17 +415,20 @@ class PyParser:
|
|||
while True:
|
||||
tokentype, token, indent = self.next()
|
||||
if token in (')', ',') and level == 1:
|
||||
names.append(name)
|
||||
if '=' not in name: name = name.replace(' ', '')
|
||||
names.append(name.strip())
|
||||
name = ''
|
||||
if token == '(':
|
||||
level += 1
|
||||
name += "("
|
||||
elif token == ')':
|
||||
level -= 1
|
||||
if level == 0: break
|
||||
else: name += ")"
|
||||
elif token == ',' and level == 1:
|
||||
pass
|
||||
else:
|
||||
name += str(token)
|
||||
name += "%s " % str(token)
|
||||
return names
|
||||
|
||||
def _parsefunction(self,indent):
|
||||
|
|
@ -500,17 +508,26 @@ class PyParser:
|
|||
#Handle 'self' params
|
||||
if scp.parent != None and type(scp.parent) == Class:
|
||||
slice = 1
|
||||
p = scp.params[0]
|
||||
i = p.find('=')
|
||||
if i != -1: p = p[:i]
|
||||
newscope.local('%s = %s' % (scp.params[0],scp.parent.name))
|
||||
for p in scp.params[slice:]:
|
||||
i = p.find('=')
|
||||
if len(p) == 0: continue
|
||||
pvar = ''
|
||||
ptype = ''
|
||||
if i == -1:
|
||||
newscope.local('%s = _PyCmplNoType()' % p)
|
||||
pvar = p
|
||||
ptype = '_PyCmplNoType()'
|
||||
else:
|
||||
newscope.local('%s = %s' % (p[:i],_sanitize(p[i+1])))
|
||||
pvar = p[:i]
|
||||
ptype = _sanitize(p[i+1:])
|
||||
if pvar.startswith('**'):
|
||||
pvar = pvar[2:]
|
||||
ptype = '{}'
|
||||
elif pvar.startswith('*'):
|
||||
pvar = pvar[1:]
|
||||
ptype = '[]'
|
||||
|
||||
newscope.local('%s = %s' % (pvar,ptype))
|
||||
|
||||
for s in scp.subscopes:
|
||||
ns = s.copy_decl(0)
|
||||
|
|
@ -538,17 +555,19 @@ class PyParser:
|
|||
self.scope = self.scope.pop(indent)
|
||||
elif token == 'def':
|
||||
func = self._parsefunction(indent)
|
||||
if func == None:
|
||||
if func is None:
|
||||
print "function: syntax error..."
|
||||
continue
|
||||
dbg("new scope: function")
|
||||
freshscope = True
|
||||
self.scope = self.scope.add(func)
|
||||
elif token == 'class':
|
||||
cls = self._parseclass(indent)
|
||||
if cls == None:
|
||||
if cls is None:
|
||||
print "class: syntax error..."
|
||||
continue
|
||||
freshscope = True
|
||||
dbg("new scope: class")
|
||||
self.scope = self.scope.add(cls)
|
||||
|
||||
elif token == 'import':
|
||||
|
|
|
|||
|
|
@ -8,3 +8,11 @@ augroup END
|
|||
augroup mako
|
||||
au! BufRead,BufNewFile *.mak setfiletype mako
|
||||
augroup END
|
||||
augroup python
|
||||
autocmd FileType python set omnifunc=pythoncomplete#Complete
|
||||
autocmd FileType python call SuperTabSetCompletionType("<C-X><C-O>")
|
||||
autocmd FileType python set completeopt-=preview
|
||||
autocmd FileType python set ts=4
|
||||
autocmd FileType python set softtabstop=4
|
||||
autocmd FileType python set shiftwidth=4
|
||||
augroup END
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
" Author:
|
||||
" Original: Gergely Kontra <kgergely@mcl.hu>
|
||||
" Current: Eric Van Dewoestine <ervandew@yahoo.com> (as of version 0.4)
|
||||
" Current: Eric Van Dewoestine <ervandew@gmail.com> (as of version 0.4)
|
||||
" Please direct all correspondence to Eric.
|
||||
" Version: 0.45
|
||||
" Version: 0.51
|
||||
"
|
||||
" Description: {{{
|
||||
" Use your tab key to do all your completion in insert mode!
|
||||
" You can cycle forward and backward with the <Tab> and <S-Tab> keys
|
||||
" (<S-Tab> will not work in the console version)
|
||||
" Note: you must press <Tab> once to be able to cycle back
|
||||
"
|
||||
" http://www.vim.org/scripts/script.php?script_id=1643
|
||||
|
|
@ -16,7 +15,7 @@
|
|||
" License: {{{
|
||||
" Software License Agreement (BSD License)
|
||||
"
|
||||
" Copyright (c) 2002 - 2007
|
||||
" Copyright (c) 2002 - 2009
|
||||
" All rights reserved.
|
||||
"
|
||||
" Redistribution and use of this software in source and binary forms, with
|
||||
|
|
@ -49,6 +48,15 @@
|
|||
" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
" }}}
|
||||
"
|
||||
" Testing Info: {{{
|
||||
" Running vim + supertab with the absolute bar minimum settings:
|
||||
" $ vim -u NONE -U NONE -c "set nocp | runtime plugin/supertab.vim"
|
||||
" }}}
|
||||
|
||||
if v:version < 700
|
||||
finish
|
||||
endif
|
||||
|
||||
if exists('complType') " Integration with other completion functions.
|
||||
finish
|
||||
|
|
@ -59,9 +67,38 @@ endif
|
|||
" Used to set the default completion type.
|
||||
" There is no need to escape this value as that will be done for you when
|
||||
" the type is set.
|
||||
" Ex. let g:SuperTabDefaultCompletionType = "<C-X><C-U>"
|
||||
" Ex. let g:SuperTabDefaultCompletionType = "<c-x><c-u>"
|
||||
"
|
||||
" Note that a special value of 'context' is supported which will result in
|
||||
" super tab attempting to use the text preceding the cursor to decide which
|
||||
" type of completion to attempt. Currently super tab can recognize method
|
||||
" calls or attribute references via '.', '::' or '->', and file path
|
||||
" references containing '/'.
|
||||
" Ex. let g:SuperTabDefaultCompletionType = 'context'
|
||||
" /usr/l<tab> # will use filename completion
|
||||
" myvar.t # will use user completion if completefunc set, or omni
|
||||
" # completion if omnifunc set.
|
||||
" myvar-> # same as above
|
||||
"
|
||||
" When using context completion, super tab will fall back to a secondary
|
||||
" default completion type set by g:SuperTabContextDefaultCompletionType.
|
||||
if !exists("g:SuperTabDefaultCompletionType")
|
||||
let g:SuperTabDefaultCompletionType = "<C-P>"
|
||||
let g:SuperTabDefaultCompletionType = "<c-p>"
|
||||
endif
|
||||
|
||||
" Sets the default completion type used when g:SuperTabDefaultCompletionType
|
||||
" is set to 'context' and the text preceding the cursor does not match any
|
||||
" patterns mapped to other specific completion types.
|
||||
if !exists("g:SuperTabContextDefaultCompletionType")
|
||||
let g:SuperTabContextDefaultCompletionType = "<c-p>"
|
||||
endif
|
||||
|
||||
" When 'context' completion is enabled, this setting can be used to fallback
|
||||
" to g:SuperTabContextDefaultCompletionType as the default for files whose
|
||||
" file type occurs in this configured list. This allows you to provide an
|
||||
" exclusion for which 'context' completion is not activated.
|
||||
if !exists("g:SuperTabContextFileTypeExclusions")
|
||||
let g:SuperTabContextFileTypeExclusions = []
|
||||
endif
|
||||
|
||||
" Used to set a list of variable, completion type pairs used to determine
|
||||
|
|
@ -69,10 +106,13 @@ endif
|
|||
" variable is non-zero and non-empty then the associated completion type
|
||||
" will be used.
|
||||
" Ex. To use omni or user completion when available, but fall back to the
|
||||
" global default otherwise.
|
||||
" let g:SuperTabDefaultCompletionTypeDiscovery = "&omnifunc:<C-X><C-O>,&completefunc:<C-X><C-U>"
|
||||
" global default otherwise:
|
||||
" let g:SuperTabDefaultCompletionTypeDiscovery = [
|
||||
" \ "&completefunc:<c-x><c-u>",
|
||||
" \ "&omnifunc:<c-x><c-o>",
|
||||
" \ ]
|
||||
if !exists("g:SuperTabDefaultCompletionTypeDiscovery")
|
||||
let g:SuperTabDefaultCompletionTypeDiscovery = ""
|
||||
let g:SuperTabDefaultCompletionTypeDiscovery = []
|
||||
endif
|
||||
|
||||
" Determines if, and for how long, the current completion type is retained.
|
||||
|
|
@ -122,6 +162,15 @@ endif
|
|||
let g:SuperTabMappingBackward = '<s-tab>'
|
||||
endif
|
||||
|
||||
" Sets the key mapping used to insert a literal tab where supertab would
|
||||
" otherwise attempt to kick off insert completion.
|
||||
" The default is '<c-tab>' (ctrl-tab) which unfortunately might not work at
|
||||
" the console. So if you are using a console vim and want this
|
||||
" functionality, you'll have to change it to something that is supported.
|
||||
if !exists("g:SuperTabMappingTabLiteral")
|
||||
let g:SuperTabMappingTabLiteral = '<c-tab>'
|
||||
endif
|
||||
|
||||
" Sets whether or not to pre-highlight first match when completeopt has
|
||||
" the popup menu enabled and the 'longest' option as well.
|
||||
" When enabled, <tab> will kick off completion and pre-select the first
|
||||
|
|
@ -139,32 +188,26 @@ endif
|
|||
\ "Hit <CR> or CTRL-] on the completion type you wish to switch to.\n" .
|
||||
\ "Use :help ins-completion for more information.\n" .
|
||||
\ "\n" .
|
||||
\ "|<C-N>| - Keywords in 'complete' searching down.\n" .
|
||||
\ "|<C-P>| - Keywords in 'complete' searching up (SuperTab default).\n" .
|
||||
\ "|<C-X><C-L>| - Whole lines.\n" .
|
||||
\ "|<C-X><C-N>| - Keywords in current file.\n" .
|
||||
\ "|<C-X><C-K>| - Keywords in 'dictionary'.\n" .
|
||||
\ "|<C-X><C-T>| - Keywords in 'thesaurus', thesaurus-style.\n" .
|
||||
\ "|<C-X><C-I>| - Keywords in the current and included files.\n" .
|
||||
\ "|<C-X><C-]>| - Tags.\n" .
|
||||
\ "|<C-X><C-F>| - File names.\n" .
|
||||
\ "|<C-X><C-D>| - Definitions or macros.\n" .
|
||||
\ "|<C-X><C-V>| - Vim command-line."
|
||||
if v:version >= 700
|
||||
let s:tabHelp = s:tabHelp . "\n" .
|
||||
\ "|<C-X><C-U>| - User defined completion.\n" .
|
||||
\ "|<C-X><C-O>| - Omni completion.\n" .
|
||||
\ "|<C-X>s| - Spelling suggestions."
|
||||
endif
|
||||
\ "|<c-n>| - Keywords in 'complete' searching down.\n" .
|
||||
\ "|<c-p>| - Keywords in 'complete' searching up (SuperTab default).\n" .
|
||||
\ "|<c-x><c-l>| - Whole lines.\n" .
|
||||
\ "|<c-x><c-n>| - Keywords in current file.\n" .
|
||||
\ "|<c-x><c-k>| - Keywords in 'dictionary'.\n" .
|
||||
\ "|<c-x><c-t>| - Keywords in 'thesaurus', thesaurus-style.\n" .
|
||||
\ "|<c-x><c-i>| - Keywords in the current and included files.\n" .
|
||||
\ "|<c-x><c-]>| - Tags.\n" .
|
||||
\ "|<c-x><c-f>| - File names.\n" .
|
||||
\ "|<c-x><c-d>| - Definitions or macros.\n" .
|
||||
\ "|<c-x><c-v>| - Vim command-line.\n" .
|
||||
\ "|<c-x><c-u>| - User defined completion.\n" .
|
||||
\ "|<c-x><c-o>| - Omni completion.\n" .
|
||||
\ "|<c-x>s| - Spelling suggestions."
|
||||
|
||||
" set the available completion types and modes.
|
||||
let s:types =
|
||||
\ "\<C-E>\<C-Y>\<C-L>\<C-N>\<C-K>\<C-T>\<C-I>\<C-]>\<C-F>\<C-D>\<C-V>\<C-N>\<C-P>"
|
||||
let s:modes = '/^E/^Y/^L/^N/^K/^T/^I/^]/^F/^D/^V/^P'
|
||||
if v:version >= 700
|
||||
let s:types = s:types . "\<C-U>\<C-O>\<C-N>\<C-P>s"
|
||||
let s:modes = s:modes . '/^U/^O/s'
|
||||
endif
|
||||
\ "\<c-e>\<c-y>\<c-l>\<c-n>\<c-k>\<c-t>\<c-i>\<c-]>" .
|
||||
\ "\<c-f>\<c-d>\<c-v>\<c-n>\<c-p>\<c-u>\<c-o>\<c-n>\<c-p>s"
|
||||
let s:modes = '/^E/^Y/^L/^N/^K/^T/^I/^]/^F/^D/^V/^P/^U/^O/s'
|
||||
let s:types = s:types . "np"
|
||||
let s:modes = s:modes . '/n/p'
|
||||
|
||||
|
|
@ -178,23 +221,29 @@ function! CtrlXPP()
|
|||
endif
|
||||
let complType = nr2char(getchar())
|
||||
if stridx(s:types, complType) != -1
|
||||
if stridx("\<C-E>\<C-Y>", complType) != -1 " no memory, just scroll...
|
||||
return "\<C-x>" . complType
|
||||
if stridx("\<c-e>\<c-y>", complType) != -1 " no memory, just scroll...
|
||||
return "\<c-x>" . complType
|
||||
elseif stridx('np', complType) != -1
|
||||
let complType = nr2char(char2nr(complType) - 96) " char2nr('n')-char2nr("\<C-n")
|
||||
let complType = nr2char(char2nr(complType) - 96)
|
||||
else
|
||||
let complType="\<C-x>" . complType
|
||||
let complType = "\<c-x>" . complType
|
||||
endif
|
||||
|
||||
if g:SuperTabRetainCompletionType
|
||||
let b:complType = complType
|
||||
endif
|
||||
|
||||
return complType
|
||||
else
|
||||
echohl "Unknown mode"
|
||||
" Hack to workaround appent bug when invoking command line completion via
|
||||
" <c-r>=
|
||||
if complType == "\<c-x>\<c-v>"
|
||||
return s:CommandLineCompletion()
|
||||
endif
|
||||
|
||||
return complType
|
||||
endif
|
||||
|
||||
echohl "Unknown mode"
|
||||
return complType
|
||||
endfunction " }}}
|
||||
|
||||
" SuperTabSetCompletionType(type) {{{
|
||||
|
|
@ -203,7 +252,7 @@ endfunction " }}}
|
|||
" default or switch to another mode without having to kick off a completion
|
||||
" of that type or use SuperTabHelp.
|
||||
" Example mapping to restore SuperTab default:
|
||||
" nmap <F6> :call SetSuperTabCompletionType("<C-P>")<cr>
|
||||
" nmap <F6> :call SetSuperTabCompletionType("<c-p>")<cr>
|
||||
function! SuperTabSetCompletionType(type)
|
||||
exec "let b:complType = \"" . escape(a:type, '<') . "\""
|
||||
endfunction " }}}
|
||||
|
|
@ -215,24 +264,22 @@ function! s:Init ()
|
|||
autocmd!
|
||||
autocmd BufEnter * call <SID>InitBuffer()
|
||||
augroup END
|
||||
" ensure InitBuffer gets called for the first buffer.
|
||||
call s:InitBuffer()
|
||||
|
||||
" ensure InitBuffer gets called for the first buffer, after the ftplugins
|
||||
" have been called.
|
||||
augroup supertab_init_first
|
||||
autocmd!
|
||||
autocmd FileType <buffer> call <SID>InitBuffer()
|
||||
augroup END
|
||||
|
||||
" Setup mechanism to restore orignial completion type upon leaving insert
|
||||
" mode if g:SuperTabRetainCompletionType == 2
|
||||
if g:SuperTabRetainCompletionType == 2
|
||||
" pre vim 7, must map <esc>
|
||||
if v:version < 700
|
||||
im <silent> <ESC> <ESC>:call s:SetDefaultCompletionType()<cr>
|
||||
|
||||
" since vim 7, we can use InsertLeave autocmd.
|
||||
else
|
||||
augroup supertab_retain
|
||||
autocmd!
|
||||
autocmd InsertLeave * call s:SetDefaultCompletionType()
|
||||
augroup END
|
||||
endif
|
||||
endif
|
||||
endfunction " }}}
|
||||
|
||||
" s:InitBuffer {{{
|
||||
|
|
@ -242,24 +289,27 @@ function! s:InitBuffer ()
|
|||
return
|
||||
endif
|
||||
|
||||
" init hack for <c-x><c-v> workaround.
|
||||
let b:complCommandLine = 0
|
||||
|
||||
if !exists("b:SuperTabDefaultCompletionType")
|
||||
" loop through discovery list to find the default
|
||||
if g:SuperTabDefaultCompletionTypeDiscovery != ''
|
||||
if !empty(g:SuperTabDefaultCompletionTypeDiscovery)
|
||||
" backward compatiability with old string value.
|
||||
if type(g:SuperTabDefaultCompletionTypeDiscovery) == 1
|
||||
let dlist = split(g:SuperTabDefaultCompletionTypeDiscovery, ',')
|
||||
else
|
||||
let dlist = g:SuperTabDefaultCompletionTypeDiscovery
|
||||
while dlist != ''
|
||||
let pair = substitute(dlist, '\(.\{-}\)\(,.*\|$\)', '\1', '')
|
||||
let dlist = substitute(dlist, '.\{-}\(,.*\|$\)', '\1', '')
|
||||
let dlist = substitute(dlist, '^,', '\1', '')
|
||||
|
||||
endif
|
||||
for pair in dlist
|
||||
let var = substitute(pair, '\(.*\):.*', '\1', '')
|
||||
let type = substitute(pair, '.*:\(.*\)', '\1', '')
|
||||
|
||||
exec 'let value = ' . var
|
||||
if value !~ '^\s*$' && value != '0'
|
||||
let b:SuperTabDefaultCompletionType = type
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
endfor
|
||||
endif
|
||||
|
||||
" fallback to configured default.
|
||||
|
|
@ -272,68 +322,6 @@ function! s:InitBuffer ()
|
|||
call SuperTabSetCompletionType(b:SuperTabDefaultCompletionType)
|
||||
endfunction " }}}
|
||||
|
||||
" s:IsWordChar(char) {{{
|
||||
" Determines if the supplied character is a word character or matches value
|
||||
" defined by 'iskeyword'.
|
||||
function! s:IsWordChar (char)
|
||||
if a:char =~ '\w'
|
||||
return 1
|
||||
endif
|
||||
|
||||
" check against 'iskeyword'
|
||||
let values = &iskeyword
|
||||
let index = stridx(values, ',')
|
||||
while index > 0 || values != ''
|
||||
if index > 0
|
||||
let value = strpart(values, 0, index)
|
||||
let values = strpart(values, index + 1)
|
||||
else
|
||||
let value = values
|
||||
let values = ''
|
||||
endif
|
||||
|
||||
" exception case for '^,'
|
||||
if value == '^'
|
||||
let value = '^,'
|
||||
|
||||
" execption case for ','
|
||||
elseif value =~ '^,,'
|
||||
let values .= strpart(value, 2)
|
||||
let value = ','
|
||||
|
||||
" execption case after a ^,
|
||||
elseif value =~ '^,'
|
||||
let value = strpart(value, 1)
|
||||
endif
|
||||
|
||||
" keyword values is an ascii number range
|
||||
if value =~ '[0-9]\+-[0-9]\+'
|
||||
let charnum = char2nr(a:char)
|
||||
exec 'let start = ' . substitute(value, '\([0-9]\+\)-.*', '\1', '')
|
||||
exec 'let end = ' . substitute(value, '.*-\([0-9]\+\)', '\1', '')
|
||||
|
||||
if charnum >= start && charnum <= end
|
||||
return 1
|
||||
endif
|
||||
|
||||
" keyword value is a set of include or exclude characters
|
||||
else
|
||||
let include = 1
|
||||
if value =~ '^\^'
|
||||
let value = strpart(value, 1)
|
||||
let include = 0
|
||||
endif
|
||||
|
||||
if a:char =~ '[' . escape(value, '[]') . ']'
|
||||
return include
|
||||
endif
|
||||
endif
|
||||
let index = stridx(values, ',')
|
||||
endwhile
|
||||
|
||||
return 0
|
||||
endfunction " }}}
|
||||
|
||||
" s:SetCompletionType() {{{
|
||||
" Sets the completion type based on what the user has chosen from the help
|
||||
" buffer.
|
||||
|
|
@ -349,32 +337,66 @@ endfunction " }}}
|
|||
|
||||
" s:SetDefaultCompletionType() {{{
|
||||
function! s:SetDefaultCompletionType()
|
||||
if exists('b:SuperTabDefaultCompletionType')
|
||||
if exists('b:SuperTabDefaultCompletionType') && !b:complCommandLine
|
||||
call SuperTabSetCompletionType(b:SuperTabDefaultCompletionType)
|
||||
endif
|
||||
endfunction " }}}
|
||||
|
||||
" s:SuperTab(command) {{{
|
||||
" Used to perform proper cycle navigtion as the user requests the next or
|
||||
" Used to perform proper cycle navigation as the user requests the next or
|
||||
" previous entry in a completion list, and determines whether or not to simply
|
||||
" retain the normal usage of <tab> based on the cursor position.
|
||||
function! s:SuperTab(command)
|
||||
if s:WillComplete()
|
||||
" rare case where no autocmds have fired for this buffer to initialize the
|
||||
" supertab vars.
|
||||
call s:InitBuffer()
|
||||
|
||||
let key = ''
|
||||
" highlight first result if longest enabled
|
||||
if g:SuperTabLongestHighlight && !pumvisible() && &completeopt =~ 'longest'
|
||||
let key = (b:complType == "\<C-P>") ? "\<C-P>" : "\<C-N>"
|
||||
let key = (b:complType == "\<c-p>") ? "\<c-p>" : "\<c-n>"
|
||||
endif
|
||||
|
||||
" exception: if in <c-p> mode, then <c-n> should move up the list, and
|
||||
" <c-p> down the list.
|
||||
if a:command == 'p' && b:complType == "\<C-P>"
|
||||
return "\<C-N>"
|
||||
if a:command == 'p' &&
|
||||
\ (b:complType == "\<c-p>" ||
|
||||
\ (b:complType == 'context' &&
|
||||
\ tolower(g:SuperTabContextDefaultCompletionType) == '<c-p>'))
|
||||
return "\<c-n>"
|
||||
endif
|
||||
|
||||
if b:complType == 'context'
|
||||
if index(g:SuperTabContextFileTypeExclusions, &ft) == -1
|
||||
let curline = getline('.')
|
||||
let cnum = col('.')
|
||||
let synname = synIDattr(synID(line('.'), cnum - 1, 1), 'name')
|
||||
if curline =~ '.*/\w*\%' . cnum . 'c' ||
|
||||
\ ((has('win32') || has('win64')) && curline =~ '.*\\\w*\%' . cnum . 'c')
|
||||
return "\<c-x>\<c-f>" . key
|
||||
elseif curline =~ '.*\(\w\|[\])]\)\(\.\|::\|->\)\w*\%' . cnum . 'c' &&
|
||||
\ synname !~ '\(String\|Comment\)'
|
||||
if &completefunc != ''
|
||||
return "\<c-x>\<c-u>" . key
|
||||
elseif &omnifunc != ''
|
||||
return "\<c-x>\<c-o>" . key
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
exec "let complType = \"" . escape(g:SuperTabContextDefaultCompletionType, '<') . "\""
|
||||
return complType . key
|
||||
endif
|
||||
|
||||
" Hack to workaround appent bug when invoking command line completion via
|
||||
" <c-r>=
|
||||
if b:complType == "\<c-x>\<c-v>"
|
||||
return s:CommandLineCompletion()
|
||||
endif
|
||||
return b:complType . key
|
||||
endif
|
||||
|
||||
return "\<Tab>"
|
||||
return "\<tab>"
|
||||
endfunction " }}}
|
||||
|
||||
" s:SuperTabHelp() {{{
|
||||
|
|
@ -424,32 +446,48 @@ function! s:WillComplete ()
|
|||
|
||||
" Within a word, but user does not have mid word completion enabled.
|
||||
let next_char = strpart(line, cnum - 1, 1)
|
||||
if !g:SuperTabMidWordCompletion && s:IsWordChar(next_char)
|
||||
if !g:SuperTabMidWordCompletion && next_char =~ '\k'
|
||||
return 0
|
||||
endif
|
||||
|
||||
" In keyword completion mode and no preceding word characters.
|
||||
"if (b:complType == "\<C-N>" || b:complType == "\<C-P>") && !s:IsWordChar(prev_char)
|
||||
"if (b:complType == "\<c-n>" || b:complType == "\<c-p>") && prev_char !~ '\k'
|
||||
" return 0
|
||||
"endif
|
||||
|
||||
return 1
|
||||
endfunction " }}}
|
||||
|
||||
" s:CommandLineCompletion() {{{
|
||||
" Hack needed to account for apparent bug in vim command line mode completion
|
||||
" when invoked via <c-r>=
|
||||
function! s:CommandLineCompletion()
|
||||
" This hack will trigger InsertLeave which will then invoke
|
||||
" s:SetDefaultCompletionType. To prevent default completion from being
|
||||
" restored prematurely, set an internal flag for s:SetDefaultCompletionType
|
||||
" to check for.
|
||||
let b:complCommandLine = 1
|
||||
return "\<c-\>\<c-o>:call feedkeys('\<c-x>\<c-v>\<c-v>', 'n') | " .
|
||||
\ "let b:complCommandLine = 0\<cr>"
|
||||
endfunction " }}}
|
||||
|
||||
" Key Mappings {{{
|
||||
im <C-X> <C-r>=CtrlXPP()<CR>
|
||||
" map a regular tab to ctrl-tab (note: doesn't work in console vim)
|
||||
exec 'inoremap ' . g:SuperTabMappingTabLiteral . ' <tab>'
|
||||
|
||||
imap <c-x> <c-r>=CtrlXPP()<cr>
|
||||
|
||||
" From the doc |insert.txt| improved
|
||||
exec 'im ' . g:SuperTabMappingForward . ' <C-n>'
|
||||
exec 'im ' . g:SuperTabMappingBackward . ' <C-p>'
|
||||
exec 'imap ' . g:SuperTabMappingForward . ' <c-n>'
|
||||
exec 'imap ' . g:SuperTabMappingBackward . ' <c-p>'
|
||||
|
||||
" After hitting <Tab>, hitting it once more will go to next match
|
||||
" (because in XIM mode <C-n> and <C-p> mappings are ignored)
|
||||
" (because in XIM mode <c-n> and <c-p> mappings are ignored)
|
||||
" and wont start a brand new completion
|
||||
" The side effect, that in the beginning of line <C-n> and <C-p> inserts a
|
||||
" The side effect, that in the beginning of line <c-n> and <c-p> inserts a
|
||||
" <Tab>, but I hope it may not be a problem...
|
||||
ino <C-n> <C-R>=<SID>SuperTab('n')<CR>
|
||||
ino <C-p> <C-R>=<SID>SuperTab('p')<CR>
|
||||
inoremap <c-n> <c-r>=<SID>SuperTab('n')<cr>
|
||||
inoremap <c-p> <c-r>=<SID>SuperTab('p')<cr>
|
||||
" }}}
|
||||
|
||||
" Command Mappings {{{
|
||||
|
|
@ -458,6 +496,6 @@ endfunction " }}}
|
|||
endif
|
||||
" }}}
|
||||
|
||||
call <SID>Init()
|
||||
call s:Init()
|
||||
|
||||
" vim:ft=vim:fdm=marker
|
||||
18
.vimrc
18
.vimrc
|
|
@ -4,36 +4,38 @@ syntax on
|
|||
"colorscheme dante
|
||||
colorscheme barak
|
||||
"set gfn=Monaco:h12:a
|
||||
set ts=4
|
||||
set softtabstop=4
|
||||
set shiftwidth=4
|
||||
set ts=8
|
||||
set softtabstop=8
|
||||
set shiftwidth=8
|
||||
"set expandtab
|
||||
set smartcase
|
||||
set autoindent
|
||||
set smartindent
|
||||
set hidden
|
||||
set backspace=indent,eol,start
|
||||
|
||||
set history=1000
|
||||
set wildmenu
|
||||
set wildmode=list:longest
|
||||
set ruler
|
||||
|
||||
|
||||
"Sources
|
||||
source ~/.vim/supertab.vim
|
||||
source ~/.vim/charm.vim
|
||||
source ~/.vim/plugin/AppleT.vim
|
||||
"source ~/.vim/supertab.vim
|
||||
"source ~/.vim/charm.vim
|
||||
"source ~/.vim/plugin/AppleT.vim
|
||||
runtime macros/matchit.vim
|
||||
"source ~/.vim/syntax/motd.vim
|
||||
|
||||
|
||||
au BufNewFile,BufRead motd.public,/tmp/motd.public.r.* setf motd
|
||||
"Highlighting features
|
||||
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
|
||||
autocmd FileType python set tags+=$HOME/.vim/tags/python.ctags
|
||||
autocmd FileType python set omnifunc=pythoncomplete#Complete
|
||||
"autocmd FileType python set omnifunc=pythoncomplete#Complete
|
||||
"autocmd FileType python call SuperTabSetCompletionType("<C-X><C-O>")
|
||||
let python_highlight_all = 1
|
||||
let g:Tb_MaxSize=0
|
||||
let g:Tb_MapCTabSwitchBufs = 1
|
||||
au Filetype html,xml,xsl source ~/.vim/closetag.vim
|
||||
|
||||
|
||||
|
|
|
|||
3
bin/prowl
Executable file
3
bin/prowl
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
$HOME/bin/prowl.pl -apikeyfile=$HOME/.prowlapi -event="Notice" -notification="$1"
|
||||
154
bin/prowl.pl
Executable file
154
bin/prowl.pl
Executable file
|
|
@ -0,0 +1,154 @@
|
|||
#!/usr/bin/perl -w
|
||||
# ProwlScript, to communicate with the Prowl server.
|
||||
#
|
||||
# Copyright (c) 2009, Zachary West
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# * Neither the name of Zachary West nor the
|
||||
# names of its contributors may be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY Zachary West ''AS IS'' AND ANY
|
||||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL Zachary West BE LIABLE FOR ANY
|
||||
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
# This requires running Prowl on your device.
|
||||
# See the Prowl website <http://prowl.weks.net>
|
||||
|
||||
use strict;
|
||||
use LWP::UserAgent;
|
||||
use Getopt::Long;
|
||||
use Pod::Usage;
|
||||
|
||||
# Grab our options.
|
||||
my %options = ();
|
||||
GetOptions(\%options, 'apikey=s', 'apikeyfile=s',
|
||||
'application=s', 'event=s', 'notification=s',
|
||||
'priority:i', 'help|?') or pod2usage(2);
|
||||
|
||||
$options{'application'} ||= "ProwlScript";
|
||||
$options{'priority'} ||= 0;
|
||||
|
||||
pod2usage(-verbose => 2) if (exists($options{'help'}));
|
||||
pod2usage(-message => "$0: Event name is required") if (!exists($options{'event'}));
|
||||
pod2usage(-message => "$0: Notification text is required") if (!exists($options{'notification'}));
|
||||
pod2usage(-priority => "$0: Priority must be in the range [-2, 2]") if ($options{'priority'} < -2 || $options{'priority'} > 2);
|
||||
|
||||
# Get the API key from STDIN if one isn't provided via a file or from the command line.
|
||||
if (!exists($options{'apikey'}) && !exists($options{'apikeyfile'})) {
|
||||
print "API key: ";
|
||||
|
||||
$options{'apikey'} = <STDIN>;
|
||||
chomp $options{'apikey'};
|
||||
} elsif (exists($options{'apikeyfile'})) {
|
||||
open(APIKEYFILE, $options{'apikeyfile'}) or die($!);
|
||||
$options{'apikey'} = <APIKEYFILE>;
|
||||
close(APIKEYFILE);
|
||||
|
||||
chomp $options{'apikey'};
|
||||
}
|
||||
|
||||
# URL encode our arguments
|
||||
$options{'application'} =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
|
||||
$options{'event'} =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
|
||||
$options{'notification'} =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
|
||||
|
||||
# Generate our HTTP request.
|
||||
my ($userAgent, $request, $response, $requestURL);
|
||||
$userAgent = LWP::UserAgent->new;
|
||||
$userAgent->agent("ProwlScript/1.0");
|
||||
|
||||
$requestURL = sprintf("https://prowl.weks.net/publicapi/add?apikey=%s&application=%s&event=%s&description=%s&priority=%d",
|
||||
$options{'apikey'},
|
||||
$options{'application'},
|
||||
$options{'event'},
|
||||
$options{'notification'},
|
||||
$options{'priority'});
|
||||
|
||||
$request = HTTP::Request->new(GET => $requestURL);
|
||||
|
||||
$response = $userAgent->request($request);
|
||||
|
||||
if ($response->is_success) {
|
||||
print "Notification successfully posted.\n";
|
||||
} elsif ($response->code == 401) {
|
||||
print STDERR "Notification not posted: incorrect API key.\n";
|
||||
} else {
|
||||
print STDERR "Notification not posted: " . $response->content . "\n";
|
||||
}
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
prowl - Send Prowl notifications
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
prowl.pl [options] event_information
|
||||
|
||||
Options:
|
||||
-help Display all help information.
|
||||
-apikey=... Your Prowl API key.
|
||||
-apikeyfile=... A file containing your Prowl API key.
|
||||
|
||||
Event information:
|
||||
-application=... The name of the application.
|
||||
-event=... The name of the event.
|
||||
-notification=... The text of the notification.
|
||||
-priority=... The priority of the notification.
|
||||
An integer in the range [-2, 2].
|
||||
|
||||
=head1 OPTIONS
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<-apikey>
|
||||
|
||||
Your Prowl API key. It is not recommend you use this, use the apikeyfile option.
|
||||
|
||||
=item B<-apikeyfile>
|
||||
|
||||
A file containing one line, which has your Prowl API key on it.
|
||||
|
||||
=item B<-application>
|
||||
|
||||
The name of the Application part of the notification. If none is provided, ProwlScript is used.
|
||||
|
||||
=item B<-event>
|
||||
|
||||
The name of the Event part of the notification. This is generally the action which occurs, such as "disk partitioning completed."
|
||||
|
||||
=item B<-notification>
|
||||
|
||||
The text of the notification, which has more details for a particular event. This is generally the description of the action which occurs, such as "The disk /dev/abc was successfully partitioned."
|
||||
|
||||
=item B<-notification>
|
||||
|
||||
The priority level of the notification. An integer value ranging [-2, 2] with meanings Very Low, Moderate, Normal, High, Emergency.
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
B<This program> sends a notification to the Prowl server, which is then forwarded to your device running the Prowl application.
|
||||
|
||||
=head1 HELP
|
||||
|
||||
For more assistance, visit the Prowl website at <http://prowl.weks.net>.
|
||||
|
||||
=cut
|
||||
Loading…
Add table
Add a link
Reference in a new issue