aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2019-11-20 00:00:11 +0000
committerJoão Távora2019-11-20 00:00:11 +0000
commitd2873706749ef68803e79bab6109a534f4c9d23a (patch)
tree6fa0fb22790189e162844255545b5986ef83f650
parentaa79f4e8c635537c50a50db211542c0f41443ae2 (diff)
downloademacs-scratch/joaot/make-completion-at-point-function.tar.gz
emacs-scratch/joaot/make-completion-at-point-function.zip
Untested make-completion-at-point-function capf entrypointscratch/joaot/make-completion-at-point-function
* lisp/minibuffer.el (make-completion-at-point-function): New helper. (completion-at-point-functions): Adjust docstring.
-rw-r--r--lisp/minibuffer.el135
1 files changed, 121 insertions, 14 deletions
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 6e72eb73f99..a122a0fe84d 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -87,7 +87,7 @@
87 87
88;;; Code: 88;;; Code:
89 89
90(eval-when-compile (require 'cl-lib)) 90(require 'cl-lib)
91 91
92;;; Completion table manipulation 92;;; Completion table manipulation
93 93
@@ -2108,22 +2108,129 @@ Also respects the obsolete wrapper hook `completion-in-region-functions'.
2108 (delq (assq 'completion-in-region-mode minor-mode-map-alist) 2108 (delq (assq 'completion-in-region-mode minor-mode-map-alist)
2109 minor-mode-map-alist)) 2109 minor-mode-map-alist))
2110 2110
2111(cl-defun make-completion-at-point-function (&rest all
2112 &key bounds
2113 metadata
2114 test-completion
2115 boundaries
2116 try-completion
2117 all-completions
2118 annotation-function
2119 doc-function
2120 forced-style
2121 exit-function
2122 display-sort-function
2123 &allow-other-keys)
2124 ;; FIXME: world-class docstring
2125 "Does the thing.
2126BOUNDS
2127METADATA
2128TEST-COMPLETION
2129BOUNDARIES
2130TRY-COMPLETION
2131ALL-COMPLETIONS
2132ANNOTATION-FUNCTION
2133DOC-FUNCTION
2134FORCED-STYLE
2135EXIT-FUNCTION
2136DISPLAY-SORT-FUNCTION
2137ALL."
2138 (let ((bounds (or (and (functionp bounds) (funcall bounds))
2139 bounds
2140 (bounds-of-thing-at-point 'symbol)
2141 (cons (point) (point))))
2142 (forced-category (and forced-style
2143 (cl-gensym "forces-style-category"))))
2144 (cl-assert all-completions nil "ALL-COMPLETIONS is a mandatory keyword arg.")
2145 (when forced-category
2146 ;; FIXME: Yes, I know, Stefan.
2147 (add-to-list 'completion-category-defaults
2148 `(,forced-category (styles . (,forced-style)))))
2149 (cl-list*
2150 (car bounds)
2151 (cdr bounds)
2152 (lambda (pattern pred action)
2153 (let* (cached-all-completions
2154 (get-all-completions
2155 (lambda ()
2156 (or cached-all-completions
2157 (setf cached-all-completions
2158 (let ((res (funcall all-completions pattern)))
2159 (if pred (cl-remove-if-not pred res) res)))))))
2160 (cond
2161 ((eq action 'metadata)
2162 (or (and (functionp metadata)
2163 (funcall metadata))
2164 metadata
2165 `(metadata
2166 .
2167 (,@(when display-sort-function
2168 `((display-sort-function . ,display-sort-function)))
2169 ,@(when forced-category
2170 `((category . ,forced-category)))))))
2171 ((eq action 'lambda)
2172 (if test-completion
2173 ;; FIXME: should we pass PRED to the user, use it here
2174 ;; directly, or ignore it?
2175 (funcall test-completion pattern)
2176 (and (member pattern (funcall get-all-completions))
2177 t)))
2178 ((eq (car-safe action) 'boundaries)
2179 (and boundaries
2180 ;; FIXME: same question
2181 (funcall boundaries pattern)))
2182 ((null action)
2183 (if try-completion
2184 ;; FIXME: same question
2185 (funcall try-completion pattern)
2186 (try-completion pattern (funcall get-all-completions))))
2187 ((eq action t)
2188 (funcall get-all-completions)))))
2189 :annotation-function annotation-function
2190 :company-doc-buffer doc-function
2191 :exit-function exit-function
2192 (cl-loop for (k v) on all by #'cddr
2193 unless (memq k
2194 ;; FIXME: define this list at compilation
2195 ;; time
2196 '(:bounds
2197 :metadata
2198 :test-completion
2199 :boundaries
2200 :try-completion
2201 :all-completions
2202 :annotation-function
2203 :doc-function
2204 :forced-style
2205 :exit-function
2206 :display-sort-function))
2207 collect k collect v))))
2208
2111(defvar completion-at-point-functions '(tags-completion-at-point-function) 2209(defvar completion-at-point-functions '(tags-completion-at-point-function)
2112 "Special hook to find the completion table for the entity at point. 2210 "Special hook to find the completion table for the entity at point.
2113Each function on this hook is called in turn without any argument and 2211Each function on this hook is called in turn and should return
2212non-nil if it is applicable at point.
2213
2214The recommended way to create functions to add to this list is
2215via `make-completion-at-point-function' (which see). The
2216remainder of the this docstring, described older, unencouraged
2217ways, to create such functions.
2218
2219The functions in this hook are called without any argument and
2114should return either nil, meaning it is not applicable at point, 2220should return either nil, meaning it is not applicable at point,
2115or a function of no arguments to perform completion (discouraged), 2221or a function of no arguments to perform
2116or a list of the form (START END COLLECTION . PROPS), where: 2222completion (discouraged), or a list of the form (START END
2117 START and END delimit the entity to complete and should include point, 2223COLLECTION . PROPS), where: START and END delimit the entity to
2118 COLLECTION is the completion table to use to complete the entity, and 2224complete and should include point, COLLECTION is the completion
2119 PROPS is a property list for additional information. 2225table to use to complete the entity, and PROPS is a property list
2120Currently supported properties are all the properties that can appear in 2226for additional information. Currently supported properties are
2121`completion-extra-properties' plus: 2227all the properties that can appear in
2122 `:predicate' a predicate that completion candidates need to satisfy. 2228`completion-extra-properties' plus: `:predicate' a predicate that
2123 `:exclusive' value of `no' means that if the completion table fails to 2229completion candidates need to satisfy. `:exclusive' value of
2124 match the text at point, then instead of reporting a completion 2230`no' means that if the completion table fails to match the text
2125 failure, the completion should try the next completion function. 2231at point, then instead of reporting a completion failure, the
2126As is the case with most hooks, the functions are responsible for 2232completion should try the next completion function. As is the
2233case with most hooks, the functions are responsible for
2127preserving things like point and current buffer. 2234preserving things like point and current buffer.
2128 2235
2129NOTE: These functions should be cheap to run since they're sometimes 2236NOTE: These functions should be cheap to run since they're sometimes