autoformat.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:sublimeTextConfig 作者: luoye-fe 项目源码 文件源码
def run(self, edit: sublime.Edit) -> None:
        if self.data is not None:
            self.replace(edit)
            return

        aggresive_level = get_settings(self.view, 'aggressive', 0)
        if aggresive_level > 0:
            if not sublime.ok_cancel_dialog(
                'You have an aggressive level of {} this may cause '
                'anaconda to change things that you don\'t really want to '
                'change.\n\nAre you sure do you want to continue?'.format(
                    aggresive_level
                )
            ):
                return

        self.code = self.view.substr(sublime.Region(0, self.view.size()))
        settings = {
            'aggressive': aggresive_level,
            'list-fixes': get_settings(self.view, 'list-fixes', False),
            'autoformat_ignore': get_settings(
                self.view, 'autoformat_ignore', []
            ),
            'autoformat_select': get_settings(
                self.view, 'autoformat_select', []
            ),
            'pep8_max_line_length': get_settings(
                self.view, 'pep8_max_line_length', 79
            )
        }
        try:
            messages = {
                'start': 'Autoformatting please wait... ',
                'end': 'Autoformatting done!',
                'fail': 'Autoformatting failed, buffer not changed.',
                'timeout': 'Autoformatting failed, buffer not changed.',
            }
            self.pbar = ProgressBar(messages)
            self.pbar.start()
            self.view.set_read_only(True)

            data = {
                'vid': self.view.id(),
                'code': self.code,
                'method': 'pep8',
                'settings': settings,
                'handler': 'autoformat'
            }
            timeout = get_settings(self.view, 'auto_formatting_timeout', 1)

            callback = Callback(timeout=timeout)
            callback.on(success=self.get_data)
            callback.on(error=self.on_failure)
            callback.on(timeout=self.on_failure)

            Worker().execute(callback, **data)
        except:
            logging.error(traceback.format_exc())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号