def find_in_file(self, pattern, col, end): Editor.find_pattern = pattern if Editor.case != "y": pattern = pattern.lower() try: rex = re_compile(pattern) except: self.message = "Invalid pattern: " + pattern return None start = self.cur_line if (col > len(self.content[start]) or (pattern[0] == '^' and col != 0)): start, col = start + 1, 0 for line in range(start, end): l = self.content[line][col:] if Editor.case != "y": l = l.lower() match = rex.search(l) if match: self.cur_line = line if pattern[-1:] == "$" and match.group(0)[-1:] != "$": self.col = col + len(l) - len(match.group(0)) else: self.col = col + l.find(match.group(0)) return len(match.group(0)) col = 0 else: self.message = pattern + " not found (again)" return None
def find_in_file(self, pattern, col, end): Editor.find_pattern = pattern ## remember it if Editor.case != "y": pattern = pattern.lower() try: rex = re_compile(pattern) except: self.message = "Invalid pattern: " + pattern return None start = self.cur_line if (col > len(self.content[start]) or # After EOL (pattern[0] == '^' and col != 0)): # or anchored and not at BOL start, col = start + 1, 0 # Skip to the next line for line in range(start, end): l = self.content[line][col:] if Editor.case != "y": l = l.lower() match = rex.search(l) if match: # Bingo self.cur_line = line ## Instead of match.span, a simple find has to be performed to get the cursor position. ## And '$' has to be treated separately, so look for a true EOL match first if pattern[-1:] == "$" and match.group(0)[-1:] != "$": self.col = col + len(l) - len(match.group(0)) else: self.col = col + l.find(match.group(0)) return len(match.group(0)) col = 0 else: self.message = pattern + " not found (again)" return None
def find_in_file(self, pattern, col, end): if is_micropython: from ure import compile as re_compile else: from re import compile as re_compile Editor.find_pattern = pattern if Editor.case != "y": pattern = pattern.lower() try: rex = re_compile(pattern) except: self.message = "Invalid pattern: " + pattern return None start = self.cur_line if (col > len(self.content[start]) or (pattern[0] == '^' and col != 0)): start, col = start + 1, 0 for line in range(start, end): l = self.content[line][col:] if Editor.case != "y": l = l.lower() match = rex.search(l) if match: self.cur_line = line if pattern[-1:] == "$" and match.group(0)[-1:] != "$": self.col = col + len(l) - len(match.group(0)) else: self.col = col + l.find(match.group(0)) return len(match.group(0)) col = 0 else: self.message = pattern + " not found (again)" return None