Summary: Rückgängig gemacht auf den Stand vom 2013-08-24 11:21 UTC
< (pt (WikiModes-backward-regexp "[ \t\n]" nil t))
> (pt (search-backward-regexp "[ \t\n]" nil t))
See also: ProgrammableCompletion.
The various sections on this page shall contain various examples:
Q: I want the very basic minimal completion, where I supply a list of completions, and pcomplete completes them based on the word at point.
Let your major mode be called foo-mode.
Now, advise your users to
(add-hook 'foo-mode-hook 'pcomplete-foo-setup)
(defvar foo-all-completions <list of completions as strings>) (defvar foo-all-completions '("foo" "bar" "baz"))
In the above example, when your users type fo and press M-x pcomplete somewhere, when in foo major mode, you want the pcompletions offered to be one of foo, bar and baz.
(defun pcomplete-foo-setup () (interactive) (set (make-local-variable 'pcomplete-parse-arguments-function) 'pcomplete-parse-foo-arguments) (set (make-local-variable 'pcomplete-default-completion-function) 'pcomplete-foo-default-completion))
(defun pcomplete-foo-default-completion () (pcomplete-here foo-all-completions))
So far, pretty clear, right? Now the only thing remaining is to define the pcomplete-parse-arguments-function. This function should return the word-at-point as a SECOND argument and should return the point where the word starts, so that pcomplete thinks of the word as an argument, not a command. The syntax of the return value is
(("command" "arg1" "arg2" ...) point0 point1 point2 ...)
where the points correspond to the args.
So, you can define:
(defun pcomplete-parse-foo-arguments () (save-excursion (let* ((thispt (point)) (pt (search-backward-regexp "[ \t\n]" nil t)) (ptt (if pt (+ pt 1) thispt))) (list (list "dummy" (buffer-substring-no-properties ptt thispt)) (point-min) ptt))))
As you can see, the first argument is a “dummy”
Also note that the above example can also work independent of foo-major-mode. All you have to do to set it up is pcomplete-foo-setup. From then on M-x pcomplete works as expected.
Q: Is there a package for Emacs to complete an interactive call to load-library() just like XEmacs does?
A: There’s a find-lib.el
For more complicated examples, browse the sources of erc-pcomplete.el and of eshell.