From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: 13032@debbugs.gnu.org
Subject: bug#13032: 24.3.50; Request: Provide a `delete-duplicate-lines' command
Date: Tue, 04 Dec 2012 08:04:13 +0100 [thread overview]
Message-ID: <87obia9u36.fsf@gmail.com> (raw)
In-Reply-To: <CAH8Pv0hzGaYS63VW51x5LM+qUjKRNG7s1qW48=w1Mbb07F4C4g@mail.gmail.com>
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
next prev parent reply other threads:[~2012-12-04 7:04 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-29 19:23 bug#13032: 24.3.50; Request: Provide a `delete-duplicate-lines' command Dani Moncayo
2012-11-29 20:49 ` Juanma Barranquero
2012-11-29 21:43 ` Dani Moncayo
2012-11-29 22:45 ` Juanma Barranquero
2012-11-30 0:31 ` Juri Linkov
2012-11-30 0:46 ` Juanma Barranquero
2012-11-30 0:50 ` Juanma Barranquero
2012-11-30 0:57 ` Juri Linkov
2012-11-30 1:02 ` Juanma Barranquero
2012-11-30 1:12 ` Juri Linkov
2012-11-30 7:51 ` Dani Moncayo
2012-12-01 0:34 ` Juri Linkov
2012-12-01 9:08 ` Dani Moncayo
2012-12-01 9:22 ` Dani Moncayo
2012-12-02 0:45 ` Juri Linkov
2012-12-02 9:13 ` Dani Moncayo
2012-12-03 23:49 ` Juri Linkov
2012-12-04 0:05 ` Juri Linkov
2012-12-04 9:13 ` Dani Moncayo
2012-12-04 23:51 ` Juri Linkov
2012-12-05 8:08 ` Dani Moncayo
2012-11-30 7:51 ` Dani Moncayo
2012-12-04 7:04 ` Thierry Volpiatto [this message]
2012-12-04 14:46 ` Stefan Monnier
2012-12-04 15:02 ` Thierry Volpiatto
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87obia9u36.fsf@gmail.com \
--to=thierry.volpiatto@gmail.com \
--cc=13032@debbugs.gnu.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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.