gpt4 book ai didi

python - 用于删除引号的 sublime text 3 插件

转载 作者:行者123 更新时间:2023-11-28 21:20:07 25 4
gpt4 key购买 nike

我正在尝试转换 this plugin从 Sublime Text 2 到 Sublime Text 3,但我一直遇到这个错误

  File "/Users/macintoshhd/Library/Application Support/Sublime Text 3/Packages/magiclessquotesjon.py", line 17, in on_pre_save
edit = view.begin_edit()
TypeError: begin_edit() missing 2 required positional arguments: 'edit_token' and 'cmd'

我知道 API 在版本之间发生了变化,并且有一个 porting guide ,但我仍然不确定如何获得正确的 TextCommand 或如何使用它。

插件代码在这里:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = "Daryl Tucker"

import sublime, sublime_plugin

class RemoveMagicFromMagic(sublime_plugin.EventListener):
def on_pre_save(self, view):
replacements = [
[u'[’‘`]{1}',u'\''],
[u'[“”]{1}',u'"'],
[u'[…]{1}',u'...'],
[u'[—]{1}',u'---'],
[u'[–]{1}',u'--'],
[u'[•]{1}',u'*'],
[u' & ',u' & '],
]
edit = view.begin_edit()
for replacement in replacements:
x = view.find_all(replacement[0])
for position in x:
view.replace(edit, position, replacement[1])
view.end_edit(edit)

最佳答案

能够通过额外的回调让它工作..

class RemoveSmartQuotesCommand(sublime_plugin.TextCommand):
def run(self, edit, user_input=None):
self.edit = edit
replacements = [
[u'[’‘`]{1}',u'\''],
[u'[“”]{1}',u'"'],
[u'[…]{1}',u'...'],
[u'[—]{1}',u'---'],
[u'[–]{1}',u'--'],
[u'[•]{1}',u'*'],
[u' & ',u' & '],
]
for replacement in replacements:
x = self.view.find_all(replacement[0])
for position in x:
self.view.replace(edit, position, replacement[1])

class RemoveSmartQuotesWhenSaving(sublime_plugin.EventListener):
def on_pre_save(self, view):
view.run_command('remove_smart_quotes')

关于python - 用于删除引号的 sublime text 3 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23355542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com