与third answer from this question,相关我想重构这个简单的插件,以便它适用于Sublime Text 3.请你能帮助我吗?我是python的新手,我对sublime的插件开发一无所知。
import sublime, sublime_plugin
def trim_trailing_white_space2(view):
trailing_white_space2 = view.find_all("[\t ]+$")
trailing_white_space2.reverse()
edit = view.begin_edit()
for r in trailing_white_space2:
view.erase(edit, r)
view.end_edit(edit)
class TrimTrailingWhiteSpace2Command(sublime_plugin.TextCommand):
def run(self, edit):
trim_trailing_white_space2(self.view)
我已搜索过,问题是begin_edit()
和end_edit()
。我不想安装插件只是为了按需触发尾随空白区域。非常感谢,最诚挚的问候。
答案 0 :(得分:1)
在Sublime Text 3中,您只需映射原生修剪功能的快捷方式。只需添加
{ "keys": ["ctrl+alt+t"], "command": "trim_trailing_white_space" }
到Preferences
→Key Bindings - User
下的键绑定。然后可以按 ctrl + alt + t 执行。
答案 1 :(得分:0)
使用ST3。
import sublime, sublime_plugin
class TrimTrailingWhiteSpace2Command(sublime_plugin.TextCommand):
def run(self, edit):
trailing_white_space = self.view.find_all("[\t ]+$")
trailing_white_space.reverse()
for r in trailing_white_space:
self.view.erase(edit, r)
class TrimTrailingWhiteSpace2(sublime_plugin.EventListener):
def run(self, view):
view.run_command("trim_trailing_white_space2")