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

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

Re: Emacs Lisp Programming Questions


From: clint.laskowski
Subject: Re: Emacs Lisp Programming Questions
Date: Thu, 8 Oct 2009 06:36:23 -0700 (PDT)
User-agent: G2/1.0

On Oct 6, 5:40 pm, "clint.laskowski" <clint.laskow...@gmail.com>
wrote:

> 2. I want to write an interactive Elisp program to remove sequential
> duplicate lines from a buffer. This buffer is not sorted, and it
> should not be sorted. The program should simply look for two
> sequential lines that are identical, delete one, and then move on to
> the next line and do it over until it reaches the end of the buffer.

I appreciate all the pointers and ideas. I ended up finding a solution
(instead of learning it myself, but that's okay - since I actually
learned more from the responses here) which is now in my .emacs file:

(defun uniquify-region (beg end)
  "remove duplicate adjacent lines in the given region"
  (interactive "*r")
  (goto-char beg)
  (while (re-search-forward "^\\(.*\n\\)\\1+" end t)
  (replace-match "\\1")))

(defun uniquify-buffer ()
  (interactive)
  (uniquify-region (point-min) (point-max)))

Thanks again for the help!

-- Clint


reply via email to

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