示例#1
0
    def reindent(self, updateModulePage=True):
        from ExternalLib import reindent
        self.refreshFromViews()
        eol = Utils.getEOLMode(self.data)
        file = SourcePseudoFile(self.getDataAsLines())
        ri = reindent.Reindenter(file, eol=eol)
        try:
            if ri.run():
                file.output = []
                ri.write(file)

                newData = ''.join(file.output)
                modified = self.data != newData
                self.modified = self.modified or modified

                if modified:
                    self.data = newData
                    if updateModulePage:
                        self.editor.updateModulePage(self)
                    self.update()
                    self.notify()

                    self.editor.statusBar.setHint(
                        _('Code reformatted (indents and or EOL characters fixed)'
                          ))
                    return True
        except Exception, error:
            self.editor.statusBar.setHint(
                _('Reindent failed - %s : %s') % (error.__class__, str(error)),
                'Error')
示例#2
0
    def reindentSource(self, srcLines, filename):
        data = ''.join(srcLines)
        eol = Utils.getEOLMode(data)
        file = SourcePseudoFile(srcLines)
        ri = reindent.Reindenter(file, eol=eol)
        try:
            if ri.run():
                file.output = []
                ri.write(file)

                return ''.join(file.output)
        except Exception, error:
            print 'Error on reindenting %s : %s' % (filename, str(error))