def indent_code(self, line, code, editor): """Indent the code properly according to the editor's preferences.""" # Automatically indent the string and replace \t (tab) with the # correct number of spaces. code = zen_core.pad_string(code, re.match(r"\s*", line).group()) if editor.get_active_view().get_insert_spaces_instead_of_tabs(): code = code.replace("\t", " " * editor.get_active_view().get_tab_width()) return code
def replace_content(self, value, start=None, end=None): """ Replace editor's content or it's part (from <code>start</code> to <code>end</code> index). If <code>value</code> contains <code>caret_placeholder</code>, the editor will put caret into this position. If you skip <code>start</code> and <code>end</code> arguments, the whole target's content will be replaced with <code>value</code>. If you pass <code>start</code> argument only, the <code>value</code> will be placed at <code>start</code> string index of current content. If you pass <code>start</code> and <code>end</code> arguments, the corresponding substring of current target's content will be replaced with <code>value</code> @param value: Content you want to paste @type value: str @param start: Start index of editor's content @type start: int @param end: End index of editor's content @type end: int """ if start is None and end is None: iter_start, iter_end = self.__buffer.get_bounds() elif end is None: iter_start = self.__buffer.get_iter_at_offset(start) iter_end = iter_start.copy() else: iter_start = self.__buffer.get_iter_at_offset(start) iter_end = self.__buffer.get_iter_at_offset(end) self.__buffer.begin_user_action() self.__buffer.delete(iter_start, iter_end) start_insertion_offset = self.__editor.cursor.get_offset() from zen_actions import get_current_line_padding padding = get_current_line_padding(self) from zen_core import pad_string self.__buffer.insert_at_cursor(pad_string(value, padding)) end_insertion_offset = self.__editor.cursor.get_offset() self.__buffer.end_user_action() self.__manager.emit("insertion-offsets", (start_insertion_offset, end_insertion_offset)) return
def replace_content(self, value, offset_start=None, offset_end=None): """ Replace editor's content or it's part (from <code>start</code> to <code>end</code> index). If <code>value</code> contains <code>caret_placeholder</code>, the editor will put caret into this position. If you skip <code>start</code> and <code>end</code> arguments, the whole target's content will be replaced with <code>value</code>. If you pass <code>start</code> argument only, the <code>value</code> will be placed at <code>start</code> string index of current content. If you pass <code>start</code> and <code>end</code> arguments, the corresponding substring of current target's content will be replaced with <code>value</code> @param value: Content you want to paste @type value: str @param start: Start index of editor's content @type start: int @param end: End index of editor's content @type end: int """ if offset_start is None and offset_end is None: iter_start = self.buffer.get_iter_at_offset(0) iter_end = self.get_end_iter() elif offset_end is None: iter_start = self.buffer.get_iter_at_offset(offset_start) iter_end = self.buffer.get_iter_at_offset(offset_start) else: iter_start = self.buffer.get_iter_at_offset(offset_start) iter_end = self.buffer.get_iter_at_offset(offset_end) self.buffer.delete(iter_start, iter_end) self.insertion_start = self.get_insert_offset() padding = zen_actions.get_current_line_padding(self) self.buffer.insert_at_cursor(zen_core.pad_string(value, padding)) self.insertion_end = self.get_insert_offset()
def replace_content(self, value, offset_start=None, offset_end=None): if offset_start is None and offset_end is None: iter_start = self.buffer.get_iter_at_offset(0) iter_end = self.get_end_iter() elif offset_end is None: iter_start = self.buffer.get_iter_at_offset(offset_start) iter_end = self.buffer.get_iter_at_offset(offset_start) else: iter_start = self.buffer.get_iter_at_offset(offset_start) iter_end = self.buffer.get_iter_at_offset(offset_end) self.buffer.delete(iter_start, iter_end) self.set_caret_pos(offset_start) self.insertion_start = self.get_insert_offset() padding = zen_actions.get_current_line_padding(self) padding = re.sub('[\r\n]', '', padding) self.buffer.insert_at_cursor(zen_core.pad_string(value, padding)) self.insertion_end = self.get_insert_offset()
def replace_content(self, value, offset_start=None, offset_end=None): """ Replace editor's content or its part (from start to end index). If value contains caret_placeholder, the editor will put caret into this position. If you skip start and end arguments, the whole target's content will be replaced with value. If you pass start argument only, the value will be placed at start string index of current content. If you pass start and end arguments, the corresponding substring of current target's content will be replaced with value @param value: Content you want to paste @type value: str @param start: Start index of editor's content @type start: int @param end: End index of editor's content @type end: int """ if offset_start is None and offset_end is None: iter_start = self.buffer.get_iter_at_offset(0) iter_end = self.get_end_iter() elif offset_end is None: iter_start = self.buffer.get_iter_at_offset(offset_start) iter_end = self.buffer.get_iter_at_offset(offset_start) else: iter_start = self.buffer.get_iter_at_offset(offset_start) iter_end = self.buffer.get_iter_at_offset(offset_end) self.buffer.delete(iter_start, iter_end) self.insertion_start = self.get_insert_offset() padding = zen_actions.get_current_line_padding(self) self.buffer.insert_at_cursor(zen_core.pad_string(value, padding)) self.insertion_end = self.get_insert_offset()