unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Evgeny Roubinchtein <zhenya@freeshell.org>
Subject: Re: How to implement line sorting, uniquifying and counting function in emacs?
Date: Mon, 30 Sep 2002 05:23:38 GMT	[thread overview]
Message-ID: <87znu0cap2.fsf@freeshell.org> (raw)
In-Reply-To: b00bb831.0209291813.72d27e23@posting.google.com

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))))

  parent reply	other threads:[~2002-09-30  5:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-30  2:13 How to implement line sorting, uniquifying and counting function in emacs? gnuist006
2002-09-30  5:15 ` Evgeny Roubinchtein
2002-09-30  5:23 ` Evgeny Roubinchtein [this message]
2002-09-30  7:04 ` Marc Spitzer
2002-09-30  8:12 ` Jens Schmidt
2002-09-30 16:14 ` Kaz Kylheku
2002-10-01  8:00 ` Steven M. Haflich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87znu0cap2.fsf@freeshell.org \
    --to=zhenya@freeshell.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).