Skip to content

Miscellaneous bug fixes #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions pyqode/python/backend/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 \
Expand Down
6 changes: 6 additions & 0 deletions pyqode/python/modes/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 14 additions & 6 deletions pyqode/python/modes/autoindent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 += '\\'
Expand Down
2 changes: 1 addition & 1 deletion pyqode/python/modes/sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pyqode/python/widgets/code_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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):
Expand Down