コード例 #1
0
ファイル: js_lint.py プロジェクト: dividedmind/kate
def get_linter(linter_name, callback):
    """tries to retrieve a linter and calls `callback` on it on success"""
    if linter_name in LINTERS:
        callback(LINTERS[linter_name])
        return

    if linter_name not in NEEDS_LICENSE:
        showError(i18nc('@info:status', 'No acceptable linter named %1!', linter_name))
        return

    license, objname, url = NEEDS_LICENSE[linter_name]
    cache_path = p.join(CACHE_DIR, linter_name + '.js')

    def success():
        """store newly created linter and “return” it"""
        LINTERS[linter_name] = JSModule(JS_ENGINE, cache_path, objname)
        callback(LINTERS[linter_name])

    if p.exists(cache_path):
        success()
        return

    # the user doesn’t have the file. ask to accept its license
    if not license_accepted(license):
        return

    download = KIO.file_copy(KUrl(url), KUrl.fromPath(cache_path))
    @download.result.connect
    def _call(job):
        if job.error():
            showError(i18nc('@info:status', 'Download failed'))
        else:
            success()
    download.start()
コード例 #2
0
ファイル: all_checker.py プロジェクト: dividedmind/kate
def checkAll(doc=None, excludes=None, exclude_all=False):
    """Check the syntax, pep8 and pyflakes errors of the document"""
    python_utils_conf = kate.configuration.root.get('python_utils', {})
    if not (not doc or (is_mymetype_python(doc) and
                        not doc.isModified())):
        return
    is_called = not bool(doc)
    from python_checkers.parse_checker import parseCode
    excludes = excludes or []
    currentDoc = doc or kate.activeDocument()
    mark_iface = currentDoc.markInterface()
    clearMarksOfError(currentDoc, mark_iface)
    if not exclude_all:
        if not 'parseCode' in excludes and (is_called or python_utils_conf.get(_PARSECODE_CHECK_WHEN_SAVE, DEFAULT_PARSECODE_CHECK_WHEN_SAVE)):
            parseCode.f(currentDoc, refresh=False)
        if not 'checkPyflakes' in excludes and (is_called or python_utils_conf.get(_PYFLAKES_CHECK_WHEN_SAVE, DEFAULT_CHECK_PYFLAKES_WHEN_SAVE)):
            try:
                from python_checkers.pyflakes_checker import checkPyflakes
                checkPyflakes.f(currentDoc, refresh=False)
            except ImportError:
                pass
        if not 'checkPep8' in excludes and (is_called or python_utils_conf.get(_PEP8_CHECK_WHEN_SAVE, DEFAULT_CHECK_PEP8_WHEN_SAVE)):
            from python_checkers.pep8_checker import checkPep8
            checkPep8.f(currentDoc, refresh=False)
    if not doc and currentDoc.isModified() and not excludes:
        showError(i18n('You must save the file first'))
コード例 #3
0
ファイル: xml_pretty.py プロジェクト: hlamer/kate
def prettyXMLFormat():
    """Pretty format of a XML code"""
    # TODO Use decorators to apply constraints
    document = kate.activeDocument()
    view = document.activeView()
    try:
        encoding = 'utf-8'
        source = view.selectionText()
        m = encoding_pattern.match(source)
        if m:
            encoding = m.groups()[0]
        target = minidom.parseString(source.encode(encoding))
        unicode_escape = codecs.getdecoder('unicode_escape')
        indent = unicode_escape(
            kate.configuration.get(_INDENT_CFG, DEFAULT_INDENT))[0]
        newl = unicode_escape(kate.configuration.get(_NEWL_CFG,
                                                     DEFAULT_NEWL))[0]
        xml_pretty = target.toprettyxml(
            indent=indent, newl=newl, encoding=encoding).decode(encoding)
        xml_pretty = newl.join([
            line for line in xml_pretty.split(newl)
            if line.replace(' ', '').replace(indent, '')
        ])
        document.replaceText(view.selectionRange(), xml_pretty)
    except (ExpatError, LookupError) as e:
        showError(
            i18nc('@info:tooltip', 'The selected text is not valid XML: %1',
                  str(e)))
コード例 #4
0
ファイル: kate_reload.py プロジェクト: LarsBV/kate_reload
  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'))
コード例 #5
0
ファイル: kate_reload.py プロジェクト: emdeeeks/kate_reload
    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'))
コード例 #6
0
ファイル: python_autocomplete.py プロジェクト: hlamer/kate
 def treatmentException(self, e):
     if self.invocationType == KTextEditor.CodeCompletionModel.AutomaticInvocation:
         return
     f = e.filename or ""
     text = e.text
     line = e.lineno
     message = i18n("There was a syntax error in this file:")
     if f:
         message = i18nc("%1 is error message", "%1\n  * file: %2", message, f)
     if text:
         message = i18nc("%1 is error message", "%1\n  * text: %2", message, text)
     if line:
         message = i18nc("%1 is error message", "%1\n  * line: %2", message, line)
     showError(message)
コード例 #7
0
ファイル: pep8_checker.py プロジェクト: dividedmind/kate
def saveFirst():
    showError(i18n('You must save the file first'))
コード例 #8
0
ファイル: js_lint.py プロジェクト: dividedmind/kate
 def _call(job):
     if job.error():
         showError(i18nc('@info:status', 'Download failed'))
     else:
         success()