From 0ce33afc6cae01cfbb998ba2d62fb791c330d3b5 Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 06:29:58 +0100 Subject: [PATCH 01/25] Typo in installation instructions. --- plugin/pythonhelper.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index 83f0546..4d644b1 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -24,7 +24,7 @@ " to recompile it with --with-pythoninterp option to the configure script " 2. Copy script pythonhelper.vim to the $HOME/.vim/plugin directory " 3. add '%{TagInStatusLine()}' yo your vimrc/statusline -" 3. Run Vim and open any python file. +" 4. Run Vim and open any python file. " python << EOS From 2e27597939c15d8f3a05cb2aa1d899fe5beafcd1 Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 06:40:12 +0100 Subject: [PATCH 02/25] Code style. Tabs AND spaces? WTF. http://i.imgur.com/Lo5Vv.png --- plugin/pythonhelper.vim | 138 ++++++++++++++++++++-------------------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index 4d644b1..b54a4a5 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -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("") . ', ' . 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("") . ')' endfunction From 888970d931c2604ada1c43f739ad042bc8f66759 Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 06:44:04 +0100 Subject: [PATCH 03/25] More typos in the installation instructions --- plugin/pythonhelper.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index b54a4a5..b969333 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -23,7 +23,7 @@ " 1. Make sure your Vim has python feature on (+python). If not, you will need " to recompile it with --with-pythoninterp option to the configure script " 2. Copy script pythonhelper.vim to the $HOME/.vim/plugin directory -" 3. add '%{TagInStatusLine()}' yo your vimrc/statusline +" 3. add '%{TagInStatusLine()}' the statusline in your vimrc " 4. Run Vim and open any python file. " python << EOS From 333db2d78ec0fe01c58e595f7a7070efef8b28a1 Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 06:44:20 +0100 Subject: [PATCH 04/25] Yet more typos in the installation instructions --- plugin/pythonhelper.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index b969333..a376290 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -23,7 +23,7 @@ " 1. Make sure your Vim has python feature on (+python). If not, you will need " to recompile it with --with-pythoninterp option to the configure script " 2. Copy script pythonhelper.vim to the $HOME/.vim/plugin directory -" 3. add '%{TagInStatusLine()}' the statusline in your vimrc +" 3. Add '%{TagInStatusLine()}' the statusline in your vimrc " 4. Run Vim and open any python file. " python << EOS From 864d36fd02a550c11b57c648ab1a4cb8540d391b Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 06:46:29 +0100 Subject: [PATCH 05/25] Bad English in the installation instructions. --- plugin/pythonhelper.vim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index a376290..4a3626a 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -20,11 +20,12 @@ " " Installation " ------------ -" 1. Make sure your Vim has python feature on (+python). If not, you will need -" to recompile it with --with-pythoninterp option to the configure script -" 2. Copy script pythonhelper.vim to the $HOME/.vim/plugin directory +" 1. Make sure your Vim has the Python feature enabled (+python). If not, you +" will need to recompile it with the --with-pythoninterp option passed to +" the configure script +" 2. Copy the pythonhelper.vim script to the $HOME/.vim/plugin directory " 3. Add '%{TagInStatusLine()}' the statusline in your vimrc -" 4. Run Vim and open any python file. +" 4. Run Vim and open any Python file. " python << EOS From 6494b9de1c6aabe5912aac3f8786ebf4fa7c1f2c Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 06:46:51 +0100 Subject: [PATCH 06/25] Tweaked installation instructions. --- plugin/pythonhelper.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index 4a3626a..6ced051 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -23,7 +23,8 @@ " 1. Make sure your Vim has the Python feature enabled (+python). If not, you " will need to recompile it with the --with-pythoninterp option passed to " the configure script -" 2. Copy the pythonhelper.vim script to the $HOME/.vim/plugin directory +" 2. Copy the pythonhelper.vim script to the $HOME/.vim/plugin directory, or +" install it in some other way (vim-addon-manager, pathogen, ...) " 3. Add '%{TagInStatusLine()}' the statusline in your vimrc " 4. Run Vim and open any Python file. " From 42d72d9e6b033aef299f7e312cfe2e6beba82bb2 Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 06:47:45 +0100 Subject: [PATCH 07/25] More bad English in the doc. --- plugin/pythonhelper.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index 6ced051..f948749 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -13,10 +13,10 @@ " " Requirements " ------------ -" This script needs only VIM compiled with Python interpreter. It doesn't rely -" on exuberant ctags utility. You can determine whether your VIM has Python -" support by issuing command :ver and looking for +python in the list of -" features. +" This script needs only VIM compiled with the Python interpreter. It doesn't +" rely on the exuberant ctags utilities. You can determine whether your VIM +" has Python support by issuing command :ver and looking for +python in the +" list of features. " " Installation " ------------ From 005a35dcf6716cb95515af636a5659a15daab406 Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 06:50:52 +0100 Subject: [PATCH 08/25] More bad English in the doc. --- plugin/pythonhelper.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index f948749..d4d02dc 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -5,11 +5,11 @@ " " Overview " -------- -" Vim script to help moving around in larger Python source files. It displays -" current class, method or function the cursor is placed in on the status -" line for every python file. It's more clever than Yegappan Lakshmanan's -" taglist.vim because it takes into account indetation and comments to -" determine what tag the cursor is placed in. +" This Vim script helps you find yourself in larger Python source files. It +" displays the current Python class, method or function the cursor is placed +" on in the status line. It's smarter than Yegappan Lakshmanan's taglist.vim +" because it takes indentation and comments into account in order to determine +" what identifier the cursor is placed on. " " Requirements " ------------ From e70cca0a110a326852f5a925dcd2a0dad3a34c6e Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 07:23:25 +0100 Subject: [PATCH 09/25] Corrected documentation. --- plugin/pythonhelper.vim | 104 ++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index d4d02dc..8993034 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -126,7 +126,7 @@ class PythonTag(object): # class SimplePythonTagsParser() {{{ class SimplePythonTagsParser(object): # DOC {{{ - """Provides a simple python tag parser. + """Provides a simple Python tag parser. """ # }}} @@ -172,13 +172,13 @@ class SimplePythonTagsParser(object): def getTags(self): # DOC {{{ - """Determines all the tags for the buffer. Returns a tuple in format + """Determines all the tags for the buffer. Returns a tuple in the format (tagLineNumbers, tags,). """ # }}} # CODE {{{ - # initialize the resulting list of the tag line numbers and the tag information {{{ + # initialize the resulting list of tag line numbers and the tag information {{{ tagLineNumbers = [] tags = {} # }}} @@ -188,20 +188,20 @@ class SimplePythonTagsParser(object): lineNumber = 0 # }}} - # go through all the lines in the source and localize all python tags in it {{{ + # go through all the lines in the source and localize all Python tags in it {{{ while 1: # get next line line = self.source.readline() - # finish if this is the end of the source {{{ + # finish when we reach the end of the source {{{ if (line == ''): break # }}} - # increase the line number + # increase line number lineNumber += 1 - # extract the line indentation characters and its content {{{ + # extract the line's indentation characters and its content {{{ lineMatch = self.COMMENTS_INDENT_RE.match(line) lineContent = lineMatch.group(2) # }}} @@ -233,14 +233,14 @@ class SimplePythonTagsParser(object): # }}} # }}} - # return the tags data for the source + # return tag data for the source return (tagLineNumbers, tags,) # }}} def getParentTag(self, tagsStack): # DOC {{{ - """Returns the parent/enclosing tag (instance of PythonTag()) from the + """Given a tag, returns its parent tag (instance of PythonTag()) from the specified tag list. If no such parent tag exists, returns None. Parameters @@ -306,18 +306,18 @@ class SimplePythonTagsParser(object): tagName -- short name of the current tag - tagTypeDecidingMethod -- reference to method that is called to + tagTypeDecidingMethod -- reference to the method that is called to determine the type of the current tag """ # }}} # CODE {{{ - # compute the indentation level + # compute indentation level indentLevel = self.computeIndentationLevel(indentChars) - # get the parent tag + # get parent tag parentTag = self.getParentTag(tagsStack) - # handle an enclosed tag {{{ + # handle enclosed tag {{{ while (parentTag): # if the indent level of the parent tag is greater than of the current tag, use parent tag of the parent tag {{{ if (parentTag.indentLevel >= indentLevel): @@ -332,7 +332,7 @@ class SimplePythonTagsParser(object): break # }}} - # use parent tag of the parent tag + # use the parent tag of the parent tag parentTag = self.getParentTag(tagsStack) # }}} # handle a top-indent level tag {{{ @@ -392,7 +392,7 @@ class SimplePythonTagsParser(object): # class VimReadlineBuffer() {{{ class VimReadlineBuffer(object): # DOC {{{ - """A simple wrapper class around vim's buffer that provides readline + """A simple wrapper class around a Vim buffer that provides the readline method. """ # }}} @@ -406,7 +406,7 @@ class VimReadlineBuffer(object): Parameters - vimBuffer -- VIM's buffer + vimBuffer -- a Vim buffer """ # }}} @@ -423,8 +423,8 @@ class VimReadlineBuffer(object): def readline(self): # DOC {{{ - """Returns next line from the buffer. If all the buffer has been read, - returns empty string. + """Returns the next line from the buffer. If the whole buffer has been + read, returns an empty string. """ # }}} @@ -432,12 +432,12 @@ class VimReadlineBuffer(object): # increase the current line counter self.currentLine += 1 - # notify end of file if we reached beyond the last line {{{ + # tell if we reached beyond the last line {{{ if (self.currentLine == self.bufferLines): return '' # }}} - # return the line with an added newline (vim stores the lines without it) + # Vim stores the lines without the newlines, so add one return "%s\n" % (self.vimBuffer[self.currentLine],) # }}} @@ -448,8 +448,8 @@ class VimReadlineBuffer(object): def getNearestLineIndex(row, tagLineNumbers): # DOC {{{ - """Returns the index of line in 'tagLineNumbers' list that is nearest to the - specified cursor row. + """Returns the index of 'tagLineNumbers' that contains the line nearest to + the specified cursor row. Parameters @@ -473,28 +473,28 @@ def getNearestLineIndex(row, tagLineNumbers): nearestLineIndex = lineIndex # }}} - # if we've got past the current cursor position, let's end the search {{{ + # if we've come past the current cursor position, end the search {{{ if (lineNumber >= row): break # }}} # }}} - # return index of the line with the nearest tag + # return the index of the line with the nearest tag return nearestLineIndex # }}} def getTags(bufferNumber, changedTick): # DOC {{{ - """Reads the tags for the specified buffer number. Returns a tuple - (taglinenumber[buffer], tags[buffer],). + """Reads the tags for the buffer specified by the number. Returns a tuple + of the format (taglinenumber[buffer], tags[buffer],). Parameters bufferNumber -- number of the current buffer - changedTick -- ever increasing number used to tell if the buffer has - been modified since the last time + changedTick -- always-increasing number used to indicate that the buffer + has been modified since the last time """ # }}} @@ -531,18 +531,18 @@ def findTag(bufferNumber, changedTick): bufferNumber -- number of the current buffer - changedTick -- ever increasing number used to tell if the buffer has - been modified since the last time + changedTick -- always-increasing number used to indicate that 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 + # get the tag data for the current buffer tagLineNumbers, tags = getTags(bufferNumber, changedTick) - # link to vim's internal data {{{ + # link to Vim's internal data {{{ currentBuffer = vim.current.buffer currentWindow = vim.current.window row, col = currentWindow.cursor @@ -551,15 +551,16 @@ def findTag(bufferNumber, changedTick): # 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 a line has been found, find out if the tag is correct {{{ + # E.g. the cursor might be below the last tag, but in code that has + # nothing to do with the tag, which we know because the line is + # indented differently. In such a case no applicable tag has been + # found. while (nearestLineIndex > -1): # get the line number of the nearest tag nearestLineNumber = tagLineNumbers[nearestLineIndex] - # walk through all the lines in range (nearestTagLine, cursorRow) {{{ + # walk through all the lines in the range (nearestTagLine, cursorRow) {{{ for lineNumber in xrange(nearestLineNumber + 1, row): # get the current line line = currentBuffer[lineNumber] @@ -588,24 +589,24 @@ def findTag(bufferNumber, changedTick): if (i == len(line)): continue # }}} - # if the next character is a '#' (python comment), skip the line {{{ + # if the next character is a '#' (python comment), skip to the next line {{{ if (line[i] == '#'): continue # }}} - # if the line's indentation starts before or at the nearest tag's one, the tag is invalid {{{ + # if the line's indentation starts before or at the nearest tag's, the tag is invalid {{{ if (lineStart <= tags[nearestLineNumber].indentLevel): nearestLineIndex -= 1 break # }}} # }}} # }}} - # the tag is appropriate, so use it {{{ + # the tag is correct, so use it {{{ else: break # }}} # }}} - # no appropriate tag has been found {{{ + # no applicable tag has been found {{{ else: nearestLineNumber = -1 # }}} @@ -614,7 +615,7 @@ def findTag(bufferNumber, changedTick): # reset the description tagDescription = "" - # if an appropriate tag has been found, set the description accordingly {{{ + # if an applicable 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],) @@ -645,7 +646,7 @@ def findTag(bufferNumber, changedTick): def deleteTags(bufferNumber): # DOC {{{ - """Removes tags data for the specified buffer number. + """Removes tag data for the specified buffer number. Parameters @@ -673,23 +674,23 @@ EOS " VIM functions {{{ function! PHCursorHold() - " only python is supported {{{ + " only Python is supported {{{ if (!exists('b:current_syntax') || (b:current_syntax != 'python')) let w:PHStatusLine = '' return endif " }}} - " call python function findTag() with the current buffer number and changed ticks + " call Python function findTag() with the current buffer number and change status indicator execute 'python findTag(' . expand("") . ', ' . b:changedtick . ')' endfunction function! PHBufferDelete() - " set PHStatusLine for this window to empty string + " set the PHStatusLine for this window to an empty string let w:PHStatusLine = "" - " call python function deleteTags() with the cur + " call Python function findTag() with the current buffer number and change status indicator execute 'python deleteTags(' . expand("") . ')' endfunction @@ -698,7 +699,7 @@ function! TagInStatusLine() " return value of w:PHStatusLine in case it's set if (exists("w:PHStatusLine")) return w:PHStatusLine - " otherwise just return empty string + " otherwise just return an empty string else return "" endif @@ -737,15 +738,14 @@ endfunction " }}} -" event binding, vim customizing {{{ +" event binding, Vim customization {{{ -" autocommands binding +" autocommands autocmd CursorHold * call PHCursorHold() autocmd CursorHoldI * call PHCursorHold() autocmd BufDelete * silent call PHBufferDelete() -" time that determines after how long time of no activity the CursorHold event -" is fired up +" period of no activity after which the CursorHold event is triggered set updatetime=1000 " }}} From c9dc1f3ec0bdbb74a61eb6ec14c195a1dae243fe Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 07:26:38 +0100 Subject: [PATCH 10/25] Lame use of exceptions. Never ever use an except block without qualifying the exception type, never ever catch exceptions from multiple sources at once. --- plugin/pythonhelper.vim | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index 8993034..436f68c 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -659,12 +659,11 @@ def deleteTags(bufferNumber): global TAGS, TAGLINENUMBERS, BUFFERTICKS # try to delete the tags for the buffer {{{ - try: - del TAGS[bufferNumber] - del TAGLINENUMBERS[bufferNumber] - del BUFFERTICKS[bufferNumber] - except: - pass + for o in (TAGS, TAGLINENUMBERS, BUFFERTICKS): + try: + del o[bufferNumber] + except KeyError: + pass # }}} # }}} From fe86a19e35d6bee4c72ad23949efdaebbc912eb0 Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 07:39:02 +0100 Subject: [PATCH 11/25] Added a FIXME for the 'except Exception'. --- plugin/pythonhelper.vim | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index 436f68c..6c2bc67 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -628,6 +628,13 @@ def findTag(bufferNumber, changedTick): # handle possible exceptions {{{ except Exception: + # FIXME: wrap try/except blocks around single sources of exceptions + # ONLY. Break this try/except block into as many small ones as you + # need, and only catch classes of exceptions that you have encountered. + # Catching "Exception" is very, very bad style! + # To the author: why is this clause here? There's no git log for why you + # have added it. Can you please put in a comment of a specific situation + # where you have encountered exceptions? # bury into the traceback {{{ ec, ei, tb = sys.exc_info() while (tb != None): From f323d3cc74b2b612c5b7781bf367e12114a92c8c Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 07:48:02 +0100 Subject: [PATCH 12/25] Starting refactor towards an iterator. --- plugin/pythonhelper.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index 6c2bc67..d8b6730 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -389,6 +389,9 @@ class SimplePythonTagsParser(object): # }}} +def vimBufferIterator(vimBuffer): + return VimReadlineBuffer(vimBuffer) + # class VimReadlineBuffer() {{{ class VimReadlineBuffer(object): # DOC {{{ @@ -508,7 +511,7 @@ def getTags(bufferNumber, changedTick): # }}} # get the tags {{{ - simpleTagsParser = SimplePythonTagsParser(VimReadlineBuffer(vim.current.buffer)) + simpleTagsParser = SimplePythonTagsParser(vimBufferIterator(vim.current.buffer)) tagLineNumbers, tags = simpleTagsParser.getTags() # }}} From d6046886a32584a7911aaddde59ae43a4c2e2e6f Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 07:48:26 +0100 Subject: [PATCH 13/25] Exceptions can tell you the same thing. --- plugin/pythonhelper.vim | 7 ------- 1 file changed, 7 deletions(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index d8b6730..3846ab2 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -158,13 +158,6 @@ class SimplePythonTagsParser(object): """ # }}} - # CODE {{{ - # make sure source has readline() method {{{ - if ((hasattr(source, 'readline') == 0) or - (callable(source.readline) == 0)): - raise AttributeError("Source must have callable readline method.") - # }}} - # remember what the source is self.source = source # }}} From ba115f64cc4162a194f1f2808b700a7cd206c176 Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 07:54:29 +0100 Subject: [PATCH 14/25] Initial iterator-based implementation. --- plugin/pythonhelper.vim | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index 3846ab2..e7a0357 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -154,7 +154,7 @@ class SimplePythonTagsParser(object): Parameters source -- source for which the tags will be generated. It must - provide callable method readline (i.e. as file objects do). + be a generator. """ # }}} @@ -182,14 +182,7 @@ class SimplePythonTagsParser(object): # }}} # go through all the lines in the source and localize all Python tags in it {{{ - while 1: - # get next line - line = self.source.readline() - - # finish when we reach the end of the source {{{ - if (line == ''): - break - # }}} + for line in self.source: # increase line number lineNumber += 1 @@ -383,7 +376,12 @@ class SimplePythonTagsParser(object): def vimBufferIterator(vimBuffer): - return VimReadlineBuffer(vimBuffer) + buf = VimReadlineBuffer(vimBuffer) + while True: + line = buf.readline() + if line == '': + break + yield line # class VimReadlineBuffer() {{{ class VimReadlineBuffer(object): From aee6f328aa195b8f6bcee53eefadf9ccb62b7d05 Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 07:59:34 +0100 Subject: [PATCH 15/25] Continue refactoring towards an iterator. --- plugin/pythonhelper.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index e7a0357..cba805b 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -376,6 +376,10 @@ class SimplePythonTagsParser(object): def vimBufferIterator(vimBuffer): + for line in vimBuffer: + yield line + "\n" + +def vimBufferIterator2(vimBuffer): buf = VimReadlineBuffer(vimBuffer) while True: line = buf.readline() From a361304e73d1ffffb95b77863974bd5766c00176 Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 08:03:23 +0100 Subject: [PATCH 16/25] Deleted non-iterator code. Refactoring complete. --- plugin/pythonhelper.vim | 65 ----------------------------------------- 1 file changed, 65 deletions(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index cba805b..4325e04 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -379,71 +379,6 @@ def vimBufferIterator(vimBuffer): for line in vimBuffer: yield line + "\n" -def vimBufferIterator2(vimBuffer): - buf = VimReadlineBuffer(vimBuffer) - while True: - line = buf.readline() - if line == '': - break - yield line - -# class VimReadlineBuffer() {{{ -class VimReadlineBuffer(object): - # DOC {{{ - """A simple wrapper class around a Vim buffer that provides the readline - method. - """ - # }}} - - - # METHODS {{{ - - def __init__(self, vimBuffer): - # DOC {{{ - """Initializes instances of VimReadlineBuffer(). - - Parameters - - vimBuffer -- a Vim buffer - """ - # }}} - - # CODE {{{ - # remember the settings - self.vimBuffer = vimBuffer - - # initialize instance attributes {{{ - self.currentLine = -1 - self.bufferLines = len(vimBuffer) - # }}} - # }}} - - - def readline(self): - # DOC {{{ - """Returns the next line from the buffer. If the whole buffer has been - read, returns an empty string. - """ - # }}} - - # CODE {{{ - # increase the current line counter - self.currentLine += 1 - - # tell if we reached beyond the last line {{{ - if (self.currentLine == self.bufferLines): - return '' - # }}} - - # Vim stores the lines without the newlines, so add one - return "%s\n" % (self.vimBuffer[self.currentLine],) - # }}} - - - # }}} -# }}} - - def getNearestLineIndex(row, tagLineNumbers): # DOC {{{ """Returns the index of 'tagLineNumbers' that contains the line nearest to From 702b07e3904c49336277083cd62fc435a4036357 Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 08:03:39 +0100 Subject: [PATCH 17/25] Code style. --- plugin/pythonhelper.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index 4325e04..1832d42 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -374,7 +374,6 @@ class SimplePythonTagsParser(object): # }}} # }}} - def vimBufferIterator(vimBuffer): for line in vimBuffer: yield line + "\n" From 0cccd82b2a3d624f0a31a2a218f8d4948d954425 Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 08:14:33 +0100 Subject: [PATCH 18/25] Use a zipper instead of counting by hand. --- plugin/pythonhelper.vim | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index 1832d42..8de8ef4 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -178,14 +178,11 @@ class SimplePythonTagsParser(object): # initalize local auxiliary variables {{{ tagsStack = [] - lineNumber = 0 # }}} + import itertools # go through all the lines in the source and localize all Python tags in it {{{ - for line in self.source: - - # increase line number - lineNumber += 1 + for (line, lineNumber) in zip(self.source, itertools.count(1)): # extract the line's indentation characters and its content {{{ lineMatch = self.COMMENTS_INDENT_RE.match(line) From 1b61929c9a65c777f362ab9af297e30ed3c7acc3 Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 08:16:28 +0100 Subject: [PATCH 19/25] Doc bug. --- plugin/pythonhelper.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index 8de8ef4..f52c614 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -625,7 +625,7 @@ function! PHBufferDelete() " set the PHStatusLine for this window to an empty string let w:PHStatusLine = "" - " call Python function findTag() with the current buffer number and change status indicator + " call Python function deleteTags() with the current buffer number and change status indicator execute 'python deleteTags(' . expand("") . ')' endfunction From dcf5507d0ff41ff1fa729cfdf1109a79f646065e Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 08:35:36 +0100 Subject: [PATCH 20/25] Doc bug. --- plugin/pythonhelper.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index f52c614..38f0852 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -25,7 +25,7 @@ " the configure script " 2. Copy the pythonhelper.vim script to the $HOME/.vim/plugin directory, or " install it in some other way (vim-addon-manager, pathogen, ...) -" 3. Add '%{TagInStatusLine()}' the statusline in your vimrc +" 3. Add '%{TagInStatusLine()}' to the statusline in your vimrc " 4. Run Vim and open any Python file. " python << EOS From 4a9a963dd6a0a0e27ab0c04ed7e3fb4faa9dbea7 Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 08:38:18 +0100 Subject: [PATCH 21/25] Added the ability to separately access the tag name and tag type, via TagInStatusLineTag or TagInStatusLineType respectively. --- plugin/pythonhelper.vim | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index 38f0852..6122b3b 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -25,7 +25,9 @@ " the configure script " 2. Copy the pythonhelper.vim script to the $HOME/.vim/plugin directory, or " install it in some other way (vim-addon-manager, pathogen, ...) -" 3. Add '%{TagInStatusLine()}' to the statusline in your vimrc +" 3. Add '%{TagInStatusLine()}' to the statusline in your vimrc. You can also +" use %{TagInStatusLine()} or %{TagInStatusLine()} for just the tag name or +" type respectively. " 4. Run Vim and open any Python file. " python << EOS @@ -543,16 +545,22 @@ def findTag(bufferNumber, changedTick): # describe the cursor position (what tag the cursor is on) {{{ # reset the description tagDescription = "" + tagDescriptionTag = "" + tagDescriptionType = "" # if an applicable 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],) + tagDescriptionTag = tagInfo.fullName + tagDescriptionType = PythonTag.TAG_TYPE_NAME[tagInfo.type] + tagDescription = "%s (%s)" % (tagDescriptionTag, tagDescriptionType) # }}} # }}} # 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:PHStatusLineTag=\"%s\"" % (tagDescriptionTag,)) + vim.command("let w:PHStatusLineType=\"%s\"" % (tagDescriptionType,)) # }}} # handle possible exceptions {{{ @@ -612,6 +620,8 @@ function! PHCursorHold() " only Python is supported {{{ if (!exists('b:current_syntax') || (b:current_syntax != 'python')) let w:PHStatusLine = '' + let w:PHStatusLineTag = '' + let w:PHStatusLineType = '' return endif " }}} @@ -622,8 +632,10 @@ endfunction function! PHBufferDelete() - " set the PHStatusLine for this window to an empty string + " set the PHStatusLine etc for this window to an empty string let w:PHStatusLine = "" + let w:PHStatusLineTag = '' + let w:PHStatusLineType = '' " call Python function deleteTags() with the current buffer number and change status indicator execute 'python deleteTags(' . expand("") . ')' @@ -641,6 +653,28 @@ function! TagInStatusLine() endfunction +function! TagInStatusLineTag() + " return value of w:PHStatusLineTag in case it's set + if (exists("w:PHStatusLineTag")) + return w:PHStatusLineTag + " otherwise just return an empty string + else + return "" + endif +endfunction + + +function! TagInStatusLineType() + " return value of w:PHStatusLineType in case it's set + if (exists("w:PHStatusLineType")) + return w:PHStatusLineType + " otherwise just return an empty string + else + return "" + endif +endfunction + + function! PHPreviousClassMethod() call search('^[ \t]*\(class\|def\)\>', 'bw') endfunction From 1e1d1cc6f1c45f0207c5da3a8bb5edc9a6d52c26 Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 08:41:52 +0100 Subject: [PATCH 22/25] Doc bug. --- plugin/pythonhelper.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index 6122b3b..bb795eb 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -26,8 +26,8 @@ " 2. Copy the pythonhelper.vim script to the $HOME/.vim/plugin directory, or " install it in some other way (vim-addon-manager, pathogen, ...) " 3. Add '%{TagInStatusLine()}' to the statusline in your vimrc. You can also -" use %{TagInStatusLine()} or %{TagInStatusLine()} for just the tag name or -" type respectively. +" use %{TagInStatusLineTag()} or %{TagInStatusLineType()} for just the tag +" name or tag type respectively. " 4. Run Vim and open any Python file. " python << EOS From e1d3306adc633b97b05a17390a868d3531b777ee Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 08:59:41 +0100 Subject: [PATCH 23/25] You can now set the updatetime used by pythonhelper with g:pythonhelper_updatetime. --- plugin/pythonhelper.vim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index bb795eb..99b2d59 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -715,7 +715,12 @@ autocmd CursorHoldI * call PHCursorHold() autocmd BufDelete * silent call PHBufferDelete() " period of no activity after which the CursorHold event is triggered -set updatetime=1000 +if (exists("g:pythonhelper_updatetime")) + let &updatetime = g:pythonhelper_updatetime +" otherwise just return an empty string +else + set updatetime=1000 +endif " }}} From 476707b68715b0bbfa4a523b12e46216b868b3f2 Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 09:08:03 +0100 Subject: [PATCH 24/25] Deleted stray comment. --- plugin/pythonhelper.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index 99b2d59..9ba67f7 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -717,7 +717,6 @@ autocmd BufDelete * silent call PHBufferDelete() " period of no activity after which the CursorHold event is triggered if (exists("g:pythonhelper_updatetime")) let &updatetime = g:pythonhelper_updatetime -" otherwise just return an empty string else set updatetime=1000 endif From 8f88e4bc7f474876310ebcdf989f275ab0f2a84a Mon Sep 17 00:00:00 2001 From: cheater Date: Wed, 8 Feb 2012 09:17:14 +0100 Subject: [PATCH 25/25] Only set updatetime if g:pythonhelper_updatetime is set. --- plugin/pythonhelper.vim | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugin/pythonhelper.vim b/plugin/pythonhelper.vim index 9ba67f7..b612ab0 100644 --- a/plugin/pythonhelper.vim +++ b/plugin/pythonhelper.vim @@ -717,8 +717,6 @@ autocmd BufDelete * silent call PHBufferDelete() " period of no activity after which the CursorHold event is triggered if (exists("g:pythonhelper_updatetime")) let &updatetime = g:pythonhelper_updatetime -else - set updatetime=1000 endif " }}}