<s> import sublime_plugin <EOL> import re <EOL> class TomdocCommand ( sublime_plugin . TextCommand ) : <EOL> def run ( self , edit ) : <EOL> point = self . view . sel ( ) [ <NUM_LIT:0> ] . end ( ) <EOL> line = self . read_line ( point + <NUM_LIT:1> ) <EOL> if not self . check_doc ( point ) : <EOL> return <EOL> doc = self . compose_doc ( line , edit ) <EOL> self . view . insert ( edit , point , doc ) <EOL> def check_doc ( self , point ) : <EOL> current_line = self . read_line ( point ) <EOL> params_match = re . search ( '<STR_LIT>' , current_line ) <EOL> if not params_match : <EOL> return True <EOL> return False <EOL> def initialize_doc ( self , params_match , current_line ) : <EOL> indent = self . get_indent ( current_line ) <EOL> lines = [ ] <EOL> lines . append ( indent + "<STR_LIT>" ) <EOL> lines . append ( indent + "<STR_LIT:#>" ) <EOL> params = [ p . strip ( ) for p in params_match . group ( <NUM_LIT:1> ) . split ( '<STR_LIT:U+002C>' ) if len ( p . strip ( ) ) > <NUM_LIT:0> ] <EOL> for param in params : <EOL> lines . append ( "<STR_LIT>" % ( indent , param ) ) <EOL> return "<STR_LIT:\r\n>" + "<STR_LIT:\r\n>" . join ( lines ) <EOL> def method_doc ( self , params_match , current_line ) : <EOL> params = [ p . strip ( ) for p in params_match . group ( <NUM_LIT:1> ) . split ( '<STR_LIT:U+002C>' ) if len ( p . strip ( ) ) > <NUM_LIT:0> ] <EOL> indent = self . get_indent ( current_line ) <EOL> lines = [ ] <EOL> lines . append ( indent + "<STR_LIT>" ) <EOL> lines . append ( indent + "<STR_LIT:#>" ) <EOL> for param in params : <EOL> lines . append ( "<STR_LIT>" % ( indent , param ) ) <EOL> if len ( params ) > <NUM_LIT:0> : <EOL> lines . append ( indent + "<STR_LIT:#>" ) <EOL> lines . append ( indent + "<STR_LIT>" ) <EOL> return "<STR_LIT:\r\n>" + "<STR_LIT:\r\n>" . join ( lines ) <EOL> def class_doc ( self , params_match , current_line ) : <EOL> indent = self . get_indent ( current_line ) <EOL> lines = [ ] <EOL> lines . append ( indent + "<STR_LIT>" ) <EOL> lines . append ( indent + "<STR_LIT>" ) <EOL> lines . append ( indent + "<STR_LIT:#>" ) <EOL> return "<STR_LIT:\r\n>" + "<STR_LIT:\r\n>" . join ( lines ) <EOL> def const_doc ( self , params_match , current_line ) : <EOL> indent = self . get_indent ( current_line ) <EOL> lines = [ ] <EOL> lines . append ( indent + "<STR_LIT>" ) <EOL> return "<STR_LIT:\r\n>" + "<STR_LIT:\r\n>" . join ( lines ) <EOL> def attributes_doc ( self , params_match , current_line ) : <EOL> indent = self . get_indent ( current_line ) <EOL> lines = [ ] <EOL> param = params_match . group ( <NUM_LIT:0> ) . strip ( ) <EOL> if param == '<STR_LIT>' : <EOL> lines . append ( indent + "<STR_LIT>" ) <EOL> elif param == '<STR_LIT>' : <EOL> lines . append ( indent + "<STR_LIT>" ) <EOL> elif param == '<STR_LIT>' : <EOL> lines . append ( indent + "<STR_LIT>" ) <EOL> return "<STR_LIT:\r\n>" + "<STR_LIT:\r\n>" . join ( lines ) <EOL> def compose_doc ( self , current_line , edit ) : <EOL> params_match = re . search ( '<STR_LIT>' , current_line ) <EOL> if params_match : <EOL> if re . search ( '<STR_LIT>' , current_line ) : <EOL> return self . initialize_doc ( params_match , current_line ) <EOL> else : <EOL> return self . method_doc ( params_match , current_line ) <EOL> params_match = re . search ( '<STR_LIT>' , current_line ) <EOL> if params_match : <EOL> return self . class_doc ( params_match , current_line ) <EOL> params_match = re . search ( '<STR_LIT>' , current_line ) <EOL> if params_match : <EOL> return self . const_doc ( params_match , current_line ) <EOL> params_match = re . search ( '<STR_LIT>' , current_line ) <EOL> if params_match : <EOL> return self . attributes_doc ( params_match , current_line ) <EOL> def get_indent ( self , line ) : <EOL> return re . search ( '<STR_LIT>' , line ) . group ( <NUM_LIT:0> ) <EOL> def read_line ( self , point ) : <EOL> if ( point >= self . view . size ( ) ) : <EOL> return <EOL> next_line = self . view . line ( point ) <EOL> return self . view . substr ( next_line ) </s>
