EmacsWiki: Programmable Completion (original) (raw)

This page is about standard Emacs library ` pcomplete.el’ and its related libraries. See PcompleteExamples for examples of using ` pcomplete.el’.

Note: The “programm**able** completion” of library ` pcomplete.el’ has nothing to do with the “programm**ed** completion” described in the EmacsLisp manual (dynamic-completion-table). The latter is about using a function to perform completion rather than supplying an explicit list of completion candidates.

Adding programmable completion using pcomplete

Example:

(defun pcomplete-erc-setup () "Setup erc-mode to use pcomplete." (set (make-local-variable 'pcomplete-parse-arguments-function) 'pcomplete-parse-erc-arguments) (set (make-local-variable 'pcomplete-command-completion-function)
'pcomplete/erc-mode/complete-command) (set (make-local-variable 'pcomplete-command-name-function) 'pcomplete-erc-command-name) (set (make-local-variable 'pcomplete-default-completion-function) (lambda () (pcomplete-here (pcomplete-erc-nicks)))) (set (make-local-variable 'pcomplete-suffix-list) '(? ?:)) )
(add-hook 'erc-mode-hook 'pcomplete-erc-setup)

pcomplete-parse-arguments-function has no parameters. It returns a list of arguments for the current command.

Returns the canonical name of the command. This is used to find the appropriate programmable completion function. For example, if the function returns “MSG” and the major mode is “erc-mode”, pcomplete will check pcomplete/erc-mode/MSG and pcomplete/MSG for completions.

pcomplete-default-completion-function gets called when you don’t have a function for the command currently being completed. Body should be of the form (pcomplete-here (… list of completions …))

Body should be of the form (pcomplete-here (… list of completions …))


CategoryCode CategoryCompletion