Function: cl-delete

cl-delete is an autoloaded and byte-compiled function defined in cl-seq.el.gz.

Signature

(cl-delete ITEM SEQ [KEYWORD VALUE]...)

Documentation

Remove all occurrences of ITEM in SEQ.

This is a destructive function; it reuses the storage of SEQ whenever possible.

Keywords supported: :test :test-not :key :count :start :end :from-end

View in manual

Aliases

delete* (obsolete since 27.1)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/cl-seq.el.gz
;;;###autoload
(defun cl-delete (item seq &rest cl-keys)
  "Remove all occurrences of ITEM in SEQ.
This is a destructive function; it reuses the storage of SEQ whenever possible.
\nKeywords supported:  :test :test-not :key :count :start :end :from-end
\n(fn ITEM SEQ [KEYWORD VALUE]...)"
  (declare (important-return-value t))
  (cl--parsing-keywords ( :test :test-not :key :if :if-not :count :from-end
                          (:start 0) :end) ()
    (let ((len (length seq)))
      (if (<= (or cl-count (setq cl-count len)) 0)
          seq
        (if (listp seq)
            (if (and cl-from-end (< cl-count (/ len 2)))
                (let (i)
                  (while (and (>= (setq cl-count (1- cl-count)) 0)
                              (setq i (cl--position item seq cl-start
                                                    cl-end cl-from-end)))
                    (if (= i 0) (setq seq (cdr seq))
                      (let ((tail (nthcdr (1- i) seq)))
                        (setcdr tail (cdr (cdr tail)))))
                    (setq cl-end i))
                  seq)
              (setq cl-end (- (or cl-end len) cl-start))
              (if (= cl-start 0)
                  (progn
                    (while (and seq
                                (> cl-end 0)
                                (cl--check-test item (car seq))
                                (setq cl-end (1- cl-end) seq (cdr seq))
                                (> (setq cl-count (1- cl-count)) 0)))
                    (setq cl-end (1- cl-end)))
                (setq cl-start (1- cl-start)))
              (if (and (> cl-count 0) (> cl-end 0))
                  (let ((p (nthcdr cl-start seq)))
                    (while (and (cdr p) (> cl-end 0))
                      (if (cl--check-test item (car (cdr p)))
                          (progn
                            (setcdr p (cdr (cdr p)))
                            (if (= (setq cl-count (1- cl-count)) 0)
                                (setq cl-end 1)))
                        (setq p (cdr p)))
                      (setq cl-end (1- cl-end)))))
              seq)
          (apply #'cl-remove item seq cl-keys))))))