1
0
mirror of https://github.com/gryf/pythonhelper.git synced 2025-12-19 12:28:16 +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

@@ -451,9 +451,9 @@ def getNearestLineIndex(row, tagLineNumbers):
Parameters 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 {{{ # go through all tag line numbers and find the one nearest to the specified row {{{
for lineIndex, lineNumber in enumerate(tagLineNumbers): for lineIndex, lineNumber in enumerate(tagLineNumbers):
# if the current line is nearer the current cursor position, take it {{{ # if the current line is nearer the current cursor position, take it {{{
if (nearestLineNumber < lineNumber <= row): if (nearestLineNumber < lineNumber <= row):
nearestLineNumber = lineNumber nearestLineNumber = lineNumber
nearestLineIndex = lineIndex nearestLineIndex = lineIndex
# }}} # }}}
# if we've got past the current cursor position, let's end the search {{{ # if we've got past the current cursor position, let's end the search {{{
if (lineNumber >= row): if (lineNumber >= row):
break break
# }}} # }}}
# }}} # }}}
# return index of the line with the nearest tag # return index of the line with the nearest tag
@@ -489,10 +489,10 @@ def getTags(bufferNumber, changedTick):
Parameters Parameters
bufferNumber -- number of the current buffer bufferNumber -- number of the current buffer
changedTick -- ever increasing number used to tell if the buffer has changedTick -- ever increasing number used to tell if the buffer has
been modified since the last time 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 {{{ # return immediately if there's no need to update the tags {{{
if (BUFFERTICKS.get(bufferNumber, None) == changedTick): if (BUFFERTICKS.get(bufferNumber, None) == changedTick):
return (TAGLINENUMBERS[bufferNumber], TAGS[bufferNumber],) return (TAGLINENUMBERS[bufferNumber], TAGS[bufferNumber],)
# }}} # }}}
# get the tags {{{ # get the tags {{{
@@ -527,32 +527,32 @@ def findTag(bufferNumber, changedTick):
Parameters Parameters
bufferNumber -- number of the current buffer bufferNumber -- number of the current buffer
changedTick -- ever increasing number used to tell if the buffer has changedTick -- ever increasing number used to tell if the buffer has
been modified since the last time been modified since the last time
""" """
# }}} # }}}
# CODE {{{ # CODE {{{
# try to find the best tag {{{ # try to find the best tag {{{
try: try:
# get the tags data for the current buffer # get the tags data for the current buffer
tagLineNumbers, tags = getTags(bufferNumber, changedTick) tagLineNumbers, tags = getTags(bufferNumber, changedTick)
# link to vim's internal data {{{ # link to vim's internal data {{{
currentBuffer = vim.current.buffer currentBuffer = vim.current.buffer
currentWindow = vim.current.window currentWindow = vim.current.window
row, col = currentWindow.cursor row, col = currentWindow.cursor
# }}} # }}}
# get the index of the nearest line # get the index of the nearest line
nearestLineIndex = getNearestLineIndex(row, tagLineNumbers) nearestLineIndex = getNearestLineIndex(row, tagLineNumbers)
# if any line was found, try to find if the tag is appropriate {{{ # 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 # (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 # to do with the tag, because it's indented differently, in such case no
# appropriate tag has been found.) # appropriate tag has been found.)
while (nearestLineIndex > -1): while (nearestLineIndex > -1):
# get the line number of the nearest tag # get the line number of the nearest tag
nearestLineNumber = tagLineNumbers[nearestLineIndex] nearestLineNumber = tagLineNumbers[nearestLineIndex]
@@ -601,41 +601,41 @@ def findTag(bufferNumber, changedTick):
# the tag is appropriate, so use it {{{ # the tag is appropriate, so use it {{{
else: else:
break break
# }}} # }}}
# }}} # }}}
# no appropriate tag has been found {{{ # no appropriate tag has been found {{{
else: else:
nearestLineNumber = -1 nearestLineNumber = -1
# }}} # }}}
# describe the cursor position (what tag the cursor is on) {{{ # describe the cursor position (what tag the cursor is on) {{{
# reset the description # reset the description
tagDescription = "" tagDescription = ""
# if an appropriate tag has been found, set the description accordingly {{{ # if an appropriate tag has been found, set the description accordingly {{{
if (nearestLineNumber > -1): if (nearestLineNumber > -1):
tagInfo = tags[nearestLineNumber] tagInfo = tags[nearestLineNumber]
tagDescription = "%s (%s)" % (tagInfo.fullName, PythonTag.TAG_TYPE_NAME[tagInfo.type],) 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 # update the variable for the status line so it get updated with the new description
vim.command("let w:PHStatusLine=\"%s\"" % (tagDescription,)) vim.command("let w:PHStatusLine=\"%s\"" % (tagDescription,))
# }}} # }}}
# handle possible exceptions {{{ # handle possible exceptions {{{
except Exception: except Exception:
# bury into the traceback {{{ # bury into the traceback {{{
ec, ei, tb = sys.exc_info() ec, ei, tb = sys.exc_info()
while (tb != None): while (tb != None):
if (tb.tb_next == None): if (tb.tb_next == None):
break break
tb = tb.tb_next tb = tb.tb_next
# }}} # }}}
# spit out the error {{{ # spit out the error {{{
print "ERROR: %s %s %s:%u" % (ec.__name__, ei, tb.tb_frame.f_code.co_filename, tb.tb_lineno,) print "ERROR: %s %s %s:%u" % (ec.__name__, ei, tb.tb_frame.f_code.co_filename, tb.tb_lineno,)
time.sleep(0.5) time.sleep(0.5)
# }}} # }}}
# }}} # }}}
# }}} # }}}
@@ -673,8 +673,8 @@ EOS
function! PHCursorHold() function! PHCursorHold()
" only python is supported {{{ " only python is supported {{{
if (!exists('b:current_syntax') || (b:current_syntax != 'python')) if (!exists('b:current_syntax') || (b:current_syntax != 'python'))
let w:PHStatusLine = '' let w:PHStatusLine = ''
return return
endif endif
" }}} " }}}