2013-11-24 6 views
12


Sto cercando di creare un plugin per il testo sublime 3.
Per ora ho solo possibile selezionare tutto il testo in una finestra e copiarlo in un'altra finestra.
Codice:Sublime Text 3 API: ottenere tutti i testo da un file

import sublime, sublime_plugin 

class PrintCodeCommand(sublime_plugin.WindowCommand): 
    def run(self): 
     # for each caracter, add it to a string with the substr method 
     s = "" 
     for x in range(0,self.window.active_view().size()): 
      s += self.window.active_view().substr(x) 
     newFile = self.window.new_file() 
     newFile.run_command("test",{"textBuffer": s}) 

class Test(sublime_plugin.TextCommand): 
    def run(self, edit, textBuffer): 
     self.view.insert(edit, 0, textBuffer) 

Sai una migliore/metodo più semplice per farlo?
Grazie!

risposta

20

È possibile ottenere il contenuto del documento corrente con:

contents = self.view.substr(sublime.Region(0, self.view.size()))