From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Evgeny Roubinchtein Newsgroups: gmane.emacs.help Subject: Re: How to implement line sorting, uniquifying and counting function in emacs? Date: Mon, 30 Sep 2002 05:23:38 GMT Organization: Giganews.Com - Premium News Outsourcing Sender: help-gnu-emacs-admin@gnu.org Message-ID: <87znu0cap2.fsf@freeshell.org> References: NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1033364181 25656 127.0.0.1 (30 Sep 2002 05:36:21 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 30 Sep 2002 05:36:21 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17vtEB-0006fd-00 for ; Mon, 30 Sep 2002 07:36:19 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17vtEI-0002sN-00; Mon, 30 Sep 2002 01:36:26 -0400 Original-Path: shelby.stanford.edu!nntp.stanford.edu!newsfeed.stanford.edu!logbridge.uoregon.edu!HSNX.atgi.net!cyclone-sf.pbi.net!151.164.30.35!cyclone.swbell.net!newsfeed1.easynews.com!easynews.com!easynews!nntp2.aus1.giganews.com!nntp.giganews.com!nntp3.aus1.giganews.com!bin4.nnrp.aus1.giganews.com.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.5 (brussels sprouts) Original-NNTP-Posting-Date: Mon, 30 Sep 2002 00:23:38 CDT Original-Lines: 29 Original-X-Trace: sv3-em0jkNv/r8/EQZU8z7EgTq9g3AHzjcTrcFtRQwC9sty13JjLgKHRRedOAQaWnORJrnWM/cIStJ/pEv+!DWmbftVJyMdlBTEmw5mjIlf6XoWC4PokxamngcCR33Asic7fcw== Original-X-Complaints-To: abuse@GigaNews.Com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Original-Xref: nntp.stanford.edu gnu.emacs.help:105527 Original-To: help-gnu-emacs@gnu.org Errors-To: help-gnu-emacs-admin@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.help:2071 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:2071 Oops... Just noticed I didn't really need to insert a dummy newline when using a temp buffer. (defun count-repeated-lines (&optional beg end) (let ((buf (current-buffer)) (repeated-count 0) (unique-count 0) (cur-line nil) (prev-line nil)) (with-temp-buffer (insert-buffer-substring buf (and beg (with-current-buffer buf (save-excursion (goto-char beg) (line-beginning-position)))) end) (sort-lines nil (point-min) (point-max)) (goto-char (point-min)) (while (/= (point) (point-max)) (setq cur-line (buffer-substring-no-properties (point) (save-excursion (end-of-line) (point)))) (if (and prev-line (string= prev-line cur-line)) (setq repeated-count (1+ repeated-count)) (setq unique-count (1+ unique-count))) (setq prev-line cur-line) (forward-line)) (cons unique-count repeated-count))))