Function: completion-pcm--optimize-pattern

completion-pcm--optimize-pattern is a byte-compiled function defined in minibuffer.el.gz.

Signature

(completion-pcm--optimize-pattern P)

Source Code

;; Defined in /usr/src/emacs/lisp/minibuffer.el.gz
(defun completion-pcm--optimize-pattern (p)
  ;; Remove empty strings in a separate phase since otherwise a ""
  ;; might prevent some other optimization, as in '(any "" any).
  (setq p (delete "" p))
  (let ((n '()))
    (while p
      (pcase p
        (`(,(or 'any 'any-delim) ,(or 'any 'point) . ,_)
         (setq p (cdr p)))
        ;; This is not just a performance improvement: it turns a
        ;; terminating `point' into an implicit `any', which affects
        ;; the final position of point (because `point' gets turned
        ;; into a non-greedy ".*?" regexp whereas we need it to be
        ;; greedy when it's at the end, see bug#38458).
        (`(point) (setq p nil)) ;Implicit terminating `any'.
        (_ (push (pop p) n))))
    (nreverse n)))