help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Most used words in current buffer


From: Emanuel Berg
Subject: Re: Most used words in current buffer
Date: Wed, 18 Jul 2018 13:48:21 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Udyant Wig wrote:

> (defun buffer-most-used-words-1 (n)
>   "Make a list of the N most used words in buffer."
>   (let ((counts (make-hash-table :test #'equal))
>       (words (split-string (buffer-string)))
>       sorted-counts)
>     (dolist (word words)
>       (let ((count (gethash (downcase word) counts 0)))
>       (puthash (downcase word) (1+ count) counts)))
>     (loop for word being the hash-keys of counts
>        using (hash-values count)
>        do
>        (push (list word count) sorted-counts)
>        finally (setf sorted-counts (cl-sort sorted-counts #'>
>                                           :key #'second)))
>     (mapcar #'first (cl-subseq sorted-counts 0 n))))

Great! Only

    (require 'cl-lib)
    loop -> cl-loop
    first -> cl-first
    second -> cl-second

Perhaps this should be published in M/ELPA or
at the very least on gnu.emacs.sources :)

-- 
underground experts united
http://user.it.uu.se/~embe8573


reply via email to

[Prev in Thread] Current Thread [Next in Thread]