コード例 #1
0
 def get_regex_linecoloffsetlength_of(self,
                                      regex,
                                      contents=None,
                                      start=0,
                                      forward=True):
     if forward:
         contents = contents or self.get_contents_from_cursor()
         try:
             rgx = re.compile(regex, re.MULTILINE)
         except:
             return (0, 0, -1, 0)
         match = rgx.search(contents, start)
         if match is None:
             return (0, 0, -1, 0)
         index = match.start()
         lines, columns = text.get_linecol_offset(contents[:index])
         l, c = self.cursor
         columns = c + columns if lines == 0 else columns + 1
         lines = l + lines
         length = match.end() - match.start()
         return lines, columns, index, length
     else:
         contents = contents or self.get_contents_before_cursor()
         try:
             rgx = re.compile(regex, re.MULTILINE)
         except:
             return (0, 0, -1, 0)
         match = None
         for match in rgx.finditer(contents, endpos=len(contents) - start):
             pass
         if match is None:
             return (0, 0, -1, 0)
         index = match.start()
         lines, columns = text.get_linecol_offset(contents[index:],
                                                  forward=False)
         back = index - contents.rfind('\n', 0, index) - 1
         if back == -1: back = 0
         columns = back + 1
         tabs = contents[contents.rfind('\n', 0, index):index].count('\t')
         columns += 7 * tabs
         ol, oc = lines, columns
         l, c = self.cursor
         lines = l - lines
         length = match.end() - match.start()
         return lines, columns, index, length
コード例 #2
0
ファイル: buffer.py プロジェクト: philipdexter/vx
 def get_linecoloffset_of(self, to_find, contents=None, start=0, forward=True):
     if forward:
         contents = contents or self.get_contents_from_cursor()
         index = contents.find(to_find, start)
         lines, columns = text.get_linecol_offset(contents[:index])
         l, c = self.cursor
         columns = c + columns if lines == 0 else columns + 1
         lines = l + lines
         return lines, columns, index
     else:
         raise Exception('not implemented')
コード例 #3
0
ファイル: buffer.py プロジェクト: philipdexter/vx
 def get_regex_linecoloffsetlength_of(self, regex, contents=None, start=0, forward=True):
     if forward:
         contents = contents or self.get_contents_from_cursor()
         try:
             rgx = re.compile(regex, re.MULTILINE)
         except:
             return (0, 0, -1, 0)
         match = rgx.search(contents, start)
         if match is None:
             return (0, 0, -1, 0)
         index = match.start()
         lines, columns = text.get_linecol_offset(contents[:index])
         l, c = self.cursor
         columns = c + columns if lines == 0 else columns + 1
         lines = l + lines
         length = match.end() - match.start()
         return lines, columns, index, length
     else:
         contents = contents or self.get_contents_before_cursor()
         try:
             rgx = re.compile(regex, re.MULTILINE)
         except:
             return (0, 0, -1, 0)
         match = None
         for match in rgx.finditer(contents, endpos=len(contents)-start):
             pass
         if match is None:
             return (0, 0, -1, 0)
         index = match.start()
         lines, columns = text.get_linecol_offset(contents[index:], forward=False)
         back = index - contents.rfind('\n', 0, index) - 1
         if back == -1: back = 0
         columns = back+1
         tabs = contents[contents.rfind('\n', 0, index):index].count('\t')
         columns += 7*tabs
         ol, oc = lines, columns
         l, c = self.cursor
         lines = l - lines
         length = match.end() - match.start()
         return lines, columns, index, length
コード例 #4
0
 def get_linecoloffset_of(self,
                          to_find,
                          contents=None,
                          start=0,
                          forward=True):
     if forward:
         contents = contents or self.get_contents_from_cursor()
         index = contents.find(to_find, start)
         lines, columns = text.get_linecol_offset(contents[:index])
         l, c = self.cursor
         columns = c + columns if lines == 0 else columns + 1
         lines = l + lines
         return lines, columns, index
     else:
         raise Exception('not implemented')