From b39b8a8b908ea69d3cd41fa326a1d97495af6bcf Mon Sep 17 00:00:00 2001 From: Sebastiaan Mathot Date: Fri, 13 Sep 2019 13:23:27 +0200 Subject: [PATCH 1/9] PyAutoIndent: remove extraneous import --- pyqode/python/modes/autoindent.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyqode/python/modes/autoindent.py b/pyqode/python/modes/autoindent.py index 69582b1c..dc0c4aa6 100644 --- a/pyqode/python/modes/autoindent.py +++ b/pyqode/python/modes/autoindent.py @@ -222,7 +222,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( From b55e2fc4790a2f74bdcd2e192c31cd28b500a151 Mon Sep 17 00:00:00 2001 From: Sebastiaan Mathot Date: Fri, 13 Sep 2019 13:22:39 +0200 Subject: [PATCH 2/9] PyCodeEditBase: fix setPlainText() - mimetype should be mime_type --- pyqode/python/widgets/code_edit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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): From 2e301990b80b421d25a18af546dd9fb6e35a5b35 Mon Sep 17 00:00:00 2001 From: Sebastiaan Mathot Date: Fri, 16 Aug 2019 19:28:40 +0200 Subject: [PATCH 3/9] AutoIndentMode: Fix a crash when (in rare cases) symbols cannot be matched --- pyqode/python/modes/autoindent.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyqode/python/modes/autoindent.py b/pyqode/python/modes/autoindent.py index dc0c4aa6..cf275fcd 100644 --- a/pyqode/python/modes/autoindent.py +++ b/pyqode/python/modes/autoindent.py @@ -169,6 +169,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()) From 4316836098686962767d216052e5ad43dca2ee64 Mon Sep 17 00:00:00 2001 From: Sebastiaan Mathot Date: Sat, 9 Nov 2019 16:17:23 +0100 Subject: [PATCH 4/9] PyFlakesChecker now respects ignore rules --- pyqode/python/backend/workers.py | 3 +++ 1 file changed, 3 insertions(+) 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 \ From 47bce798ec9b4d6b4520d1ca996b4304e4e3f6c8 Mon Sep 17 00:00:00 2001 From: Sebastiaan Mathot Date: Sat, 16 Nov 2019 10:18:29 +0100 Subject: [PATCH 5/9] Fix autoindent when the last word is an empty string --- pyqode/python/modes/autoindent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyqode/python/modes/autoindent.py b/pyqode/python/modes/autoindent.py index cf275fcd..843a18fc 100644 --- a/pyqode/python/modes/autoindent.py +++ b/pyqode/python/modes/autoindent.py @@ -362,8 +362,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 += '\\' From ddb4e552debe288f95557b8021b31e4cecbf7a6c Mon Sep 17 00:00:00 2001 From: Sebastiaan Mathot Date: Sun, 24 Nov 2019 17:55:09 +0100 Subject: [PATCH 6/9] PythonSH: fix misspelling of builtins key - Fixes no highlighting for builtins --- pyqode/python/modes/sh.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyqode/python/modes/sh.py b/pyqode/python/modes/sh.py index 39fc5fb6..f42fd184 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 == 'builtin': # trick to highlight __init__, __add__ and so on with # builtin color self.setFormat(start, end - start, From bc4f422f5497041b25c978487695fe39cd93844f Mon Sep 17 00:00:00 2001 From: Sebastiaan Mathot Date: Sun, 24 Nov 2019 18:02:38 +0100 Subject: [PATCH 7/9] PyAutoIndentMode: recognize wildcard import --- pyqode/python/modes/autoindent.py | 5 ++++- pyqode/python/modes/sh.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pyqode/python/modes/autoindent.py b/pyqode/python/modes/autoindent.py index 843a18fc..2a814fbc 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( diff --git a/pyqode/python/modes/sh.py b/pyqode/python/modes/sh.py index f42fd184..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': + elif key in ('builtin', 'builtin_fct'): # trick to highlight __init__, __add__ and so on with # builtin color self.setFormat(start, end - start, From e29fa94bcec8794f12a0217929a46f4c680163b8 Mon Sep 17 00:00:00 2001 From: Sebastiaan Mathot Date: Sun, 24 Nov 2019 18:16:02 +0100 Subject: [PATCH 8/9] PyAutoIndentMode: fix indentation for tabs within parentheses --- pyqode/python/modes/autoindent.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pyqode/python/modes/autoindent.py b/pyqode/python/modes/autoindent.py index 2a814fbc..52fb1044 100644 --- a/pyqode/python/modes/autoindent.py +++ b/pyqode/python/modes/autoindent.py @@ -268,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: From 55a6e44aa99c22d02a73c21d5c1a3b122cf9f92d Mon Sep 17 00:00:00 2001 From: Sebastiaan Mathot Date: Sun, 24 Nov 2019 20:04:53 +0100 Subject: [PATCH 9/9] PyAutoCompleteMode: don't duplicate : characters - Less annoying function defs --- pyqode/python/modes/autocomplete.py | 6 ++++++ 1 file changed, 6 insertions(+) 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