vimrc cleanup, new versions

git-svn-id: http://photonzero.com/dotfiles/trunk@31 23f722f6-122a-0410-8cef-c75bd312dd78
This commit is contained in:
michener 2009-09-09 00:48:20 +00:00
parent 143fd36427
commit 6becfb4ec2
7 changed files with 725 additions and 501 deletions

View file

@ -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':

View file

@ -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

File diff suppressed because it is too large Load diff

18
.vimrc
View file

@ -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
View file

@ -0,0 +1,3 @@
#!/bin/bash
$HOME/bin/prowl.pl -apikeyfile=$HOME/.prowlapi -event="Notice" -notification="$1"

154
bin/prowl.pl Executable file
View 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