Function: avy-read-words

avy-read-words is a byte-compiled function defined in avy.el.

Signature

(avy-read-words LST WORDS)

Documentation

Select from LST using WORDS.

Source Code

;; Defined in ~/.emacs.d/elpa/avy-20241101.1357/avy.el
(defun avy-read-words (lst words)
  "Select from LST using WORDS."
  (catch 'done
    (let ((num-words (length words))
          (num-entries (length lst))
          alist)
      ;; If there are not enough words to cover all the candidates,
      ;; we use a De Bruijn sequence to generate the remaining ones.
      (when (< num-words num-entries)
        (let ((keys avy-keys)
              (bad-keys '(?a ?e ?i ?o ?u ?y))
              (path-len 1)
              (num-remaining (- num-entries num-words))
              tmp-alist)
          ;; Delete all keys which could lead to duplicates.
          ;; We want at least three keys left to work with.
          (dolist (x bad-keys)
            (when (memq x keys)
              (setq keys (delq ?a keys))))
          (when (< (length keys) 3)
            (signal 'user-error
                    '("Please add more keys to the variable `avy-keys'.")))
          ;; Generate the sequence and add the keys to the existing words.
          (while (not tmp-alist)
            (cl-incf path-len)
            (setq tmp-alist (avy--path-alist-1 lst path-len keys)))
          (while (>= (cl-decf num-remaining) 0)
            (push (mapconcat 'string (caar tmp-alist) nil) (cdr (last words)))
            (setq tmp-alist (cdr tmp-alist)))))
      (dolist (x lst)
        (push (cons (string-to-list (pop words)) x) alist))
      (setq avy-current-path "")
      (while (or (> (length alist) 1)
                 (caar alist))
        (dolist (x (reverse alist))
          (avy--overlay-at-full (reverse (car x)) (cdr x)))
        (let ((char (funcall avy-translate-char-function (read-key))))
          (avy--remove-leading-chars)
          (setq alist
                (delq nil
                      (mapcar (lambda (x)
                                (when (eq (caar x) char)
                                  (cons (cdr (car x)) (cdr x))))
                              alist)))
          (setq avy-current-path
                (concat avy-current-path (string (avy--key-to-char char))))
          (unless alist
            (funcall avy-handler-function char))))
      (cdar alist))))