def checkPyflakes(currentDocument=None, refresh=True): """Check the pyflakes errors of the document""" if not canCheckDocument(currentDocument): return if refresh: checkAll.f(currentDocument, ['checkPyflakes'], exclude_all=not currentDocument) move_cursor = not currentDocument currentDocument = currentDocument or kate.activeDocument() path = unicode(currentDocument.url().path()) mark_key = '%s-pyflakes' % path text = unicode(currentDocument.text()) errors = pyflakes(text.encode('utf-8', 'ignore'), path) errors_to_show = [] if len(errors) == 0: showOk("Pyflakes Ok") return # Prepare errors found for painting for error in errors: errors_to_show.append({ "message": error.message % error.message_args, "line": error.lineno, }) showErrors('Pyflakes Errors:', errors_to_show, mark_key, currentDocument, move_cursor=move_cursor)
def checkPyflakes(currentDocument=None, refresh=True): """Check the pyflakes errors of the document""" if not canCheckDocument(currentDocument): return if refresh: checkAll.f(currentDocument, ['checkPyflakes'], exclude_all=not currentDocument) move_cursor = not currentDocument currentDocument = currentDocument or kate.activeDocument() path = currentDocument.url().path() mark_key = '%s-pyflakes' % path text = currentDocument.text() errors = pyflakes(text, path) errors_to_show = [] if len(errors) == 0: showOk(i18n("Pyflakes Ok")) return # Prepare errors found for painting for error in errors: error_to_show = { "message": error.message % error.message_args, "line": error.lineno, } if getattr(error, 'col', None) is not None: error_to_show['column'] = error.col + 1 errors_to_show.append(error_to_show) showErrors(i18n('Pyflakes Errors:'), errors_to_show, mark_key, currentDocument, move_cursor=move_cursor)
def _lint(document, move_cursor, linter_name, linter): """extracted part of lint_js that has to be called after the linter is ready""" ok = linter(document.text(), {}) if ok: showOk(i18nc('@info:status', '<application>%1</application> OK', linter_name)) return errors = [error for error in linter['errors'] if error] # sometimes None # Prepare errors found for painting for error in errors: error['message'] = error.pop('reason') # rename since showErrors has 'message' hardcoded error.pop('raw', None) # Only reason, line, and character are always there error.pop('a', None) error.pop('b', None) error.pop('c', None) error.pop('d', None) mark_key = '{}-{}'.format(document.url().path(), linter_name) showErrors(i18nc('@info:status', '<application>%1</application> Errors:', linter_name), errors, mark_key, document, key_column='character', move_cursor=move_cursor)
def checkJslint(currentDocument=None): """Check your js code with the jslint tool""" if not (not currentDocument or (is_mymetype_js(currentDocument) and not currentDocument.isModified())): return move_cursor = not currentDocument currentDocument = currentDocument or kate.activeDocument() mark_iface = currentDocument.markInterface() clearMarksOfError(currentDocument, mark_iface) hideOldPopUps() path = unicode(currentDocument.url().path()) mark_key = '%s-jslint' % path text = unicode(currentDocument.text()) errors = check_JSLint(text.encode('utf-8', 'ignore')) errors_to_show = [] # Prepare errors found for painting for error in errors: matches = pattern.search(error) if matches: errors_to_show.append({ "message": matches.groups()[2], "line": int(matches.groups()[0]), "column": int(matches.groups()[1]) + 1, }) if len(errors_to_show) == 0: showOk("JSLint Ok") return showErrors('JSLint Errors:', errors_to_show, mark_key, currentDocument, move_cursor=move_cursor)
def disable(self, doc): if doc.property('AutoReload'): doc.setModifiedOnDiskWarning(True) doc.modifiedOnDisk.disconnect(doc.documentReload) doc.setProperty('AutoReload', False) showOk(i18n('Auto-Reload disabled')) else: print('Error disabled called on something with no auto-reload')
def checkPep8(currentDocument=None, refresh=True): """Check the pep8 errors of the document""" if not canCheckDocument(currentDocument): return if refresh: checkAll.f(currentDocument, ['checkPep8'], exclude_all=not currentDocument) move_cursor = not currentDocument currentDocument = currentDocument or kate.activeDocument() if currentDocument.isModified(): saveFirst() return path = currentDocument.url().path() if not path: saveFirst() return mark_key = '%s-pep8' % currentDocument.url().path() # Check the file for errors with PEP8 sys.argv = [path] pep8.process_options([path]) python_utils_conf = kate.configuration.root.get('python_utils', {}) ignore_pep8_errors = python_utils_conf.get(_IGNORE_PEP8_ERRORS, DEFAULT_IGNORE_PEP8_ERRORS) if ignore_pep8_errors: ignore_pep8_errors = ignore_pep8_errors.split(",") else: ignore_pep8_errors = [] if pep8.__version__ in OLD_PEP8_VERSIONS: checker = StoreErrorsChecker(path) pep8.options.ignore = ignore_pep8_errors checker.check_all() errors = checker.get_errors() else: checker = pep8.Checker(path, reporter=KateReport, ignore=ignore_pep8_errors) checker.check_all() errors = checker.report.get_errors() if len(errors) == 0: showOk(i18n('Pep8 Ok')) return errors_to_show = [] # Paint errors found for error in errors: errors_to_show.append({ "line": error[0], "column": error[1] + 1, "message": error[3], }) showErrors(i18n('Pep8 Errors:'), errors_to_show, mark_key, currentDocument, move_cursor=move_cursor)
def enable(self, doc): if doc.url() == '': self.act.blockSignals(True) showError(i18n('Can\'t auto-reload unsaved file')) self.act.setChecked(False) self.act.blockSignals(False) return doc.setModifiedOnDiskWarning(False) doc.modifiedOnDisk.connect(doc.documentReload) doc.setProperty('AutoReload', True) showOk(i18n('Auto-Reload enabled'))
def checkPep8(currentDocument=None, refresh=True): """Check the pep8 errors of the document""" if not canCheckDocument(currentDocument): return if refresh: checkAll.f(currentDocument, ['checkPep8'], exclude_all=not currentDocument) move_cursor = not currentDocument currentDocument = currentDocument or kate.activeDocument() if currentDocument.isModified(): saveFirst() return path = unicode(currentDocument.url().path()) if not path: saveFirst() return mark_key = '%s-pep8' % unicode(currentDocument.url().path()) # Check the file for errors with PEP8 sys.argv = [path] pep8.process_options([path]) if pep8.__version__ in OLD_PEP8_VERSIONS: checker = StoreErrorsChecker(path) pep8.options.ignore = IGNORE_PEP8_ERRORS checker.check_all() errors = checker.get_errors() else: checker = pep8.Checker(path, reporter=KateReport, ignore=IGNORE_PEP8_ERRORS) checker.check_all() errors = checker.report.get_errors() if len(errors) == 0: showOk('Pep8 Ok') return errors_to_show = [] # Paint errors found for error in errors: errors_to_show.append({ "line": error[0], "column": error[1] + 1, "message": error[3], }) showErrors('Pep8 Errors:', errors_to_show, mark_key, currentDocument, move_cursor=move_cursor)
def __init__(self): QObject.__init__(self) self.window = kate.mainInterfaceWindow().window() self.addAction('open_selection_info', None, 'Selection info', 'Ctrl+Alt+I', self.selection_info, 'Tools') showOk('Selection inits!') self.dia = QDialog(None, Qt.CustomizeWindowHint | Qt.WindowStaysOnTopHint) self.dia.setStyleSheet('QDialog { border: 1px solid black; }') layout = QFormLayout(self.dia) layout.setSpacing(5) ok = QPushButton('Close') ok.clicked.connect(self.dia.hide) self.chars = QLabel() self.lines = QLabel() self.spaces = QLabel() self.word_count = QLabel() self.chars_no_space = QLabel() self.occurences = QLabel() self.chars .setTextInteractionFlags(Qt.TextSelectableByMouse) self.lines .setTextInteractionFlags(Qt.TextSelectableByMouse) self.spaces .setTextInteractionFlags(Qt.TextSelectableByMouse) self.word_count .setTextInteractionFlags(Qt.TextSelectableByMouse) self.chars_no_space .setTextInteractionFlags(Qt.TextSelectableByMouse) self.occurences .setTextInteractionFlags(Qt.TextSelectableByMouse) self.search = QLineEdit() self.search.textChanged.connect(self.updateInfo) self.search.setPlaceholderText('Regex') layout.addRow('Characters w. spaces:', self.chars) layout.addRow('Newlines:', self.lines) layout.addRow('Word Count:', self.word_count) layout.addRow('Characters:', self.chars_no_space) layout.addRow('Spaces:', self.spaces) layout.addRow( self.search, self.occurences) layout.addRow( ok )
def parseCode(doc=None, refresh=True): """Check the syntax errors of the document""" if not canCheckDocument(doc): return if refresh: checkAll.f(doc, ['parseCode'], exclude_all=not doc) move_cursor = not doc doc = doc or kate.activeDocument() text = doc.text() text = text.encode('utf-8', 'ignore') mark_key = '%s-parse-python' % doc.url().path() try: parse(text) showOk(i18n('Parse code Ok')) except SyntaxError as e: error = {} error['text'] = e.text error['line'] = e.lineno showErrors(i18n('Parse code Errors:'), [error], mark_key, doc, move_cursor=move_cursor)
def parseCode(doc=None, refresh=True): """Check the syntax errors of the document""" if not canCheckDocument(doc): return if refresh: checkAll.f(doc, ['parseCode'], exclude_all=not doc) move_cursor = not doc doc = doc or kate.activeDocument() text = unicode(doc.text()) text = text.encode('utf-8', 'ignore') mark_key = '%s-parse-python' % unicode(doc.url().path()) try: compiler.parse(text) showOk('Parse code Ok') except SyntaxError, e: error = {} error['text'] = e.text error['line'] = e.lineno showErrors('Parse code Errors:', [error], mark_key, doc, move_cursor=move_cursor)
def __init__(self): QObject.__init__(self) self.window = kate.mainInterfaceWindow().window() showOk('MyPlugin inits!')