From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: Most used words in current buffer Date: Wed, 18 Jul 2018 13:48:21 +0200 Organization: Aioe.org NNTP Server Message-ID: <86o9f4hiii.fsf@zoho.com> References: <861sc1iu1m.fsf@zoho.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1531914506 11526 195.159.176.226 (18 Jul 2018 11:48:26 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 18 Jul 2018 11:48:26 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jul 18 13:48:21 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ffkwP-0002rm-Ch for geh-help-gnu-emacs@m.gmane.org; Wed, 18 Jul 2018 13:48:21 +0200 Original-Received: from localhost ([::1]:36026 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ffkyU-0003DS-9l for geh-help-gnu-emacs@m.gmane.org; Wed, 18 Jul 2018 07:50:30 -0400 Original-Path: usenet.stanford.edu!goblin1!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 31 Original-NNTP-Posting-Host: onLrbz09yV+MU3RaxdbMkg.user.gioia.aioe.org Original-X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.3 Mail-Copies-To: never Cancel-Lock: sha1:RfweRw1rWJBlJR2JOegqC63Me1Y= Original-Xref: usenet.stanford.edu gnu.emacs.help:223356 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:117482 Archived-At: 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