GNU bug report logs -
#13032
24.3.50; Request: Provide a `delete-duplicate-lines' command
Previous Next
Reported by: Dani Moncayo <dmoncayo <at> gmail.com>
Date: Thu, 29 Nov 2012 19:26:01 UTC
Severity: wishlist
Found in version 24.3.50
Done: Juri Linkov <juri <at> jurta.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
On Thu, Nov 29, 2012 at 8:23 PM, Dani Moncayo <dmoncayo <at> gmail.com> wrote:
> Severity: wishlist
> That is: provide a function `delete-duplicate-lines' (or some such)
> that removes all duplicate lines in the active region and prints in
> the echo area a message like "Duplicate lines removed: <n>".
Perhaps you can work from this (not very well tested):
(defun delete-duplicate-lines (beg end)
"Delete consecutive duplicate lines in region BEG..END."
(interactive "r")
(save-excursion
(save-restriction
(narrow-to-region beg end)
(goto-char beg)
(let ((kill-whole-line t)
(last (buffer-substring (line-beginning-position)
(line-end-position)))
(removed 0)
current)
(forward-line 1)
(while (and (< (point) (or end 1))
(not (eobp)))
(setq current (buffer-substring (line-beginning-position)
(line-end-position)))
(if (string= last current)
(progn
(kill-line)
(setq removed (1+ removed)))
(setq last current)
(forward-line 1)))
(message "Duplicate lines removed: %d" removed)))))
This bug report was last modified 12 years and 172 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.