Have the following code that counts the number of times words are used. I want to list the results sorted by the number of counts.
(defun rk-word-analysis (reg-beg reg-end)
"Count times words are used in a region, ignoring punctuation."
(interactive "r")
(let ($words)
(save-excursion
(goto-char reg-beg)
(while (re-search-forward "\\w+" reg-end t)
(let* (($word (intern (match-string 0)))
($cell (assq $word $words)))
(if $cell
(setcdr $cell (1+ (cdr $cell)))
(setq $words (cons (cons $word 1) $words))))))
(when (interactive-p)
(message "%S" $words))
$words))