bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#13032: 24.3.50; Request: Provide a `delete-duplicate-lines' command


From: Juanma Barranquero
Subject: bug#13032: 24.3.50; Request: Provide a `delete-duplicate-lines' command
Date: Thu, 29 Nov 2012 21:49:47 +0100

On Thu, Nov 29, 2012 at 8:23 PM, Dani Moncayo <dmoncayo@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)))))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]