Function: cl-remove
cl-remove is an autoloaded and byte-compiled function defined in
cl-seq.el.gz.
Signature
(cl-remove ITEM SEQ [KEYWORD VALUE]...)
Documentation
Remove all occurrences of ITEM in SEQ.
This is a non-destructive function; it makes a copy of SEQ if necessary to avoid corrupting the original SEQ.
Keywords supported: :test :test-not :key :count :start :end :from-end
Aliases
remove* (obsolete since 27.1)
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/cl-seq.el.gz
;;;###autoload
(defun cl-remove (item seq &rest cl-keys)
"Remove all occurrences of ITEM in SEQ.
This is a non-destructive function; it makes a copy of SEQ if necessary
to avoid corrupting the original SEQ.
\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 (or (nlistp seq) (and cl-from-end (< cl-count (/ len 2))))
(let ((i (cl--position item seq cl-start cl-end
cl-from-end)))
(if i
(let ((res (apply #'cl-delete item (append seq nil)
(append (if cl-from-end
(list :end (1+ i))
(list :start i))
cl-keys))))
(if (listp seq) res
(if (stringp seq) (concat res) (vconcat res))))
seq))
(setq cl-end (- (or cl-end len) cl-start))
(if (= cl-start 0)
(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))))
(if (and (> cl-count 0) (> cl-end 0))
(let ((p (if (> cl-start 0) (nthcdr cl-start seq)
(setq cl-end (1- cl-end)) (cdr seq))))
(while (and p (> cl-end 0)
(not (cl--check-test item (car p))))
(setq p (cdr p) cl-end (1- cl-end)))
(if (and p (> cl-end 0))
(nconc (cl-ldiff seq p)
(if (= cl-count 1) (cdr p)
(and (cdr p)
(apply #'cl-delete item
(copy-sequence (cdr p))
:start 0 :end (1- cl-end)
:count (1- cl-count) cl-keys))))
seq))
seq))))))