Function: delete-consecutive-dups

delete-consecutive-dups is a byte-compiled function defined in subr.el.gz.

Signature

(delete-consecutive-dups LIST &optional CIRCULAR)

Documentation

Destructively remove equal consecutive duplicates from LIST.

First and last elements are considered consecutive if CIRCULAR is non-nil.

Probably introduced at or before Emacs version 24.4.

Source Code

;; Defined in /usr/src/emacs/lisp/subr.el.gz
;; See https://lists.gnu.org/r/emacs-devel/2013-05/msg00204.html
(defun delete-consecutive-dups (list &optional circular)
  "Destructively remove `equal' consecutive duplicates from LIST.
First and last elements are considered consecutive if CIRCULAR is
non-nil."
  (let ((tail list) last)
    (while (cdr tail)
      (if (equal (car tail) (cadr tail))
	  (setcdr tail (cddr tail))
	(setq last tail
	      tail (cdr tail))))
    (if (and circular
	     last
	     (equal (car tail) (car list)))
	(setcdr last nil)))
  list)