<s> """<STR_LIT>""" <EOL> import sublime <EOL> import sublime_plugin <EOL> import os <EOL> import json <EOL> def abbrevs_path ( ) : <EOL> path = os . path . join ( sublime . packages_path ( ) , <EOL> '<STR_LIT>' ) <EOL> return os . path . normpath ( path ) <EOL> def load_abbrevs ( ) : <EOL> path = abbrevs_path ( ) <EOL> decoded_json = None <EOL> if os . path . exists ( path ) : <EOL> with open ( path , '<STR_LIT:r>' ) as f : <EOL> decoded_json = json . load ( f ) <EOL> return decoded_json or { '<STR_LIT>' : [ ] } <EOL> def save_abbrevs ( data ) : <EOL> path = abbrevs_path ( ) <EOL> with open ( path , '<STR_LIT:w>' ) as f : <EOL> json . dump ( data , f ) <EOL> class Store ( object ) : <EOL> """<STR_LIT>""" <EOL> def set ( self , short , full ) : <EOL> abbrevs = load_abbrevs ( ) <EOL> idx = self . contains ( abbrevs , short ) <EOL> if idx is not None : <EOL> abbrevs [ '<STR_LIT>' ] [ idx ] = dict ( trigger = short , contents = full ) <EOL> else : <EOL> abbrevs [ '<STR_LIT>' ] . append ( dict ( trigger = short , contents = full ) ) <EOL> save_abbrevs ( abbrevs ) <EOL> def get ( self , short ) : <EOL> raise NotImplementedError ( ) <EOL> def get_all ( self ) : <EOL> abbrevs = load_abbrevs ( ) <EOL> for item in abbrevs [ '<STR_LIT>' ] : <EOL> yield item <EOL> def contains ( self , data , short ) : <EOL> for ( i , completion ) in enumerate ( data [ '<STR_LIT>' ] ) : <EOL> if completion [ '<STR_LIT>' ] == short : <EOL> return i <EOL> return None <EOL> def erase ( self , short ) : <EOL> data = load_abbrevs ( ) <EOL> idx = self . contains ( data , short ) <EOL> if idx is not None : <EOL> del data [ '<STR_LIT>' ] [ idx ] <EOL> save_abbrevs ( data ) </s>
