<s> import bibtex <EOL> import cache <EOL> ENCODING = '<STR_LIT:utf-8>' <EOL> def candidates ( bib_files , cache_dir ) : <EOL> """<STR_LIT>""" <EOL> if type ( bib_files ) is str : <EOL> bib_files = [ bib_files ] <EOL> unite_keyvals = dict ( ) <EOL> for bib in bib_files : <EOL> c = cache . Cache ( bib , cache_dir ) <EOL> try : <EOL> c . read ( ) <EOL> except ( cache . NoCache , cache . OutdatedCache ) : <EOL> c . update ( bibtex . parse ) <EOL> c . write ( ) <EOL> unite_keyvals . update ( c . data ) <EOL> gathered = [ ( bibtex_key , text ) for bibtex_key , text in <EOL> sorted ( unite_keyvals . viewitems ( ) , key = lambda x : x [ <NUM_LIT:0> ] . lower ( ) ) ] <EOL> return gathered <EOL> def make_vim_commands ( gathered , target , prefix , postfix ) : <EOL> """<STR_LIT>""" <EOL> cmd_list = list ( ) <EOL> for item in gathered : <EOL> action_text = prefix + item [ <NUM_LIT:0> ] . encode ( ENCODING ) + postfix <EOL> word = item [ <NUM_LIT:1> ] . replace ( "<STR_LIT:'>" , "<STR_LIT>" ) . encode ( ENCODING ) <EOL> cmd = "<STR_LIT>" % ( <EOL> target , action_text , word ) <EOL> cmd_list . append ( cmd ) <EOL> return cmd_list </s>
