diff --git a/pyqode/python/backend/workers.py b/pyqode/python/backend/workers.py index e7e1aaa6..671cadfd 100644 --- a/pyqode/python/backend/workers.py +++ b/pyqode/python/backend/workers.py @@ -204,6 +204,7 @@ def run_pyflakes(request_data): code = request_data['code'] path = request_data['path'] encoding = request_data['encoding'] + ignore_rules = request_data['ignore_rules'] if not encoding: encoding = 'utf-8' if not path: @@ -232,6 +233,8 @@ def run_pyflakes(request_data): w = checker.Checker(tree, os.path.split(path)[1]) w.messages.sort(key=lambda m: m.lineno) for message in w.messages: + if any(message.message.startswith(ir) for ir in ignore_rules): + continue msg = "[pyFlakes] %s" % str(message).split(':')[-1].strip() line = message.lineno - 1 status = WARNING \ diff --git a/pyqode/python/modes/autocomplete.py b/pyqode/python/modes/autocomplete.py index af5b000e..899cc147 100644 --- a/pyqode/python/modes/autocomplete.py +++ b/pyqode/python/modes/autocomplete.py @@ -13,6 +13,12 @@ class PyAutoCompleteMode(AutoCompleteMode): - function completion adds "):" to the function definition. - method completion adds "self):" to the method definition. """ + + def __init__(self): + + super(PyAutoCompleteMode, self).__init__() + self.AVOID_DUPLICATES = ')', ']', '}', ':' + def _in_method_call(self): helper = TextHelper(self.editor) line_nbr = helper.current_line_nbr() - 1 diff --git a/pyqode/python/modes/autoindent.py b/pyqode/python/modes/autoindent.py index 69582b1c..52fb1044 100644 --- a/pyqode/python/modes/autoindent.py +++ b/pyqode/python/modes/autoindent.py @@ -46,8 +46,11 @@ def _get_indent(self, cursor): else: lastword = self._get_last_word(cursor) lastwordu = self._get_last_word_unstripped(cursor) + # A * can als be a wildcard import, so we make an exception for + # those end_with_op = fullline.endswith( - ('+', '-', '*', '/', '=', ' and', ' or', '%')) + ('+', '-', '*', '/', '=', ' and', ' or', '%') + ) and not fullline.endswith('import *') in_string_def, char = self._is_in_string_def(fullline, column) if in_string_def: post, pre = self._handle_indent_inside_string( @@ -169,6 +172,8 @@ def _get_indent_of_opening_paren(self, tc): else: ol, oc = self.editor.modes.get(SymbolMatcherMode).symbol_pos( tc, character, char_type) + if ol is None: + return 0 line = self._helper.line_text(ol) return len(line) - len(line.lstrip()) @@ -222,7 +227,6 @@ def _get_paren_pos(self, tc, column): mapping = {'(': PAREN, '[': SQUARE, '{': BRACE} tc2 = QTextCursor(tc) tc2.setPosition(pos) - import sys ol, oc = self.editor.modes.get(SymbolMatcherMode).symbol_pos( tc2, OPEN, mapping[char]) cl, cc = self.editor.modes.get(SymbolMatcherMode).symbol_pos( @@ -264,8 +268,12 @@ def _handle_indent_between_paren(self, column, line, parent_impl, tc): elif next_close and prev_char != ',': post = open_line_indent * self._indent_char elif tc.block().blockNumber() == open_line: - post = open_symbol_col * self._indent_char - + if self._indent_char == '\t': + # When using tab indents, we indent by one level + post = (open_line_indent + 1) * self._indent_char + else: + # When using space indents, we indent to the opening paren + post = open_symbol_col * self._indent_char # adapt indent if cursor on closing line and next line have same # indent -> PEP8 compliance if close_line and close_col: @@ -361,8 +369,8 @@ def _handle_indent_after_paren(self, cursor, post): return post def _handle_indent_in_statement(self, fullline, lastword, post, pre): - if lastword[-1] != ':': - if lastword and lastword[-1] != " ": + if lastword and lastword[-1] != ':': + if lastword[-1] != " ": pre += " \\" else: pre += '\\' diff --git a/pyqode/python/modes/sh.py b/pyqode/python/modes/sh.py index 39fc5fb6..0996ecd6 100644 --- a/pyqode/python/modes/sh.py +++ b/pyqode/python/modes/sh.py @@ -173,7 +173,7 @@ def highlight_block(self, text, block): self.setFormat(start, end - start, self.formats["string"]) state = self.INSIDE_DQSTRING - elif key == 'builtin_fct': + elif key in ('builtin', 'builtin_fct'): # trick to highlight __init__, __add__ and so on with # builtin color self.setFormat(start, end - start, diff --git a/pyqode/python/widgets/code_edit.py b/pyqode/python/widgets/code_edit.py index aa4edb6e..cd9c95d9 100644 --- a/pyqode/python/widgets/code_edit.py +++ b/pyqode/python/widgets/code_edit.py @@ -31,7 +31,7 @@ def __init__(self, parent=None, create_default_actions=True): super(PyCodeEditBase, self).__init__(parent, create_default_actions) self.file = pymanagers.PyFileManager(self) - def setPlainText(self, txt, mimetype='text/x-python', encoding='utf-8'): + def setPlainText(self, txt, mime_type='text/x-python', encoding='utf-8'): """ Extends QCodeEdit.setPlainText to allow user to setPlainText without mimetype (since the python syntax highlighter does not use it). @@ -41,7 +41,7 @@ def setPlainText(self, txt, mimetype='text/x-python', encoding='utf-8'): self.syntax_highlighter.import_statements[:] = [] except AttributeError: pass - super(PyCodeEditBase, self).setPlainText(txt, mimetype, encoding) + super(PyCodeEditBase, self).setPlainText(txt, mime_type, encoding) class PyCodeEdit(PyCodeEditBase):