Skip to content

Instantly share code, notes, and snippets.

@baron
Created November 19, 2010 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baron/706601 to your computer and use it in GitHub Desktop.
Save baron/706601 to your computer and use it in GitHub Desktop.
;;;_ , my-remove-duplicates
; This little fellow is great. It removes duplicates from region i.e.
; transforms "foo baz foo bar baz" into "foo baz bar".
(defun my-remove-duplicates (start end)
(interactive "r")
(save-excursion
(goto-char start)
(narrow-to-region start end)
(let ((seen nil) (word nil) (s start))
(while (forward-word)
(when (setq word (word-at-point))
(if (member word seen)
(kill-region s (point))
(setq seen (cons word seen)) ))
(setq s (point))))
(widen))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment