1
0
mirror of https://github.com/gryf/pythonhelper.git synced 2025-12-18 20:10:24 +01:00

Code style. Tabs AND spaces? WTF. http://i.imgur.com/Lo5Vv.png

This commit is contained in:
cheater
2012-02-08 06:40:12 +01:00
committed by cheater
parent 0ce33afc6c
commit 2e27597939

View File

@@ -25,7 +25,7 @@
" 2. Copy script pythonhelper.vim to the $HOME/.vim/plugin directory
" 3. add '%{TagInStatusLine()}' yo your vimrc/statusline
" 4. Run Vim and open any python file.
"
"
python << EOS
# import of required modules {{{
@@ -53,7 +53,7 @@ class PythonTag(object):
# STATIC VARIABLES {{{
# possible tag types {{{
TT_CLASS = 0
TT_METHOD = 1
@@ -72,13 +72,13 @@ class PythonTag(object):
# METHODS {{{
def __init__(self, type, name, fullName, lineNumber, indentLevel):
# DOC {{{
"""Initializes instances of PythonTag().
Parameters
type -- tag type
name -- short tag name
@@ -119,9 +119,9 @@ class PythonTag(object):
# }}}
# }}}
# class SimplePythonTagsParser() {{{
# class SimplePythonTagsParser() {{{
class SimplePythonTagsParser(object):
# DOC {{{
"""Provides a simple python tag parser.
@@ -144,7 +144,7 @@ class SimplePythonTagsParser(object):
# METHODS {{{
def __init__(self, source):
# DOC {{{
"""Initializes instances of SimplePythonTagsParser().
@@ -162,12 +162,12 @@ class SimplePythonTagsParser(object):
(callable(source.readline) == 0)):
raise AttributeError("Source must have callable readline method.")
# }}}
# remember what the source is
self.source = source
# }}}
def getTags(self):
# DOC {{{
"""Determines all the tags for the buffer. Returns a tuple in format
@@ -185,7 +185,7 @@ class SimplePythonTagsParser(object):
tagsStack = []
lineNumber = 0
# }}}
# go through all the lines in the source and localize all python tags in it {{{
while 1:
# get next line
@@ -254,7 +254,7 @@ class SimplePythonTagsParser(object):
else:
parentTag = None
# }}}
# return the tag
return parentTag
# }}}
@@ -370,7 +370,7 @@ class SimplePythonTagsParser(object):
tag) for functions/methods.
Parameters
parentTagType -- type of the enclosing/parent tag
"""
# }}}
@@ -439,7 +439,7 @@ class VimReadlineBuffer(object):
return "%s\n" % (self.vimBuffer[self.currentLine],)
# }}}
# }}}
# }}}
@@ -451,9 +451,9 @@ def getNearestLineIndex(row, tagLineNumbers):
Parameters
row -- current cursor row
row -- current cursor row
tagLineNumbers -- list of tags' line numbers (ie. their position)
tagLineNumbers -- list of tags' line numbers (ie. their position)
"""
# }}}
@@ -465,16 +465,16 @@ def getNearestLineIndex(row, tagLineNumbers):
# go through all tag line numbers and find the one nearest to the specified row {{{
for lineIndex, lineNumber in enumerate(tagLineNumbers):
# if the current line is nearer the current cursor position, take it {{{
if (nearestLineNumber < lineNumber <= row):
nearestLineNumber = lineNumber
# if the current line is nearer the current cursor position, take it {{{
if (nearestLineNumber < lineNumber <= row):
nearestLineNumber = lineNumber
nearestLineIndex = lineIndex
# }}}
# }}}
# if we've got past the current cursor position, let's end the search {{{
if (lineNumber >= row):
break
# }}}
# if we've got past the current cursor position, let's end the search {{{
if (lineNumber >= row):
break
# }}}
# }}}
# return index of the line with the nearest tag
@@ -489,10 +489,10 @@ def getTags(bufferNumber, changedTick):
Parameters
bufferNumber -- number of the current buffer
bufferNumber -- number of the current buffer
changedTick -- ever increasing number used to tell if the buffer has
been modified since the last time
changedTick -- ever increasing number used to tell if the buffer has
been modified since the last time
"""
# }}}
@@ -502,7 +502,7 @@ def getTags(bufferNumber, changedTick):
# return immediately if there's no need to update the tags {{{
if (BUFFERTICKS.get(bufferNumber, None) == changedTick):
return (TAGLINENUMBERS[bufferNumber], TAGS[bufferNumber],)
return (TAGLINENUMBERS[bufferNumber], TAGS[bufferNumber],)
# }}}
# get the tags {{{
@@ -527,32 +527,32 @@ def findTag(bufferNumber, changedTick):
Parameters
bufferNumber -- number of the current buffer
bufferNumber -- number of the current buffer
changedTick -- ever increasing number used to tell if the buffer has
been modified since the last time
changedTick -- ever increasing number used to tell if the buffer has
been modified since the last time
"""
# }}}
# CODE {{{
# try to find the best tag {{{
try:
# get the tags data for the current buffer
tagLineNumbers, tags = getTags(bufferNumber, changedTick)
# get the tags data for the current buffer
tagLineNumbers, tags = getTags(bufferNumber, changedTick)
# link to vim's internal data {{{
currentBuffer = vim.current.buffer
currentWindow = vim.current.window
row, col = currentWindow.cursor
# }}}
# link to vim's internal data {{{
currentBuffer = vim.current.buffer
currentWindow = vim.current.window
row, col = currentWindow.cursor
# }}}
# get the index of the nearest line
nearestLineIndex = getNearestLineIndex(row, tagLineNumbers)
# get the index of the nearest line
nearestLineIndex = getNearestLineIndex(row, tagLineNumbers)
# if any line was found, try to find if the tag is appropriate {{{
# (ie. the cursor can be below the last tag but on a code that has nothing
# to do with the tag, because it's indented differently, in such case no
# appropriate tag has been found.)
# if any line was found, try to find if the tag is appropriate {{{
# (ie. the cursor can be below the last tag but on a code that has nothing
# to do with the tag, because it's indented differently, in such case no
# appropriate tag has been found.)
while (nearestLineIndex > -1):
# get the line number of the nearest tag
nearestLineNumber = tagLineNumbers[nearestLineIndex]
@@ -601,41 +601,41 @@ def findTag(bufferNumber, changedTick):
# the tag is appropriate, so use it {{{
else:
break
# }}}
# }}}
# }}}
# no appropriate tag has been found {{{
else:
nearestLineNumber = -1
# }}}
# describe the cursor position (what tag the cursor is on) {{{
else:
nearestLineNumber = -1
# }}}
# describe the cursor position (what tag the cursor is on) {{{
# reset the description
tagDescription = ""
tagDescription = ""
# if an appropriate tag has been found, set the description accordingly {{{
if (nearestLineNumber > -1):
tagInfo = tags[nearestLineNumber]
tagDescription = "%s (%s)" % (tagInfo.fullName, PythonTag.TAG_TYPE_NAME[tagInfo.type],)
# }}}
# }}}
if (nearestLineNumber > -1):
tagInfo = tags[nearestLineNumber]
tagDescription = "%s (%s)" % (tagInfo.fullName, PythonTag.TAG_TYPE_NAME[tagInfo.type],)
# }}}
# }}}
# update the variable for the status line so it get updated with the new description
vim.command("let w:PHStatusLine=\"%s\"" % (tagDescription,))
# update the variable for the status line so it get updated with the new description
vim.command("let w:PHStatusLine=\"%s\"" % (tagDescription,))
# }}}
# handle possible exceptions {{{
except Exception:
# bury into the traceback {{{
ec, ei, tb = sys.exc_info()
while (tb != None):
if (tb.tb_next == None):
break
tb = tb.tb_next
ec, ei, tb = sys.exc_info()
while (tb != None):
if (tb.tb_next == None):
break
tb = tb.tb_next
# }}}
# spit out the error {{{
print "ERROR: %s %s %s:%u" % (ec.__name__, ei, tb.tb_frame.f_code.co_filename, tb.tb_lineno,)
time.sleep(0.5)
print "ERROR: %s %s %s:%u" % (ec.__name__, ei, tb.tb_frame.f_code.co_filename, tb.tb_lineno,)
time.sleep(0.5)
# }}}
# }}}
# }}}
@@ -654,7 +654,7 @@ def deleteTags(bufferNumber):
# CODE {{{
# define global variables
global TAGS, TAGLINENUMBERS, BUFFERTICKS
# try to delete the tags for the buffer {{{
try:
del TAGS[bufferNumber]
@@ -673,11 +673,11 @@ EOS
function! PHCursorHold()
" only python is supported {{{
if (!exists('b:current_syntax') || (b:current_syntax != 'python'))
let w:PHStatusLine = ''
return
let w:PHStatusLine = ''
return
endif
" }}}
" call python function findTag() with the current buffer number and changed ticks
execute 'python findTag(' . expand("<abuf>") . ', ' . b:changedtick . ')'
endfunction
@@ -686,7 +686,7 @@ endfunction
function! PHBufferDelete()
" set PHStatusLine for this window to empty string
let w:PHStatusLine = ""
" call python function deleteTags() with the cur
execute 'python deleteTags(' . expand("<abuf>") . ')'
endfunction