|
From: | Evgeny Roubinchtein |
Subject: | Re: How to implement line sorting, uniquifying and counting function in emacs? |
Date: | Mon, 30 Sep 2002 05:23:38 GMT |
User-agent: | Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.5 (brussels sprouts) |
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))))
[Prev in Thread] | Current Thread | [Next in Thread] |