Function: completion-table-dynamic

completion-table-dynamic is a byte-compiled function defined in minibuffer.el.gz.

Signature

(completion-table-dynamic FUN &optional SWITCH-BUFFER)

Documentation

Use function FUN as a dynamic completion table.

FUN is called with one argument, the string for which completion is requested, and it should return a completion table containing all the intended possible completions. This table is allowed to include elements that do not actually match the string: they will be automatically filtered out. The completion table returned by FUN can use any of the usual formats of completion tables such as lists, alists, and hash-tables.

If SWITCH-BUFFER is non-nil and completion is performed in the minibuffer, FUN will be called in the buffer from which the minibuffer was entered.

The result of the completion-table-dynamic form is a function that can be used as the COLLECTION argument to try-completion and all-completions. See Info node (elisp)Programmed Completion. The completion table returned by completion-table-dynamic has empty metadata and trivial boundaries.

See also the related function completion-table-with-cache.

View in manual

Probably introduced at or before Emacs version 24.4.

Source Code

;; Defined in /usr/src/emacs/lisp/minibuffer.el.gz
(defun completion-table-dynamic (fun &optional switch-buffer)
  "Use function FUN as a dynamic completion table.
FUN is called with one argument, the string for which completion is requested,
and it should return a completion table containing all the intended possible
completions.
This table is allowed to include elements that do not actually match the
string: they will be automatically filtered out.
The completion table returned by FUN can use any of the usual formats of
completion tables such as lists, alists, and hash-tables.

If SWITCH-BUFFER is non-nil and completion is performed in the
minibuffer, FUN will be called in the buffer from which the minibuffer
was entered.

The result of the `completion-table-dynamic' form is a function
that can be used as the COLLECTION argument to `try-completion' and
`all-completions'.  See Info node `(elisp)Programmed Completion'.
The completion table returned by `completion-table-dynamic' has empty
metadata and trivial boundaries.

See also the related function `completion-table-with-cache'."
  (lambda (string pred action)
    (if (or (eq (car-safe action) 'boundaries) (eq action 'metadata))
        ;; `fun' is not supposed to return another function but a plain old
        ;; completion table, whose boundaries are always trivial.
        nil
      (with-current-buffer (if (not switch-buffer) (current-buffer)
                             (let ((win (minibuffer-selected-window)))
                               (if (window-live-p win) (window-buffer win)
                                 (current-buffer))))
        (complete-with-action action (funcall fun string) string pred)))))