Function: haskell-complete-module-read

haskell-complete-module-read is a natively compiled function defined in haskell-complete-module.el.

Signature

(haskell-complete-module-read PROMPT CANDIDATES)

Documentation

Interactively auto-complete from a list of candidates.

Source Code

;; Defined in /nix/store/9lz2mhw95f9fqxr9mnq46k3f6qz3aq83-emacs-packages-deps/share/emacs/site-lisp/elpa/haskell-mode-20260904.1042/haskell-complete-module.el
(defun haskell-complete-module-read (prompt candidates)
  "Interactively auto-complete from a list of candidates."
  (let ((stack (list))
        (pattern "")
        (result nil))
    (delete-dups candidates)
    (setq candidates
          (sort candidates
                (lambda (a b)
                  (let ((a-mem (member a haskell-complete-module-preferred))
                        (b-mem (member b haskell-complete-module-preferred)))
                    (cond
                     ((and a-mem (not b-mem))
                      t)
                     ((and b-mem (not a-mem))
                      nil)
                     (t
                      (string< a b)))))))
    (while (not result)
      (let ((key
             (key-description
              (vector
               (read-key
                (concat (propertize prompt 'face 'minibuffer-prompt)
                        (propertize pattern 'face 'font-lock-type-face)
                        "{"
                        (mapconcat #'identity
                                   (let* ((i 0))
                                     (cl-loop for candidate in candidates
                                              while (<= i haskell-complete-module-max-display)
                                              do (cl-incf i)
                                              collect (cond ((> i haskell-complete-module-max-display)
                                                             "...")
                                                            ((= i 1)
                                                             (propertize candidate 'face 'ido-first-match-face))
                                                            (t candidate))))
                                   " | ")
                        "}"))))))
        (cond
         ((string= key "C-g")
          (keyboard-quit))
         ((string= key "DEL")
          (unless (null stack)
            (setq candidates (pop stack)))
          (unless (string= "" pattern)
            (setq pattern (substring pattern 0 -1))))
         ((string= key "RET")
          (setq result (or (car candidates)
                           pattern)))
         ((string= key "<left>")
          (setq candidates
                (append (last candidates)
                        (butlast candidates))))
         ((string= key "<right>")
          (setq candidates
                (append (cdr candidates)
                        (list (car candidates)))))
         (t
          (when (string-match "[A-Za-z0-9_'.]+" key)
            (push candidates stack)
            (setq pattern (concat pattern key))
            (setq candidates (haskell-complete-module pattern candidates)))))))
    result))