Function: cl-search
cl-search is an autoloaded and byte-compiled function defined in
cl-seq.el.gz.
Signature
(cl-search SEQ1 SEQ2 [KEYWORD VALUE]...)
Documentation
Search for SEQ1 as a subsequence of SEQ2.
Return the index of the leftmost element of the first match found; return nil if there are no matches.
Keywords supported: :test :test-not :key :start1 :end1 :start2 :end2 :from-end
Aliases
search (obsolete since 27.1)
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/cl-seq.el.gz
;;;###autoload
(defun cl-search (seq1 seq2 &rest cl-keys)
"Search for SEQ1 as a subsequence of SEQ2.
Return the index of the leftmost element of the first match found;
return nil if there are no matches.
\nKeywords supported: :test :test-not :key :start1 :end1 :start2 :end2 :from-end
\n(fn SEQ1 SEQ2 [KEYWORD VALUE]...)"
(declare (important-return-value t))
(cl--parsing-keywords ( :test :test-not :key :from-end
(:start1 0) :end1 (:start2 0) :end2) ()
(or cl-end1 (setq cl-end1 (length seq1)))
(or cl-end2 (setq cl-end2 (length seq2)))
(if (>= cl-start1 cl-end1)
(if cl-from-end cl-end2 cl-start2)
(let* ((len (- cl-end1 cl-start1))
(first (cl--check-key (elt seq1 cl-start1)))
(cl-if nil) pos)
(setq cl-end2 (- cl-end2 (1- len)))
(while (and (< cl-start2 cl-end2)
(setq pos (cl--position first seq2
cl-start2 cl-end2 cl-from-end))
(apply #'cl-mismatch seq1 seq2
:start1 (1+ cl-start1) :end1 cl-end1
:start2 (1+ pos) :end2 (+ pos len)
:from-end nil cl-keys))
(if cl-from-end (setq cl-end2 pos) (setq cl-start2 (1+ pos))))
(and (< cl-start2 cl-end2) pos)))))