diff options
Diffstat (limited to 'lisp/minibuffer.el')
| -rw-r--r-- | lisp/minibuffer.el | 135 |
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. | ||
| 2126 | BOUNDS | ||
| 2127 | METADATA | ||
| 2128 | TEST-COMPLETION | ||
| 2129 | BOUNDARIES | ||
| 2130 | TRY-COMPLETION | ||
| 2131 | ALL-COMPLETIONS | ||
| 2132 | ANNOTATION-FUNCTION | ||
| 2133 | DOC-FUNCTION | ||
| 2134 | FORCED-STYLE | ||
| 2135 | EXIT-FUNCTION | ||
| 2136 | DISPLAY-SORT-FUNCTION | ||
| 2137 | ALL." | ||
| 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. |
| 2113 | Each function on this hook is called in turn without any argument and | 2211 | Each function on this hook is called in turn and should return |
| 2212 | non-nil if it is applicable at point. | ||
| 2213 | |||
| 2214 | The recommended way to create functions to add to this list is | ||
| 2215 | via `make-completion-at-point-function' (which see). The | ||
| 2216 | remainder of the this docstring, described older, unencouraged | ||
| 2217 | ways, to create such functions. | ||
| 2218 | |||
| 2219 | The functions in this hook are called without any argument and | ||
| 2114 | should return either nil, meaning it is not applicable at point, | 2220 | should return either nil, meaning it is not applicable at point, |
| 2115 | or a function of no arguments to perform completion (discouraged), | 2221 | or a function of no arguments to perform |
| 2116 | or a list of the form (START END COLLECTION . PROPS), where: | 2222 | completion (discouraged), or a list of the form (START END |
| 2117 | START and END delimit the entity to complete and should include point, | 2223 | COLLECTION . PROPS), where: START and END delimit the entity to |
| 2118 | COLLECTION is the completion table to use to complete the entity, and | 2224 | complete and should include point, COLLECTION is the completion |
| 2119 | PROPS is a property list for additional information. | 2225 | table to use to complete the entity, and PROPS is a property list |
| 2120 | Currently supported properties are all the properties that can appear in | 2226 | for additional information. Currently supported properties are |
| 2121 | `completion-extra-properties' plus: | 2227 | all 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 | 2229 | completion 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. | 2231 | at point, then instead of reporting a completion failure, the |
| 2126 | As is the case with most hooks, the functions are responsible for | 2232 | completion should try the next completion function. As is the |
| 2233 | case with most hooks, the functions are responsible for | ||
| 2127 | preserving things like point and current buffer. | 2234 | preserving things like point and current buffer. |
| 2128 | 2235 | ||
| 2129 | NOTE: These functions should be cheap to run since they're sometimes | 2236 | NOTE: These functions should be cheap to run since they're sometimes |