@@ -353,39 +353,24 @@ def resort_ctags(tag_file):
353353
354354 :returns: None
355355 """
356- meta = []
357- symbols = []
358- tmp_file = tag_file + '.tmp'
356+ groups = {}
359357
360358 with codecs .open (tag_file , encoding = 'utf-8' , errors = 'replace' ) as file_ :
361359 for line in file_ :
360+ # meta data not needed in sorted files
362361 if line .startswith ('!_TAG' ):
363- meta .append (line )
364362 continue
365363
366364 # read all valid symbol tags, which contain at least
367365 # symbol name and containing file and build a list of tuples
368- split = line .split ('\t ' )
366+ split = line .split ('\t ' , FILENAME + 1 )
369367 if len (split ) > FILENAME :
370- symbols . append (( split [FILENAME ], split ) )
368+ groups . setdefault ( split [FILENAME ], []). append ( line )
371369
372- # sort inplace to save some RAM with large .tags files
373- meta .sort ()
374- symbols .sort ()
375-
376- with codecs .open (tmp_file , 'w' , encoding = 'utf-8' ,
370+ with codecs .open (tag_file + '_sorted_by_file' , 'w' , encoding = 'utf-8' ,
377371 errors = 'replace' ) as file_ :
378-
379- # write sourted metadata
380- file_ .writelines (meta )
381-
382- # followed by sorted list of symbols
383- for _ , split in symbols :
384- split [FILENAME ] = split [FILENAME ].lstrip ('.\\ ' )
385- file_ .write ('\t ' .join (split ))
386-
387- os .remove (tag_file )
388- os .rename (tmp_file , tag_file )
372+ for group in sorted (groups ):
373+ file_ .writelines (groups [group ])
389374
390375#
391376# Models
0 commit comments