bairui

Symbol Table Frequency List

Jan 9th, 2012
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 0.71 KB | None | 0 0
  1. " Frequency Count of Unique Symbols
  2. " Barry Arthur, 2012 01 09
  3.  
  4. function! Symbols()
  5.   let lines = join(getline(1,'$'))
  6.   let lines = substitute(lines, '"\w.\{-}"', '', 'g')
  7.   return sort(filter(split(lines, '\s\+\|[-|''"=+$#@!.,{}()\[\]]'), 'v:val != ""'))
  8. endfunction
  9.  
  10. function! DictSort(i1, i2)
  11.   return a:i1[1] == a:i2[1] ? 0 : a:i1[1] > a:i2[1] ? 1 : -1
  12. endfunction
  13.  
  14. function! Unique(symbols)
  15.   let sym = {}
  16.   for s in a:symbols
  17.     if has_key(sym, s)
  18.       let sym[s] += 1
  19.     else
  20.       let sym[s] = 1
  21.     end
  22.   endfor
  23.   return sort(items(sym), 'DictSort')
  24. endfunction
  25.  
  26. function! PrettyPrint(data)
  27.   for r in a:data
  28.     echo r
  29.   endfor
  30. endfunction
  31.  
  32. call PrettyPrint(Unique(Symbols()))
Advertisement
Add Comment
Please, Sign In to add comment