2015-02-24 33 views
0

third answer from this question,相關我想重構這個簡單的插件,以便它可以與Sublime Text 3一起使用。請幫助我嗎?我是python的新手,對於崇高的插件開發我一無所知。觸發在崇高文本上追加需求的白色空間3

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()。我不想安裝插件只是爲了按需觸發尾隨空白。非常感謝,最誠摯的問候。

+1

Sublime有這個內置的,你可以在設置中設置''trim_trailing_white_space_on_save「:true,'。 – Kos 2015-02-24 14:56:55

+0

是的,我知道,但是我在一個團隊中工作的人不會裁剪拖尾的空白區域,所以我只想刪除我自己文件中的空白區域。從快捷方式觸發是完美的。 – 2015-02-24 14:59:53

+3

如果你的項目沒有這個約定,我建議強制執行它,讓每個人都設置他們的編輯器,或者只是忘記它,而不是混淆了「你自己的文件」中無關空格變化的差異。一致性在此獲勝。 – Kos 2015-02-24 15:06:27

回答

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") 
1

在Sublime Text 3中,您只需映射本機修剪功能的快捷鍵即可。只需添加

{ "keys": ["ctrl+alt+t"], "command": "trim_trailing_white_space" } 

要鍵綁定下PreferencesKey Bindings - User。然後可以通過按ctrl + alt + t執行。