Mercurial > emacs
annotate lisp/cedet/semantic/analyze/complete.el @ 110763:0fe64d68a522
Merge changes made in Gnus trunk.
shr.el: Implement table rendering.
shr.el (shr-make-table): Tweak table generation.
shr.el (shr-make-table): Fix typo.
nnimap.el (nnimap-open-connection): Allow tls as a synonym for ssl.
gnus-util.el (gnus-emacs-completing-read): Mapcar collection to list, for XEmacs.
nnimap.el (nnimap-close-server): Implement.
gnus-salt.el: Remove all gnus-carpal stuff -- it's not useful.
nnir.el (nnir-run-imap): Remove spurious space in search string.
message.el (message-idna-to-ascii-rhs-1): Don't bug out on addresses without @ signs.
gnus-sum.el (gnus-widen-article-window): New variable.
shr.el (browse-url): Required.
shr.el (shr-ensure-paragraph): Don't insert a new newline after empty-ish lines.
shr.el (shr-show-alt-text, shr-browse-image): New commands.
gravatar.el (gravatar-retrieved): kill buffer when retrieved.
shr.el (shr-browse-url, shr-copy-url): New commands.
shr.el (shr-render-td): Protect against too-wide text.
spam-report.el (spam-report-url-ping-plain): Don't query about killing the process.
nnimap.el (nnimap-finish-retrieve-group-infos): Message while waiting for data.
shr.el (shr-tag-blockquote): Ensure paragraph after quote, too.
mml-smime.el: Fix gnus-completing-read usage.
shr.el (shr-get-image-data): Ensure against the cache file missing.
nnimap.el (nnimap-open-connection): Give an error if nnimap-stream is unknown.
author | Katsumi Yamaoka <yamaoka@jpl.org> |
---|---|
date | Mon, 04 Oct 2010 22:26:51 +0000 |
parents | a5ad4f188e19 |
children | 376148b31b5e |
rev | line source |
---|---|
104421 | 1 ;;; semantic/analyze/complete.el --- Smart Completions |
2 | |
106815 | 3 ;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
104421 | 4 |
5 ;; Author: Eric M. Ludlam <zappo@gnu.org> | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software: you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation, either version 3 of the License, or | |
12 ;; (at your option) any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
21 | |
22 ;;; Commentary: | |
23 ;; | |
105340 | 24 ;; Calculate smart completions. |
104421 | 25 ;; |
26 ;; Uses the analyzer context routine to determine the best possible | |
27 ;; list of completions. | |
28 ;; | |
29 ;;; History: | |
30 ;; | |
31 ;; Code was moved here from semantic-analyze.el | |
32 | |
33 (require 'semantic/analyze) | |
34 | |
104450
08a15f853c45
lisp/cedet/semantic/edit.el: Add local vars for autoloading.
Chong Yidong <cyd@stupidchicken.com>
parents:
104446
diff
changeset
|
35 ;; For semantic-find-* macros: |
08a15f853c45
lisp/cedet/semantic/edit.el: Add local vars for autoloading.
Chong Yidong <cyd@stupidchicken.com>
parents:
104446
diff
changeset
|
36 (eval-when-compile (require 'semantic/find)) |
08a15f853c45
lisp/cedet/semantic/edit.el: Add local vars for autoloading.
Chong Yidong <cyd@stupidchicken.com>
parents:
104446
diff
changeset
|
37 |
104421 | 38 ;;; Code: |
39 | |
40 ;;; Helper Fcns | |
41 ;; | |
42 ;; | |
104446
df08b7ab0ba0
lisp/cedet/semantic/analyze.el: Add local vars for autoloading.
Chong Yidong <cyd@stupidchicken.com>
parents:
104444
diff
changeset
|
43 ;;;###autoload |
104421 | 44 (define-overloadable-function semantic-analyze-type-constants (type) |
45 "For the tag TYPE, return any constant symbols of TYPE. | |
46 Used as options when completing.") | |
47 | |
48 (defun semantic-analyze-type-constants-default (type) | |
49 "Do nothing with TYPE." | |
50 nil) | |
51 | |
52 (defun semantic-analyze-tags-of-class-list (tags classlist) | |
53 "Return the tags in TAGS that are of classes in CLASSLIST." | |
54 (let ((origc tags)) | |
55 ;; Accept only tags that are of the datatype specified by | |
56 ;; the desired classes. | |
57 (setq tags (apply 'nconc ;; All input lists are permutable. | |
58 (mapcar (lambda (class) | |
59 (semantic-find-tags-by-class class origc)) | |
60 classlist))) | |
61 tags)) | |
62 | |
63 ;;; MAIN completion calculator | |
64 ;; | |
104444
2bf481006ba4
lisp/Makefile.in: Ignore CEDET subdirectories when making subdirs.el.
Chong Yidong <cyd@stupidchicken.com>
parents:
104421
diff
changeset
|
65 ;;;###autoload |
110523
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
66 (define-overloadable-function semantic-analyze-possible-completions (context &rest flags) |
104421 | 67 "Return a list of semantic tags which are possible completions. |
68 CONTEXT is either a position (such as point), or a precalculated | |
69 context. Passing in a context is useful if the caller also needs | |
70 to access parts of the analysis. | |
110523
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
71 The remaining FLAGS arguments are passed to the mode specific completion engine. |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
72 Bad flags should be ignored by modes that don't use them. |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
73 See `semantic-analyze-possible-completions-default' for details on the default FLAGS. |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
74 |
104421 | 75 Completions run through the following filters: |
76 * Elements currently in scope | |
77 * Constants currently in scope | |
78 * Elements match the :prefix in the CONTEXT. | |
79 * Type of the completion matches the type of the context. | |
80 Context type matching can identify the following: | |
81 * No specific type | |
82 * Assignment into a variable of some type. | |
83 * Argument to a function with type constraints. | |
84 When called interactively, displays the list of possible completions | |
85 in a buffer." | |
86 (interactive "d") | |
87 ;; In theory, we don't need the below since the context will | |
88 ;; do it for us. | |
89 ;;(semantic-refresh-tags-safe) | |
90 (with-syntax-table semantic-lex-syntax-table | |
91 (let* ((context (if (semantic-analyze-context-child-p context) | |
92 context | |
93 (semantic-analyze-current-context context))) | |
94 (ans (if (not context) | |
105340 | 95 (error "Nothing to complete") |
104421 | 96 (:override)))) |
97 ;; If interactive, display them. | |
106197
019d906c8f48
* cedet/srecode/map.el (srecode-get-maps):
Chong Yidong <cyd@stupidchicken.com>
parents:
105842
diff
changeset
|
98 (when (called-interactively-p 'any) |
104421 | 99 (with-output-to-temp-buffer "*Possible Completions*" |
100 (semantic-analyze-princ-sequence ans "" (current-buffer))) | |
101 (shrink-window-if-larger-than-buffer | |
102 (get-buffer-window "*Possible Completions*"))) | |
103 ans))) | |
104 | |
110523
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
105 (defun semantic-analyze-possible-completions-default (context &optional flags) |
104421 | 106 "Default method for producing smart completions. |
110523
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
107 Argument CONTEXT is an object specifying the locally derived context. |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
108 The optional argument FLAGS changes which return options are returned. |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
109 FLAGS can be any number of: |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
110 'no-tc - do not apply data-type constraint. |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
111 'no-unique - do not apply unique by name filtering." |
104421 | 112 (let* ((a context) |
113 (desired-type (semantic-analyze-type-constraint a)) | |
114 (desired-class (oref a prefixclass)) | |
115 (prefix (oref a prefix)) | |
116 (prefixtypes (oref a prefixtypes)) | |
117 (completetext nil) | |
118 (completetexttype nil) | |
119 (scope (oref a scope)) | |
110523
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
120 (localvar (when scope (oref scope localvar))) |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
121 (origc nil) |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
122 (c nil) |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
123 (any nil) |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
124 (do-typeconstraint (not (memq 'no-tc flags))) |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
125 (do-unique (not (memq 'no-unique flags))) |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
126 ) |
104421 | 127 |
128 ;; Calculate what our prefix string is so that we can | |
129 ;; find all our matching text. | |
130 (setq completetext (car (reverse prefix))) | |
131 (if (semantic-tag-p completetext) | |
132 (setq completetext (semantic-tag-name completetext))) | |
133 | |
134 (if (and (not completetext) (not desired-type)) | |
135 (error "Nothing to complete")) | |
136 | |
137 (if (not completetext) (setq completetext "")) | |
138 | |
139 ;; This better be a reasonable type, or we should fry it. | |
140 ;; The prefixtypes should always be at least 1 less than | |
141 ;; the prefix since the type is never looked up for the last | |
142 ;; item when calculating a sequence. | |
143 (setq completetexttype (car (reverse prefixtypes))) | |
144 (when (or (not completetexttype) | |
145 (not (and (semantic-tag-p completetexttype) | |
146 (eq (semantic-tag-class completetexttype) 'type)))) | |
147 ;; What should I do here? I think this is an error condition. | |
148 (setq completetexttype nil) | |
149 ;; If we had something that was a completetexttype but it wasn't | |
150 ;; valid, then express our dismay! | |
151 (when (> (length prefix) 1) | |
152 (let* ((errprefix (car (cdr (reverse prefix))))) | |
153 (error "Cannot find types for `%s'" | |
154 (cond ((semantic-tag-p errprefix) | |
155 (semantic-format-tag-prototype errprefix)) | |
156 (t | |
157 (format "%S" errprefix))))) | |
158 )) | |
159 | |
160 ;; There are many places to get our completion stream for. | |
161 ;; Here we go. | |
162 (if completetexttype | |
163 | |
164 (setq c (semantic-find-tags-for-completion | |
165 completetext | |
166 (semantic-analyze-scoped-type-parts completetexttype scope) | |
167 )) | |
168 | |
169 ;; No type based on the completetext. This is a free-range | |
170 ;; var or function. We need to expand our search beyond this | |
171 ;; scope into semanticdb, etc. | |
172 (setq c (nconc | |
173 ;; Argument list and local variables | |
174 (semantic-find-tags-for-completion completetext localvar) | |
175 ;; The current scope | |
110523
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
176 (semantic-find-tags-for-completion completetext (when scope (oref scope fullscope))) |
104421 | 177 ;; The world |
178 (semantic-analyze-find-tags-by-prefix completetext)) | |
179 ) | |
180 ) | |
181 | |
110523
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
182 (let ((loopc c) |
104421 | 183 (dtname (semantic-tag-name desired-type))) |
184 | |
110523
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
185 ;; Save off our first batch of completions |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
186 (setq origc c) |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
187 |
104421 | 188 ;; Reset c. |
189 (setq c nil) | |
190 | |
191 ;; Loop over all the found matches, and catagorize them | |
192 ;; as being possible features. | |
110523
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
193 (while (and loopc do-typeconstraint) |
104421 | 194 |
195 (cond | |
196 ;; Strip operators | |
110523
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
197 ((semantic-tag-get-attribute (car loopc) :operator-flag) |
104421 | 198 nil |
199 ) | |
200 | |
201 ;; If we are completing from within some prefix, | |
202 ;; then we want to exclude constructors and destructors | |
203 ((and completetexttype | |
110523
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
204 (or (semantic-tag-get-attribute (car loopc) :constructor-flag) |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
205 (semantic-tag-get-attribute (car loopc) :destructor-flag))) |
104421 | 206 nil |
207 ) | |
208 | |
209 ;; If there is a desired type, we need a pair of restrictions | |
210 (desired-type | |
211 | |
212 (cond | |
213 ;; Ok, we now have a completion list based on the text we found | |
214 ;; we want to complete on. Now filter that stream against the | |
215 ;; type we want to search for. | |
110523
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
216 ((string= dtname (semantic-analyze-type-to-name (semantic-tag-type (car loopc)))) |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
217 (setq c (cons (car loopc) c)) |
104421 | 218 ) |
219 | |
220 ;; Now anything that is a compound type which could contain | |
221 ;; additional things which are of the desired type | |
110523
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
222 ((semantic-tag-type (car loopc)) |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
223 (let ((att (semantic-analyze-tag-type (car loopc) scope)) |
104421 | 224 ) |
225 (if (and att (semantic-tag-type-members att)) | |
110523
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
226 (setq c (cons (car loopc) c)))) |
104421 | 227 ) |
228 | |
229 ) ; cond | |
230 ); desired type | |
231 | |
232 ;; No desired type, no other restrictions. Just add. | |
233 (t | |
110523
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
234 (setq c (cons (car loopc) c))) |
104421 | 235 |
236 ); cond | |
237 | |
110523
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
238 (setq loopc (cdr loopc))) |
104421 | 239 |
240 (when desired-type | |
241 ;; Some types, like the enum in C, have special constant values that | |
242 ;; we could complete with. Thus, if the target is an enum, we can | |
243 ;; find possible symbol values to fill in that value. | |
244 (let ((constants | |
245 (semantic-analyze-type-constants desired-type))) | |
246 (if constants | |
247 (progn | |
248 ;; Filter | |
249 (setq constants | |
250 (semantic-find-tags-for-completion | |
251 completetext constants)) | |
252 ;; Add to the list | |
253 (setq c (nconc c constants))) | |
254 ))) | |
255 ) | |
256 | |
257 (when desired-class | |
258 (setq c (semantic-analyze-tags-of-class-list c desired-class))) | |
259 | |
110523
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
260 (if do-unique |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
261 (if c |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
262 ;; Pull out trash. |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
263 ;; NOTE TO SELF: Is this too slow? |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
264 (setq c (semantic-unique-tag-table-by-name c)) |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
265 (setq c (semantic-unique-tag-table-by-name origc))) |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
266 (when (not c) |
a5ad4f188e19
Synch Semantic to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
267 (setq c origc))) |
104421 | 268 |
269 ;; All done! | |
270 c)) | |
271 | |
272 (provide 'semantic/analyze/complete) | |
273 | |
104444
2bf481006ba4
lisp/Makefile.in: Ignore CEDET subdirectories when making subdirs.el.
Chong Yidong <cyd@stupidchicken.com>
parents:
104421
diff
changeset
|
274 ;; Local variables: |
2bf481006ba4
lisp/Makefile.in: Ignore CEDET subdirectories when making subdirs.el.
Chong Yidong <cyd@stupidchicken.com>
parents:
104421
diff
changeset
|
275 ;; generated-autoload-file: "../loaddefs.el" |
104450
08a15f853c45
lisp/cedet/semantic/edit.el: Add local vars for autoloading.
Chong Yidong <cyd@stupidchicken.com>
parents:
104446
diff
changeset
|
276 ;; generated-autoload-load-name: "semantic/analyze/complete" |
104444
2bf481006ba4
lisp/Makefile.in: Ignore CEDET subdirectories when making subdirs.el.
Chong Yidong <cyd@stupidchicken.com>
parents:
104421
diff
changeset
|
277 ;; End: |
2bf481006ba4
lisp/Makefile.in: Ignore CEDET subdirectories when making subdirs.el.
Chong Yidong <cyd@stupidchicken.com>
parents:
104421
diff
changeset
|
278 |
105377 | 279 ;; arch-tag: 97071c7e-2459-4e7a-8875-8cc5bbbc1f4d |
104421 | 280 ;;; semantic/analyze/complete.el ends here |