From: Stephen Berman <stephen.berman@gmx.net>
To: emacs-devel@gnu.org
Subject: Re: uniq
Date: Sat, 04 Dec 2010 13:08:28 +0100 [thread overview]
Message-ID: <87ipz9hhab.fsf@escher.home> (raw)
In-Reply-To: 20101203.184112.37434497.Takaaki.Ota@am.sony.com
On Fri, 3 Dec 2010 18:41:12 -0800 Tak Ota <Takaaki.Ota@am.sony.com> wrote:
> Do we have something equivalent to the next command? I know the name
> is bad as it is not same as UNIQ(1). It works better because sorting
> is not required.
>
> -Tak
>
> ;;
> ;; uniq
> ;;
> (defun uniq ()
> "Omit duplicated lines."
> (interactive)
> (save-excursion
> (goto-char (point-min))
> (while (not (= (point) (point-max)))
> (let* ((start (point))
> (str (format "^%s"
> (regexp-quote
> (buffer-substring start
> (progn (forward-line 1) (point)))))))
> (save-excursion
> (while (re-search-forward str nil t)
> (delete-region (match-beginning 0) (match-end 0))))))))
Would it be faster to avoid nested while-loops?
(defun uniq ()
"Omit duplicated lines."
(interactive)
(let (lines)
(save-excursion
(goto-char (point-min))
(while (not (eobp))
(let* ((beg (line-beginning-position))
(end (line-end-position))
(line (buffer-substring beg end)))
(if (member line lines)
(delete-region beg (1+ end))
(push line lines)
(forward-line)))))))
Steve Berman
next prev parent reply other threads:[~2010-12-04 12:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-04 2:41 uniq Tak Ota
2010-12-04 12:08 ` Stephen Berman [this message]
2010-12-04 14:09 ` uniq Stefan Monnier
2010-12-05 18:54 ` uniq René Kyllingstad
2010-12-05 19:15 ` uniq Lennart Borgman
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=87ipz9hhab.fsf@escher.home \
--to=stephen.berman@gmx.net \
--cc=emacs-devel@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.