[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: |
Thierry Volpiatto |
Subject: |
bug#13032: 24.3.50; Request: Provide a `delete-duplicate-lines' command |
Date: |
Tue, 04 Dec 2012 08:04:13 +0100 |
User-agent: |
Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.3.50 (gnu/linux) |
Hi, just for info, here a simple and fast version.
Dani Moncayo <dmoncayo@gmail.com> writes:
>> This is what I currently use to delete duplicate lines:
>>
>> C-u M-| awk -- '!a[$0]++' RET
>>
>> Do you intend to create a Lisp function with the same result?
>
> I don't know awk, but I've tried that command and seems to do what I
> want: remove all duplicate lines in the region. Although it don't
> inform about the number of lines deleted, which is important to me.
--8<---------------cut here---------------start------------->8---
(defun delete-duplicate-lines (beg end)
"Delete duplicate lines in region."
(interactive "r")
(save-excursion
(save-restriction
(narrow-to-region beg end)
(let ((lines (helm-fast-remove-dups
(split-string (buffer-string) "\n" t)
:test 'equal)))
(delete-region (point-min) (point-max))
(loop for l in lines do (insert (concat l "\n")))))))
--8<---------------cut here---------------end--------------->8---
helm-fast-remove-dups is a function in helm:
https://github.com/emacs-helm/helm/blob/master/helm-utils.el
line 342
For the number of lines removed it is easy to modify the function to do
so.
--
Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997
- bug#13032: 24.3.50; Request: Provide a `delete-duplicate-lines' command, Dani Moncayo, 2012/12/01
- bug#13032: 24.3.50; Request: Provide a `delete-duplicate-lines' command, Dani Moncayo, 2012/12/01
- bug#13032: 24.3.50; Request: Provide a `delete-duplicate-lines' command, Juri Linkov, 2012/12/01
- bug#13032: 24.3.50; Request: Provide a `delete-duplicate-lines' command, Dani Moncayo, 2012/12/02
- bug#13032: 24.3.50; Request: Provide a `delete-duplicate-lines' command, Juri Linkov, 2012/12/03
- bug#13032: 24.3.50; Request: Provide a `delete-duplicate-lines' command, Juri Linkov, 2012/12/03
- bug#13032: 24.3.50; Request: Provide a `delete-duplicate-lines' command, Dani Moncayo, 2012/12/04
- bug#13032: 24.3.50; Request: Provide a `delete-duplicate-lines' command, Juri Linkov, 2012/12/04
- bug#13032: 24.3.50; Request: Provide a `delete-duplicate-lines' command, Dani Moncayo, 2012/12/05
- bug#13032: 24.3.50; Request: Provide a `delete-duplicate-lines' command,
Thierry Volpiatto <=