Mercurial > emacs
annotate lisp/completion.el @ 2074:0196b8bce529
entered into RCS
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 09 Mar 1993 05:37:50 +0000 |
parents | dcf780f7ae1b |
children | 2c7997f249eb |
rev | line source |
---|---|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
190
diff
changeset
|
1 ;;; completion.el --- dynamic word-completion code |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
190
diff
changeset
|
2 |
795
c693d56ef36d
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
3 ;; Maintainer: bug-completion@think.com |
c693d56ef36d
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
4 |
c693d56ef36d
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
5 ;;; Commentary: |
c693d56ef36d
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
6 |
56 | 7 ;;; This is a Completion system for GNU Emacs |
8 ;;; | |
9 ;;; E-Mail: | |
10 ;;; Internet: completion@think.com, bug-completion@think.com | |
11 ;;; UUCP: {rutgers,harvard,mit-eddie}!think!completion | |
12 ;;; | |
13 ;;; If you are a new user, we'd appreciate knowing your site name and | |
14 ;;; any comments you have. | |
15 ;;; | |
16 ;;; | |
17 ;;; NO WARRANTY | |
18 ;;; | |
19 ;;; This software is distributed free of charge and is in the public domain. | |
20 ;;; Anyone may use, duplicate or modify this program. Thinking Machines | |
21 ;;; Corporation does not restrict in any way the use of this software by | |
22 ;;; anyone. | |
23 ;;; | |
24 ;;; Thinking Machines Corporation provides absolutely no warranty of any kind. | |
25 ;;; The entire risk as to the quality and performance of this program is with | |
26 ;;; you. In no event will Thinking Machines Corporation be liable to you for | |
27 ;;; damages, including any lost profits, lost monies, or other special, | |
28 ;;; incidental or consequential damages arising out of the use of this program. | |
29 ;;; | |
30 ;;; You must not restrict the distribution of this software. | |
31 ;;; | |
32 ;;; Please keep this notice and author information in any copies you make. | |
33 ;;; | |
34 ;;; 4/90 | |
35 ;;; | |
36 ;;; | |
37 ;;; Advertisement | |
38 ;;;--------------- | |
39 ;;; Try using this. If you are like most you will be happy you did. | |
40 ;;; | |
41 ;;; What to put in .emacs | |
42 ;;;----------------------- | |
43 ;;; (load "completion") ;; If it's not part of the standard band. | |
44 ;;; (initialize-completions) | |
45 ;;; | |
46 ;;; For best results, be sure to byte-compile the file first. | |
47 ;;; | |
48 | |
49 ;;; Authors | |
50 ;;;--------- | |
51 ;;; Jim Salem {salem@think.com} | |
52 ;;; Brewster Kahle {brewster@think.com} | |
53 ;;; Thinking Machines Corporation | |
54 ;;; 245 First St., Cambridge MA 02142 (617) 876-1111 | |
55 ;;; | |
56 ;;; Mailing Lists | |
57 ;;;--------------- | |
58 ;;; | |
59 ;;; Bugs to bug-completion@think.com | |
60 ;;; Comments to completion@think.com | |
61 ;;; Requests to be added completion-request@think.com | |
62 ;;; | |
63 ;;; Availability | |
64 ;;;-------------- | |
65 ;;; Anonymous FTP from think.com | |
66 ;;; | |
67 | |
68 ;;;--------------------------------------------------------------------------- | |
69 ;;; Documentation [Slightly out of date] | |
70 ;;;--------------------------------------------------------------------------- | |
71 ;;; (also check the documentation string of the functions) | |
72 ;;; | |
73 ;;; Introduction | |
74 ;;;--------------- | |
75 ;;; | |
76 ;;; After you type a few characters, pressing the "complete" key inserts | |
77 ;;; the rest of the word you are likely to type. | |
78 ;;; | |
79 ;;; This watches all the words that you type and remembers them. When | |
80 ;;; typing a new word, pressing "complete" (meta-return) "completes" the | |
81 ;;; word by inserting the most recently used word that begins with the | |
82 ;;; same characters. If you press meta-return repeatedly, it cycles | |
83 ;;; through all the words it knows about. | |
84 ;;; | |
85 ;;; If you like the completion then just continue typing, it is as if you | |
86 ;;; entered the text by hand. If you want the inserted extra characters | |
87 ;;; to go away, type control-w or delete. More options are described below. | |
88 ;;; | |
89 ;;; The guesses are made in the order of the most recently "used". Typing | |
90 ;;; in a word and then typing a separator character (such as a space) "uses" | |
91 ;;; the word. So does moving a cursor over the word. If no words are found, | |
92 ;;; it uses an extended version of the dabbrev style completion. | |
93 ;;; | |
94 ;;; You automatically save the completions you use to a file between | |
95 ;;; sessions. | |
96 ;;; | |
97 ;;; Completion enables programmers to enter longer, more descriptive | |
98 ;;; variable names while typing fewer keystrokes than they normally would. | |
99 ;;; | |
100 ;;; | |
101 ;;; Full documentation | |
102 ;;;--------------------- | |
103 ;;; | |
104 ;;; A "word" is any string containing characters with either word or symbol | |
105 ;;; syntax. [E.G. Any alphanumeric string with hypens, underscores, etc.] | |
106 ;;; Unless you change the constants, you must type at least three characters | |
107 ;;; for the word to be recognized. Only words longer than 6 characters are | |
108 ;;; saved. | |
109 ;;; | |
110 ;;; When you load this file, completion will be on. I suggest you use the | |
111 ;;; compiled version (because it is noticibly faster). | |
112 ;;; | |
113 ;;; M-X completion-mode toggles whether or not new words are added to the | |
114 ;;; database by changing the value of *completep*. | |
115 ;;; | |
116 ;;; SAVING/LOADING COMPLETIONS | |
117 ;;; Completions are automatically saved from one session to another | |
118 ;;; (unless *save-completions-p* or *completep* is nil). | |
119 ;;; Loading this file (or calling initialize-completions) causes EMACS | |
120 ;;; to load a completions database for a saved completions file | |
121 ;;; (default: ~/.completions). When you exit, EMACS saves a copy of the | |
122 ;;; completions that you | |
123 ;;; often use. When you next start, EMACS loads in the saved completion file. | |
124 ;;; | |
125 ;;; The number of completions saved depends loosely on | |
126 ;;; *saved-completions-decay-factor*. Completions that have never been | |
127 ;;; inserted via "complete" are not saved. You are encouraged to experiment | |
128 ;;; with different functions (see compute-completion-min-num-uses). | |
129 ;;; | |
130 ;;; Some completions are permanent and are always saved out. These | |
131 ;;; completions have their num-uses slot set to T. Use | |
132 ;;; add-permanent-completion to do this | |
133 ;;; | |
134 ;;; Completions are saved only if *completep* is T. The number of old | |
135 ;;; versions kept of the saved completions file is controlled by | |
136 ;;; *completion-file-versions-kept*. | |
137 ;;; | |
138 ;;; COMPLETE KEY OPTIONS | |
139 ;;; The complete function takes a numeric arguments. | |
140 ;;; control-u :: leave the point at the beginning of the completion rather | |
141 ;;; than the middle. | |
142 ;;; a number :: rotate through the possible completions by that amount | |
143 ;;; `-' :: same as -1 (insert previous completion) | |
144 ;;; | |
145 ;;; HOW THE DATABASE IS MAINTAINED | |
146 ;;; <write> | |
147 ;;; | |
148 ;;; UPDATING THE DATABASE MANUALLY | |
149 ;;; m-x kill-completion | |
150 ;;; kills the completion at point. | |
151 ;;; m-x add-completion | |
152 ;;; m-x add-permanent-completion | |
153 ;;; | |
154 ;;; UPDATING THE DATABASE FROM A SOURCE CODE FILE | |
155 ;;; m-x add-completions-from-buffer | |
156 ;;; Parses all the definition names from a C or LISP mode buffer and | |
157 ;;; adds them to the completion database. | |
158 ;;; | |
159 ;;; m-x add-completions-from-lisp-file | |
160 ;;; Parses all the definition names from a C or Lisp mode file and | |
161 ;;; adds them to the completion database. | |
162 ;;; | |
163 ;;; UPDATING THE DATABASE FROM A TAGS TABLE | |
164 ;;; m-x add-completions-from-tags-table | |
165 ;;; Adds completions from the current tags-table-buffer. | |
166 ;;; | |
167 ;;; HOW A COMPLETION IS FOUND | |
168 ;;; <write> | |
169 ;;; | |
170 ;;; STRING CASING | |
171 ;;; Completion is string case independent if case-fold-search has its | |
172 ;;; normal default of T. Also when the completion is inserted the case of the | |
173 ;;; entry is coerced appropriately. | |
174 ;;; [E.G. APP --> APPROPRIATELY app --> appropriately | |
175 ;;; App --> Appropriately] | |
176 ;;; | |
177 ;;; INITIALIZATION | |
178 ;;; The form `(initialize-completions)' initializes the completion system by | |
179 ;;; trying to load in the user's completions. After the first cal, further | |
180 ;;; calls have no effect so one should be careful not to put the form in a | |
181 ;;; site's standard site-init file. | |
182 ;;; | |
183 ;;;--------------------------------------------------------------------------- | |
184 ;;; | |
185 ;;; | |
186 | |
187 ;;;----------------------------------------------- | |
188 ;;; Porting Notes | |
189 ;;;----------------------------------------------- | |
190 ;;; | |
191 ;;; Should run on 18.49, 18.52, and 19.0 | |
192 ;;; Tested on vanilla version. | |
193 ;;; This requires the standard cl.el file. It could easily rewritten to not | |
194 ;;; require it. It defines remove which is not in cl.el. | |
195 ;;; | |
196 ;;; FUNCTIONS BASHED | |
197 ;;; The following functions are bashed but it is done carefully and should not | |
198 ;;; cause problems :: | |
199 ;;; kill-region, next-line, previous-line, newline, newline-and-indent, | |
200 ;;; kill-emacs | |
201 ;;; | |
202 ;;; | |
203 ;;;--------------------------------------------------------------------------- | |
204 ;;; Functions you might like to call | |
205 ;;;--------------------------------------------------------------------------- | |
206 ;;; | |
207 ;;; add-completion string &optional num-uses | |
208 ;;; Adds a new string to the database | |
209 ;;; | |
210 ;;; add-permanent-completion string | |
211 ;;; Adds a new string to the database with num-uses = T | |
212 ;;; | |
213 | |
214 ;;; kill-completion string | |
215 ;;; Kills the completion from the database. | |
216 ;;; | |
217 ;;; clear-all-completions | |
218 ;;; Clears the database | |
219 ;;; | |
220 ;;; list-all-completions | |
221 ;;; Returns a list of all completions. | |
222 ;;; | |
223 ;;; | |
224 ;;; next-completion string &optional index | |
225 ;;; Returns a completion entry that starts with string. | |
226 ;;; | |
227 ;;; find-exact-completion string | |
228 ;;; Returns a completion entry that exactly matches string. | |
229 ;;; | |
230 ;;; complete | |
231 ;;; Inserts a completion at point | |
232 ;;; | |
233 ;;; initialize-completions | |
234 ;;; Loads the completions file and sets up so that exiting emacs will | |
235 ;;; save them. | |
236 ;;; | |
237 ;;; save-completions-to-file &optional filename | |
238 ;;; load-completions-from-file &optional filename | |
239 ;;; | |
240 ;;;----------------------------------------------- | |
241 ;;; Other functions | |
242 ;;;----------------------------------------------- | |
243 ;;; | |
244 ;;; get-completion-list string | |
245 ;;; | |
246 ;;; These things are for manipulating the structure | |
247 ;;; make-completion string num-uses | |
248 ;;; completion-num-uses completion | |
249 ;;; completion-string completion | |
250 ;;; set-completion-num-uses completion num-uses | |
251 ;;; set-completion-string completion string | |
252 ;;; | |
253 ;;; | |
254 | |
255 ;;;----------------------------------------------- | |
256 ;;; To Do :: (anybody ?) | |
257 ;;;----------------------------------------------- | |
258 ;;; | |
259 ;;; Implement Lookup and keyboard interface in C | |
260 ;;; Add package prefix smarts (for Common Lisp) | |
261 ;;; Add autoprompting of possible completions after every keystroke (fast | |
262 ;;; terminals only !) | |
263 ;;; Add doc. to texinfo | |
264 ;;; | |
265 ;;; | |
266 ;;;----------------------------------------------- | |
795
c693d56ef36d
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
267 ;;; Change Log: |
56 | 268 ;;;----------------------------------------------- |
269 ;;; Sometime in '84 Brewster implemented a somewhat buggy version for | |
270 ;;; Symbolics LISPMs. | |
271 ;;; Jan. '85 Jim became enamored of the idea and implemented a faster, | |
272 ;;; more robust version. | |
273 ;;; With input from many users at TMC, (rose, craig, and gls come to mind), | |
274 ;;; the current style of interface was developed. | |
275 ;;; 9/87, Jim and Brewster took terminals home. Yuck. After | |
276 ;;; complaining for a while Brewester implemented a subset of the current | |
277 ;;; LISPM version for GNU Emacs. | |
278 ;;; 8/88 After complaining for a while (and with sufficient | |
279 ;;; promised rewards), Jim reimplemented a version of GNU completion | |
280 ;;; superior to that of the LISPM version. | |
281 ;;; | |
282 ;;;----------------------------------------------- | |
283 ;;; Acknowlegements | |
284 ;;;----------------------------------------------- | |
285 ;;; Cliff Lasser (cal@think.com), Kevin Herbert (kph@cisco.com), | |
286 ;;; eero@media-lab, kgk@cs.brown.edu, jla@ai.mit.edu, | |
287 ;;; | |
288 ;;;----------------------------------------------- | |
289 ;;; Change Log | |
290 ;;;----------------------------------------------- | |
291 ;;; From version 9 to 10 | |
292 ;;; - Allowance for non-integral *completion-version* nos. | |
293 ;;; - Fix cmpl-apply-as-top-level for keyboard macros | |
294 ;;; - Fix broken completion merging (in save-completions-to-file) | |
295 ;;; - More misc. fixes for version 19.0 of emacs | |
296 ;;; | |
297 ;;; From Version 8 to 9 | |
298 ;;; - Ported to version 19.0 of emacs (backcompatible with version 18) | |
299 ;;; - Added add-completions-from-tags-table (with thanks to eero@media-lab) | |
300 ;;; | |
301 ;;; From Version 7 to 8 | |
302 ;;; - Misc. changes to comments | |
303 ;;; - new completion key bindings: c-x o, M->, M-<, c-a, c-e | |
304 ;;; - cdabbrev now checks all the visible window buffers and the "other buffer" | |
305 ;;; - `%' is now a symbol character rather than a separator (except in C mode) | |
306 ;;; | |
307 ;;; From Version 6 to 7 | |
308 ;;; - Fixed bug with saving out .completion file the first time | |
309 ;;; | |
310 ;;; From Version 5 to 6 | |
311 ;;; - removed statistics recording | |
312 ;;; - reworked advise to handle autoloads | |
313 ;;; - Fixed fortran mode support | |
314 ;;; - Added new cursor motion triggers | |
315 ;;; | |
316 ;;; From Version 4 to 5 | |
317 ;;; - doesn't bother saving if nothing has changed | |
318 ;;; - auto-save if haven't used for a 1/2 hour | |
319 ;;; - save period extended to two weeks | |
320 ;;; - minor fix to capitalization code | |
321 ;;; - added *completion-auto-save-period* to variables recorded. | |
322 ;;; - added reenter protection to cmpl-record-statistics-filter | |
323 ;;; - added backup protection to save-completions-to-file (prevents | |
324 ;;; problems with disk full errors) | |
325 | |
795
c693d56ef36d
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
326 ;;; Code: |
c693d56ef36d
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
327 |
56 | 328 ;;;----------------------------------------------- |
329 ;;; Requires | |
330 ;;; Version | |
331 ;;;----------------------------------------------- | |
332 | |
333 ;;(require 'cl) ;; DOTIMES, etc. {actually done after variable defs.} | |
334 | |
335 (defconst *completion-version* 10 | |
336 "Tested for EMACS versions 18.49, 18.52, 18.55 and beyond and 19.0.") | |
337 | |
338 ;;;--------------------------------------------------------------------------- | |
339 ;;; User changeable parameters | |
340 ;;;--------------------------------------------------------------------------- | |
341 | |
342 (defvar *completep* t | |
343 "*Set to nil to turn off the completion hooks. | |
190 | 344 (No new words added to the database or saved to the init file).") |
56 | 345 |
346 (defvar *save-completions-p* t | |
347 "*If non-nil, the most useful completions are saved to disk when | |
348 exiting EMACS. See *saved-completions-decay-factor*.") | |
349 | |
350 (defvar *saved-completions-filename* "~/.completions" | |
351 "*The filename to save completions to.") | |
352 | |
353 (defvar *saved-completion-retention-time* 336 | |
190 | 354 "*The maximum amount of time to save a completion for if it has not been used. |
56 | 355 In hours. (1 day = 24, 1 week = 168). If this is 0, non-permanent completions |
190 | 356 will not be saved unless these are used. Default is two weeks.") |
56 | 357 |
358 (defvar *separator-character-uses-completion-p* nil | |
359 "*If non-nil, typing a separator character after a completion symbol that | |
360 is not part of the database marks it as used (so it will be saved).") | |
361 | |
362 (defvar *completion-file-versions-kept* kept-new-versions | |
363 "*Set this to the number of versions you want save-completions-to-file | |
364 to keep.") | |
365 | |
366 (defvar *print-next-completion-speed-threshold* 4800 | |
367 "*The baud rate at or above which to print the next potential completion | |
368 after inserting the current one." | |
369 ) | |
370 | |
371 (defvar *print-next-completion-does-cdabbrev-search-p* nil | |
190 | 372 "*If non-nil, the next completion prompt will also do a cdabbrev search. |
56 | 373 This can be time consuming.") |
374 | |
375 (defvar *cdabbrev-radius* 15000 | |
376 "*How far to search for cdabbrevs. In number of characters. If nil, the | |
377 whole buffer is searched.") | |
378 | |
379 (defvar *modes-for-completion-find-file-hook* '(lisp c) | |
190 | 380 "*A list of modes {either C or Lisp}. Definitions from visited files |
56 | 381 of those types are automatically added to the completion database.") |
382 | |
383 (defvar *record-cmpl-statistics-p* nil | |
384 "*If non-nil, statistics are automatically recorded.") | |
385 | |
386 (defvar *completion-auto-save-period* 1800 | |
387 "*The period in seconds to wait for emacs to be idle before autosaving | |
388 the completions. Default is a 1/2 hour.") | |
389 | |
390 (defconst *completion-min-length* nil ;; defined below in eval-when | |
391 "*The minimum length of a stored completion. | |
392 DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.") | |
393 | |
394 (defconst *completion-max-length* nil ;; defined below in eval-when | |
395 "*The maximum length of a stored completion. | |
396 DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.") | |
397 | |
398 (defconst *completion-prefix-min-length* nil ;; defined below in eval-when | |
399 "The minimum length of a completion search string. | |
400 DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.") | |
401 | |
402 (defmacro eval-when-compile-load-eval (&rest body) | |
403 ;; eval everything before expanding | |
404 (mapcar 'eval body) | |
190 | 405 (cons 'progn body)) |
56 | 406 |
407 (defun completion-eval-when () | |
408 (eval-when-compile-load-eval | |
409 ;; These vars. are defined at both compile and load time. | |
410 (setq *completion-min-length* 6) | |
411 (setq *completion-max-length* 200) | |
412 (setq *completion-prefix-min-length* 3) | |
413 ;; Need this file around too | |
190 | 414 (require 'cl))) |
56 | 415 |
416 (completion-eval-when) | |
417 | |
418 ;;;--------------------------------------------------------------------------- | |
419 ;;; Internal Variables | |
420 ;;;--------------------------------------------------------------------------- | |
421 | |
422 (defvar cmpl-initialized-p nil | |
190 | 423 "Set to t when the completion system is initialized. Indicates that the |
424 old completion file has been read in.") | |
56 | 425 |
426 (defvar cmpl-completions-accepted-p nil | |
427 "Set to T as soon as the first completion has been accepted. Used to | |
428 decide whether to save completions.") | |
429 | |
430 | |
431 ;;;--------------------------------------------------------------------------- | |
432 ;;; Low level tools | |
433 ;;;--------------------------------------------------------------------------- | |
434 | |
435 ;;;----------------------------------------------- | |
436 ;;; Misc. | |
437 ;;;----------------------------------------------- | |
438 | |
439 (defun remove (item list) | |
440 (setq list (copy-sequence list)) | |
190 | 441 (delq item list)) |
56 | 442 |
443 (defun minibuffer-window-selected-p () | |
444 "True iff the current window is the minibuffer." | |
445 (eq (minibuffer-window) (selected-window))) | |
446 | |
447 (eval-when-compile-load-eval | |
448 (defun function-needs-autoloading-p (symbol) | |
449 ;; True iff symbol is represents an autoloaded function and has not yet been | |
450 ;; autoloaded. | |
451 (and (listp (symbol-function symbol)) | |
452 (eq 'autoload (car (symbol-function symbol))) | |
190 | 453 ))) |
56 | 454 |
455 (defun function-defined-and-loaded (symbol) | |
456 ;; True iff symbol is bound to a loaded function. | |
190 | 457 (and (fboundp symbol) (not (function-needs-autoloading-p symbol)))) |
56 | 458 |
459 (defmacro read-time-eval (form) | |
460 ;; Like the #. reader macro | |
190 | 461 (eval form)) |
56 | 462 |
463 ;;;----------------------------------------------- | |
464 ;;; Emacs Version 19 compatibility | |
465 ;;;----------------------------------------------- | |
466 | |
467 (defconst emacs-is-version-19 (string= (substring emacs-version 0 2) "19")) | |
468 | |
469 (defun cmpl19-baud-rate () | |
470 (if emacs-is-version-19 | |
471 baud-rate | |
472 (baud-rate))) | |
473 | |
474 (defun cmpl19-sit-for (amount) | |
475 (if (and emacs-is-version-19 (= amount 0)) | |
476 (sit-for 1 t) | |
477 (sit-for amount))) | |
478 | |
479 ;;;----------------------------------------------- | |
480 ;;; Advise | |
481 ;;;----------------------------------------------- | |
482 | |
483 (defmacro completion-advise (function-name where &rest body) | |
484 "Adds the body code before calling function. This advise is not compiled. | |
485 WHERE is either :BEFORE or :AFTER." | |
486 (completion-advise-1 function-name where body) | |
487 ) | |
488 | |
489 (defmacro cmpl-apply-as-top-level (function arglist) | |
490 "Calls function-name interactively if inside a call-interactively." | |
491 (list 'cmpl-apply-as-top-level-1 function arglist | |
492 '(let ((executing-macro nil)) (interactive-p))) | |
493 ) | |
494 | |
495 (defun cmpl-apply-as-top-level-1 (function arglist interactive-p) | |
496 (if (and interactive-p (commandp function)) | |
497 (call-interactively function) | |
498 (apply function arglist) | |
499 )) | |
500 | |
501 (eval-when-compile-load-eval | |
502 | |
503 (defun cmpl-defun-preamble (function-name) | |
504 (let ((doc-string | |
505 (condition-case e | |
506 ;; This condition-case is here to stave | |
507 ;; off bizarre load time errors 18.52 gets | |
508 ;; on the function c-mode | |
509 (documentation function-name) | |
510 (error nil))) | |
511 (interactivep (commandp function-name)) | |
512 ) | |
513 (append | |
514 (if doc-string (list doc-string)) | |
515 (if interactivep '((interactive))) | |
516 ))) | |
517 | |
518 (defun completion-advise-1 (function-name where body &optional new-name) | |
519 (unless new-name (setq new-name function-name)) | |
520 (let ((quoted-name (list 'quote function-name)) | |
521 (quoted-new-name (list 'quote new-name)) | |
522 ) | |
523 | |
524 (cond ((function-needs-autoloading-p function-name) | |
525 (list* 'defun function-name '(&rest arglist) | |
526 (append | |
527 (cmpl-defun-preamble function-name) | |
528 (list (list 'load (second (symbol-function function-name))) | |
529 (list 'eval | |
530 (list 'completion-advise-1 quoted-name | |
531 (list 'quote where) (list 'quote body) | |
532 quoted-new-name)) | |
533 (list 'cmpl-apply-as-top-level quoted-new-name 'arglist) | |
534 ))) | |
535 ) | |
536 (t | |
537 (let ((old-def-name | |
538 (intern (concat "$$$cmpl-" (symbol-name function-name)))) | |
539 ) | |
540 | |
541 (list 'progn | |
542 (list 'defvar old-def-name | |
543 (list 'symbol-function quoted-name)) | |
544 (list* 'defun new-name '(&rest arglist) | |
545 (append | |
546 (cmpl-defun-preamble function-name) | |
547 (ecase where | |
548 (:before | |
549 (list (cons 'progn body) | |
550 (list 'cmpl-apply-as-top-level | |
551 old-def-name 'arglist))) | |
552 (:after | |
553 (list* (list 'cmpl-apply-as-top-level | |
554 old-def-name 'arglist) | |
555 body) | |
556 ))) | |
557 ))) | |
558 )))) | |
559 ) ;; eval-when | |
560 | |
561 | |
562 ;;;----------------------------------------------- | |
563 ;;; String case coercion | |
564 ;;;----------------------------------------------- | |
565 | |
566 (defun cmpl-string-case-type (string) | |
567 "Returns :capitalized, :up, :down, :mixed, or :neither." | |
568 (let ((case-fold-search nil)) | |
569 (cond ((string-match "[a-z]" string) | |
570 (cond ((string-match "[A-Z]" string) | |
571 (cond ((and (> (length string) 1) | |
572 (null (string-match "[A-Z]" string 1))) | |
573 ':capitalized) | |
574 (t | |
575 ':mixed))) | |
576 (t ':down))) | |
577 (t | |
578 (cond ((string-match "[A-Z]" string) | |
579 ':up) | |
580 (t ':neither)))) | |
581 )) | |
582 | |
583 ;;; Tests - | |
584 ;;; (cmpl-string-case-type "123ABCDEF456") --> :up | |
585 ;;; (cmpl-string-case-type "123abcdef456") --> :down | |
586 ;;; (cmpl-string-case-type "123aBcDeF456") --> :mixed | |
587 ;;; (cmpl-string-case-type "123456") --> :neither | |
588 ;;; (cmpl-string-case-type "Abcde123") --> :capitalized | |
589 | |
590 (defun cmpl-coerce-string-case (string case-type) | |
591 (cond ((eq case-type ':down) (downcase string)) | |
592 ((eq case-type ':up) (upcase string)) | |
593 ((eq case-type ':capitalized) | |
594 (setq string (downcase string)) | |
595 (aset string 0 (logand ?\337 (aref string 0))) | |
596 string) | |
597 (t string) | |
598 )) | |
599 | |
600 (defun cmpl-merge-string-cases (string-to-coerce given-string) | |
601 (let ((string-case-type (cmpl-string-case-type string-to-coerce)) | |
602 ) | |
603 (cond ((memq string-case-type '(:down :up :capitalized)) | |
604 ;; Found string is in a standard case. Coerce to a type based on | |
605 ;; the given string | |
606 (cmpl-coerce-string-case string-to-coerce | |
607 (cmpl-string-case-type given-string)) | |
608 ) | |
609 (t | |
610 ;; If the found string is in some unusual case, just insert it | |
611 ;; as is | |
612 string-to-coerce) | |
613 ))) | |
614 | |
615 ;;; Tests - | |
616 ;;; (cmpl-merge-string-cases "AbCdEf456" "abc") --> AbCdEf456 | |
617 ;;; (cmpl-merge-string-cases "abcdef456" "ABC") --> ABCDEF456 | |
618 ;;; (cmpl-merge-string-cases "ABCDEF456" "Abc") --> Abcdef456 | |
619 ;;; (cmpl-merge-string-cases "ABCDEF456" "abc") --> abcdef456 | |
620 | |
621 | |
622 ;;;----------------------------------------------- | |
623 ;;; Emacs Idle Time hooks | |
624 ;;;----------------------------------------------- | |
625 | |
626 (defvar cmpl-emacs-idle-process nil) | |
627 | |
628 (defvar cmpl-emacs-idle-interval 150 | |
190 | 629 "Seconds between running the Emacs idle process.") |
56 | 630 |
631 (defun init-cmpl-emacs-idle-process () | |
632 "Initialize the emacs idle process." | |
633 (let ((live (and cmpl-emacs-idle-process | |
634 (eq (process-status cmpl-emacs-idle-process) 'run))) | |
635 ;; do not allocate a pty | |
636 (process-connection-type nil)) | |
637 (if live | |
638 (kill-process cmpl-emacs-idle-process)) | |
639 (if cmpl-emacs-idle-process | |
640 (delete-process cmpl-emacs-idle-process)) | |
641 (setq cmpl-emacs-idle-process | |
642 (start-process "cmpl-emacs-idle" nil | |
643 "loadst" | |
644 "-n" (int-to-string cmpl-emacs-idle-interval))) | |
645 (process-kill-without-query cmpl-emacs-idle-process) | |
646 (set-process-filter cmpl-emacs-idle-process 'cmpl-emacs-idle-filter) | |
647 )) | |
648 | |
649 (defvar cmpl-emacs-buffer nil) | |
650 (defvar cmpl-emacs-point 0) | |
651 (defvar cmpl-emacs-last-command nil) | |
652 (defvar cmpl-emacs-last-command-char nil) | |
653 (defun cmpl-emacs-idle-p () | |
654 ;; returns T if emacs has been idle | |
655 (if (and (eq cmpl-emacs-buffer (current-buffer)) | |
656 (= cmpl-emacs-point (point)) | |
657 (eq cmpl-emacs-last-command last-command) | |
658 (eq last-command-char last-command-char) | |
659 ) | |
660 t ;; idle | |
661 ;; otherwise, update count | |
662 (setq cmpl-emacs-buffer (current-buffer)) | |
663 (setq cmpl-emacs-point (point)) | |
664 (setq cmpl-emacs-last-command last-command) | |
665 (setq last-command-char last-command-char) | |
666 nil | |
667 )) | |
668 | |
669 (defvar cmpl-emacs-idle-time 0 | |
190 | 670 "The idle time of Emacs in seconds.") |
56 | 671 |
672 (defvar inside-cmpl-emacs-idle-filter nil) | |
673 (defvar cmpl-emacs-idle-time-hooks nil) | |
674 | |
675 (defun cmpl-emacs-idle-filter (proc string) | |
676 ;; This gets called every cmpl-emacs-idle-interval seconds | |
677 ;; Update idle time clock | |
678 (if (cmpl-emacs-idle-p) | |
679 (incf cmpl-emacs-idle-time cmpl-emacs-idle-interval) | |
680 (setq cmpl-emacs-idle-time 0)) | |
681 | |
682 (unless inside-cmpl-emacs-idle-filter | |
683 ;; Don't reenter if we are hung | |
684 | |
685 (setq inside-cmpl-emacs-idle-filter t) | |
686 | |
687 (dolist (function cmpl-emacs-idle-time-hooks) | |
688 (condition-case e | |
689 (funcall function) | |
690 (error nil) | |
691 )) | |
692 (setq inside-cmpl-emacs-idle-filter nil) | |
693 )) | |
694 | |
695 | |
696 ;;;----------------------------------------------- | |
697 ;;; Time | |
698 ;;;----------------------------------------------- | |
190 | 699 ;;; What a backwards way to get the time! Unfortunately, GNU Emacs |
56 | 700 ;;; doesn't have an accessible time function. |
701 | |
702 (defconst cmpl-hours-per-day 24) | |
703 (defconst cmpl-hours-per-year (* 365 cmpl-hours-per-day)) | |
704 (defconst cmpl-hours-per-4-years (+ (* 4 cmpl-hours-per-year) | |
705 cmpl-hours-per-day)) | |
706 (defconst cmpl-days-since-start-of-year | |
707 '(0 31 59 90 120 151 181 212 243 273 304 334)) | |
708 (defconst cmpl-days-since-start-of-leap-year | |
709 '(0 31 60 91 121 152 182 213 244 274 305 335)) | |
710 (defconst cmpl-months | |
190 | 711 '("Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec")) |
56 | 712 |
713 (defun cmpl-hours-since-1900-internal (month day year hours) | |
714 "Month is an integer from 1 to 12. Year is a two digit integer (19XX)" | |
715 (+ ;; Year | |
716 (* (/ (1- year) 4) cmpl-hours-per-4-years) | |
717 (* (1+ (mod (1- year) 4)) cmpl-hours-per-year) | |
718 ;; minus two to account for 1968 rather than 1900 | |
719 ;; month | |
720 (* cmpl-hours-per-day | |
721 (nth (1- month) (if (zerop (mod year 4)) | |
722 cmpl-days-since-start-of-leap-year | |
723 cmpl-days-since-start-of-year))) | |
724 (* (1- day) cmpl-hours-per-day) | |
190 | 725 hours)) |
56 | 726 |
727 (defun cmpl-month-from-string (month-string) | |
728 "Month string is a three char. month string" | |
729 (let ((count 1)) | |
730 (do ((list cmpl-months (cdr list)) | |
731 ) | |
732 ((or (null list) (string-equal month-string (car list)))) | |
733 (setq count (1+ count))) | |
734 (if (> count 12) | |
735 (error "Unknown month - %s" month-string)) | |
736 count)) | |
737 | |
738 (defun cmpl-hours-since-1900 (&optional time-string) | |
739 "String is a string in the format of current-time-string (the default)." | |
740 (let* ((string (or time-string (current-time-string))) | |
741 (month (cmpl-month-from-string (substring string 4 7))) | |
742 (day (string-to-int (substring string 8 10))) | |
743 (year (string-to-int (substring string 22 24))) | |
744 (hour (string-to-int (substring string 11 13))) | |
745 ) | |
190 | 746 (cmpl-hours-since-1900-internal month day year hour))) |
56 | 747 |
748 ;;; Tests - | |
749 ;;;(cmpl-hours-since-1900 "Wed Jan 1 00:00:28 1900") --> 35040 | |
750 ;;;(cmpl-hours-since-1900 "Wed Nov 2 23:00:28 1988") --> 778751 | |
751 ;;;(cmpl-hours-since-1900 "Wed Jan 23 14:34:28 1988") --> 771926 | |
752 ;;;(cmpl-hours-since-1900 "Wed Feb 23 14:34:28 1988") --> 772670 | |
753 ;;;(cmpl-hours-since-1900 "Wed Mar 23 14:34:28 1988") --> 773366 | |
754 ;;;(cmpl-hours-since-1900 "Wed Apr 23 14:34:28 1988") --> 774110 | |
755 ;;;(cmpl-hours-since-1900 "Wed May 23 14:34:28 1988") --> 774830 | |
756 ;;;(cmpl-hours-since-1900 "Wed Jun 23 14:34:28 1988") --> 775574 | |
757 ;;;(cmpl-hours-since-1900 "Wed Jul 23 14:34:28 1988") --> 776294 | |
758 ;;;(cmpl-hours-since-1900 "Wed Aug 23 14:34:28 1988") --> 777038 | |
759 ;;;(cmpl-hours-since-1900 "Wed Sep 23 14:34:28 1988") --> 777782 | |
760 ;;;(cmpl-hours-since-1900 "Wed Oct 23 14:34:28 1988") --> 778502 | |
761 ;;;(cmpl-hours-since-1900 "Wed Nov 23 14:34:28 1988") --> 779246 | |
762 ;;;(cmpl-hours-since-1900 "Wed Dec 23 14:34:28 1988") --> 779966 | |
763 ;;;(cmpl-hours-since-1900 "Wed Jan 23 14:34:28 1957") --> 500198 | |
764 ;;;(cmpl-hours-since-1900 "Wed Feb 23 14:34:28 1957") --> 500942 | |
765 ;;;(cmpl-hours-since-1900 "Wed Mar 23 14:34:28 1957") --> 501614 | |
766 ;;;(cmpl-hours-since-1900 "Wed Apr 23 14:34:28 1957") --> 502358 | |
767 ;;;(cmpl-hours-since-1900 "Wed May 23 14:34:28 1957") --> 503078 | |
768 ;;;(cmpl-hours-since-1900 "Wed Jun 23 14:34:28 1957") --> 503822 | |
769 ;;;(cmpl-hours-since-1900 "Wed Jul 23 14:34:28 1957") --> 504542 | |
770 ;;;(cmpl-hours-since-1900 "Wed Aug 23 14:34:28 1957") --> 505286 | |
771 ;;;(cmpl-hours-since-1900 "Wed Sep 23 14:34:28 1957") --> 506030 | |
772 ;;;(cmpl-hours-since-1900 "Wed Oct 23 14:34:28 1957") --> 506750 | |
773 ;;;(cmpl-hours-since-1900 "Wed Nov 23 14:34:28 1957") --> 507494 | |
774 ;;;(cmpl-hours-since-1900 "Wed Dec 23 14:34:28 1957") --> 508214 | |
775 | |
776 | |
777 ;;;--------------------------------------------------------------------------- | |
778 ;;; "Symbol" parsing functions | |
779 ;;;--------------------------------------------------------------------------- | |
780 ;;; The functions symbol-before-point, symbol-under-point, etc. quickly return | |
781 ;;; an appropriate symbol string. The strategy is to temporarily change | |
782 ;;; the syntax table to enable fast symbol searching. There are three classes | |
783 ;;; of syntax in these "symbol" syntax tables :: | |
784 ;;; | |
785 ;;; syntax (?_) - "symbol" chars (e.g. alphanumerics) | |
786 ;;; syntax (?w) - symbol chars to ignore at end of words (e.g. period). | |
787 ;;; syntax (? ) - everything else | |
788 ;;; | |
789 ;;; Thus by judicious use of scan-sexps and forward-word, we can get | |
790 ;;; the word we want relatively fast and without consing. | |
791 ;;; | |
792 ;;; Why do we need a separate category for "symbol chars to ignore at ends" ? | |
793 ;;; For example, in LISP we want starting :'s trimmed | |
794 ;;; so keyword argument specifiers also define the keyword completion. And, | |
795 ;;; for example, in C we want `.' appearing in a structure ref. to | |
796 ;;; be kept intact in order to store the whole structure ref.; however, if | |
797 ;;; it appears at the end of a symbol it should be discarded because it is | |
798 ;;; probably used as a period. | |
799 | |
800 ;;; Here is the default completion syntax :: | |
801 ;;; Symbol chars :: A-Z a-z 0-9 @ / \ * + ~ $ < > % | |
802 ;;; Symbol chars to ignore at ends :: _ : . - | |
803 ;;; Separator chars. :: <tab> <space> ! ^ & ( ) = ` | { } [ ] ; " ' # | |
804 ;;; , ? <Everything else> | |
805 | |
806 ;;; Mode specific differences and notes :: | |
807 ;;; LISP diffs -> | |
808 ;;; Symbol chars :: ! & ? = ^ | |
809 ;;; | |
810 ;;; C diffs -> | |
811 ;;; Separator chars :: + * / : % | |
812 ;;; A note on the hypen (`-'). Perhaps, the hypen should also be a separator | |
813 ;;; char., however, we wanted to have completion symbols include pointer | |
814 ;;; references. For example, "foo->bar" is a symbol as far as completion is | |
815 ;;; concerned. | |
816 ;;; | |
817 ;;; FORTRAN diffs -> | |
818 ;;; Separator chars :: + - * / : | |
819 ;;; | |
820 ;;; Pathname diffs -> | |
821 ;;; Symbol chars :: . | |
822 ;;; Of course there is no pathname "mode" and in fact we have not implemented | |
823 ;;; this table. However, if there was such a mode, this is what it would look | |
824 ;;; like. | |
825 | |
826 ;;;----------------------------------------------- | |
827 ;;; Table definitions | |
828 ;;;----------------------------------------------- | |
829 | |
830 (defun make-standard-completion-syntax-table () | |
831 (let ((table (make-vector 256 0)) ;; default syntax is whitespace | |
832 ) | |
833 ;; alpha chars | |
834 (dotimes (i 26) | |
835 (modify-syntax-entry (+ ?a i) "_" table) | |
836 (modify-syntax-entry (+ ?A i) "_" table)) | |
837 ;; digit chars. | |
838 (dotimes (i 10) | |
839 (modify-syntax-entry (+ ?0 i) "_" table)) | |
840 ;; Other ones | |
841 (let ((symbol-chars '(?@ ?/ ?\\ ?* ?+ ?~ ?$ ?< ?> ?%)) | |
842 (symbol-chars-ignore '(?_ ?- ?: ?.)) | |
843 ) | |
844 (dolist (char symbol-chars) | |
845 (modify-syntax-entry char "_" table)) | |
846 (dolist (char symbol-chars-ignore) | |
847 (modify-syntax-entry char "w" table) | |
848 ) | |
849 ) | |
850 table)) | |
851 | |
852 (defconst cmpl-standard-syntax-table (make-standard-completion-syntax-table)) | |
853 | |
854 (defun make-lisp-completion-syntax-table () | |
855 (let ((table (copy-syntax-table cmpl-standard-syntax-table)) | |
856 (symbol-chars '(?! ?& ?? ?= ?^)) | |
857 ) | |
858 (dolist (char symbol-chars) | |
859 (modify-syntax-entry char "_" table)) | |
860 table)) | |
861 | |
862 (defun make-c-completion-syntax-table () | |
863 (let ((table (copy-syntax-table cmpl-standard-syntax-table)) | |
864 (separator-chars '(?+ ?* ?/ ?: ?%)) | |
865 ) | |
866 (dolist (char separator-chars) | |
867 (modify-syntax-entry char " " table)) | |
868 table)) | |
869 | |
870 (defun make-fortran-completion-syntax-table () | |
871 (let ((table (copy-syntax-table cmpl-standard-syntax-table)) | |
872 (separator-chars '(?+ ?- ?* ?/ ?:)) | |
873 ) | |
874 (dolist (char separator-chars) | |
875 (modify-syntax-entry char " " table)) | |
876 table)) | |
877 | |
878 (defconst cmpl-lisp-syntax-table (make-lisp-completion-syntax-table)) | |
879 (defconst cmpl-c-syntax-table (make-c-completion-syntax-table)) | |
880 (defconst cmpl-fortran-syntax-table (make-fortran-completion-syntax-table)) | |
881 | |
882 (defvar cmpl-syntax-table cmpl-standard-syntax-table | |
883 "This variable holds the current completion syntax table.") | |
884 (make-variable-buffer-local 'cmpl-syntax-table) | |
885 | |
886 ;;;----------------------------------------------- | |
887 ;;; Installing the appropriate mode tables | |
888 ;;;----------------------------------------------- | |
889 | |
890 (completion-advise lisp-mode-variables :after | |
891 (setq cmpl-syntax-table cmpl-lisp-syntax-table) | |
892 ) | |
893 | |
894 (completion-advise c-mode :after | |
895 (setq cmpl-syntax-table cmpl-c-syntax-table) | |
896 ) | |
897 | |
898 (completion-advise fortran-mode :after | |
899 (setq cmpl-syntax-table cmpl-fortran-syntax-table) | |
900 (completion-setup-fortran-mode) | |
901 ) | |
902 | |
903 ;;;----------------------------------------------- | |
904 ;;; Symbol functions | |
905 ;;;----------------------------------------------- | |
906 (defvar cmpl-symbol-start nil | |
907 "Set to the first character of the symbol after one of the completion | |
908 symbol functions is called.") | |
909 (defvar cmpl-symbol-end nil | |
910 "Set to the last character of the symbol after one of the completion | |
911 symbol functions is called.") | |
912 ;;; These are temp. vars. we use to avoid using let. | |
913 ;;; Why ? Small speed improvement. | |
914 (defvar cmpl-saved-syntax nil) | |
915 (defvar cmpl-saved-point nil) | |
916 | |
917 (defun symbol-under-point () | |
918 "Returns the symbol that the point is currently on if it is longer | |
919 than *completion-min-length*." | |
920 (setq cmpl-saved-syntax (syntax-table)) | |
921 (set-syntax-table cmpl-syntax-table) | |
922 (cond | |
923 ;; Cursor is on following-char and after preceding-char | |
924 ((memq (char-syntax (following-char)) '(?w ?_)) | |
925 (setq cmpl-saved-point (point) | |
926 cmpl-symbol-start (scan-sexps (1+ cmpl-saved-point) -1) | |
927 cmpl-symbol-end (scan-sexps cmpl-saved-point 1)) | |
928 ;; remove chars to ignore at the start | |
929 (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w) | |
930 (goto-char cmpl-symbol-start) | |
931 (forward-word 1) | |
932 (setq cmpl-symbol-start (point)) | |
933 (goto-char cmpl-saved-point) | |
934 )) | |
935 ;; remove chars to ignore at the end | |
936 (cond ((= (char-syntax (char-after (1- cmpl-symbol-end))) ?w) | |
937 (goto-char cmpl-symbol-end) | |
938 (forward-word -1) | |
939 (setq cmpl-symbol-end (point)) | |
940 (goto-char cmpl-saved-point) | |
941 )) | |
942 ;; restore state | |
943 (set-syntax-table cmpl-saved-syntax) | |
944 ;; Return completion if the length is reasonable | |
945 (if (and (<= (read-time-eval *completion-min-length*) | |
946 (- cmpl-symbol-end cmpl-symbol-start)) | |
947 (<= (- cmpl-symbol-end cmpl-symbol-start) | |
948 (read-time-eval *completion-max-length*))) | |
949 (buffer-substring cmpl-symbol-start cmpl-symbol-end)) | |
950 ) | |
951 (t | |
952 ;; restore table if no symbol | |
953 (set-syntax-table cmpl-saved-syntax) | |
954 nil) | |
955 )) | |
956 | |
957 ;;; tests for symbol-under-point | |
958 ;;; `^' indicates cursor pos. where value is returned | |
959 ;;; simple-word-test | |
960 ;;; ^^^^^^^^^^^^^^^^ --> simple-word-test | |
961 ;;; _harder_word_test_ | |
962 ;;; ^^^^^^^^^^^^^^^^^^ --> harder_word_test | |
963 ;;; .___.______. | |
964 ;;; --> nil | |
965 ;;; /foo/bar/quux.hello | |
966 ;;; ^^^^^^^^^^^^^^^^^^^ --> /foo/bar/quux.hello | |
967 ;;; | |
968 | |
969 (defun symbol-before-point () | |
970 "Returns a string of the symbol immediately before point | |
971 or nil if there isn't one longer than *completion-min-length*." | |
972 ;; This is called when a word separator is typed so it must be FAST ! | |
973 (setq cmpl-saved-syntax (syntax-table)) | |
974 (set-syntax-table cmpl-syntax-table) | |
975 ;; Cursor is on following-char and after preceding-char | |
976 (cond ((= (setq cmpl-preceding-syntax (char-syntax (preceding-char))) ?_) | |
977 ;; No chars. to ignore at end | |
978 (setq cmpl-symbol-end (point) | |
979 cmpl-symbol-start (scan-sexps (1+ cmpl-symbol-end) -1) | |
980 ) | |
981 ;; remove chars to ignore at the start | |
982 (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w) | |
983 (goto-char cmpl-symbol-start) | |
984 (forward-word 1) | |
985 (setq cmpl-symbol-start (point)) | |
986 (goto-char cmpl-symbol-end) | |
987 )) | |
988 ;; restore state | |
989 (set-syntax-table cmpl-saved-syntax) | |
990 ;; return value if long enough | |
991 (if (>= cmpl-symbol-end | |
992 (+ cmpl-symbol-start | |
993 (read-time-eval *completion-min-length*))) | |
994 (buffer-substring cmpl-symbol-start cmpl-symbol-end)) | |
995 ) | |
996 ((= cmpl-preceding-syntax ?w) | |
997 ;; chars to ignore at end | |
998 (setq cmpl-saved-point (point) | |
999 cmpl-symbol-start (scan-sexps (1+ cmpl-saved-point) -1)) | |
1000 ;; take off chars. from end | |
1001 (forward-word -1) | |
1002 (setq cmpl-symbol-end (point)) | |
1003 ;; remove chars to ignore at the start | |
1004 (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w) | |
1005 (goto-char cmpl-symbol-start) | |
1006 (forward-word 1) | |
1007 (setq cmpl-symbol-start (point)) | |
1008 )) | |
1009 ;; restore state | |
1010 (goto-char cmpl-saved-point) | |
1011 (set-syntax-table cmpl-saved-syntax) | |
1012 ;; Return completion if the length is reasonable | |
1013 (if (and (<= (read-time-eval *completion-min-length*) | |
1014 (- cmpl-symbol-end cmpl-symbol-start)) | |
1015 (<= (- cmpl-symbol-end cmpl-symbol-start) | |
1016 (read-time-eval *completion-max-length*))) | |
1017 (buffer-substring cmpl-symbol-start cmpl-symbol-end)) | |
1018 ) | |
1019 (t | |
1020 ;; restore table if no symbol | |
1021 (set-syntax-table cmpl-saved-syntax) | |
1022 nil) | |
1023 )) | |
1024 | |
1025 ;;; tests for symbol-before-point | |
1026 ;;; `^' indicates cursor pos. where value is returned | |
1027 ;;; simple-word-test | |
1028 ;;; ^ --> nil | |
1029 ;;; ^ --> nil | |
1030 ;;; ^ --> simple-w | |
1031 ;;; ^ --> simple-word-test | |
1032 ;;; _harder_word_test_ | |
1033 ;;; ^ --> harder_word_test | |
1034 ;;; ^ --> harder_word_test | |
1035 ;;; ^ --> harder | |
1036 ;;; .___.... | |
1037 ;;; --> nil | |
1038 | |
1039 (defun symbol-under-or-before-point () | |
1040 ;;; This could be made slightly faster but it is better to avoid | |
1041 ;;; copying all the code. | |
1042 ;;; However, it is only used by the completion string prompter. | |
1043 ;;; If it comes into common use, it could be rewritten. | |
1044 (setq cmpl-saved-syntax (syntax-table)) | |
1045 (set-syntax-table cmpl-syntax-table) | |
1046 (cond ((memq (char-syntax (following-char)) '(?w ?_)) | |
1047 (set-syntax-table cmpl-saved-syntax) | |
1048 (symbol-under-point)) | |
1049 (t | |
1050 (set-syntax-table cmpl-saved-syntax) | |
1051 (symbol-before-point)) | |
1052 )) | |
1053 | |
1054 | |
1055 (defun symbol-before-point-for-complete () | |
1056 ;; "Returns a string of the symbol immediately before point | |
1057 ;; or nil if there isn't one. Like symbol-before-point but doesn't trim the | |
1058 ;; end chars." | |
1059 ;; Cursor is on following-char and after preceding-char | |
1060 (setq cmpl-saved-syntax (syntax-table)) | |
1061 (set-syntax-table cmpl-syntax-table) | |
1062 (cond ((memq (setq cmpl-preceding-syntax (char-syntax (preceding-char))) | |
1063 '(?_ ?w)) | |
1064 (setq cmpl-symbol-end (point) | |
1065 cmpl-symbol-start (scan-sexps (1+ cmpl-symbol-end) -1) | |
1066 ) | |
1067 ;; remove chars to ignore at the start | |
1068 (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w) | |
1069 (goto-char cmpl-symbol-start) | |
1070 (forward-word 1) | |
1071 (setq cmpl-symbol-start (point)) | |
1072 (goto-char cmpl-symbol-end) | |
1073 )) | |
1074 ;; restore state | |
1075 (set-syntax-table cmpl-saved-syntax) | |
1076 ;; Return completion if the length is reasonable | |
1077 (if (and (<= (read-time-eval | |
1078 *completion-prefix-min-length*) | |
1079 (- cmpl-symbol-end cmpl-symbol-start)) | |
1080 (<= (- cmpl-symbol-end cmpl-symbol-start) | |
1081 (read-time-eval *completion-max-length*))) | |
1082 (buffer-substring cmpl-symbol-start cmpl-symbol-end)) | |
1083 ) | |
1084 (t | |
1085 ;; restore table if no symbol | |
1086 (set-syntax-table cmpl-saved-syntax) | |
1087 nil) | |
1088 )) | |
1089 | |
1090 ;;; tests for symbol-before-point-for-complete | |
1091 ;;; `^' indicates cursor pos. where value is returned | |
1092 ;;; simple-word-test | |
1093 ;;; ^ --> nil | |
1094 ;;; ^ --> nil | |
1095 ;;; ^ --> simple-w | |
1096 ;;; ^ --> simple-word-test | |
1097 ;;; _harder_word_test_ | |
1098 ;;; ^ --> harder_word_test | |
1099 ;;; ^ --> harder_word_test_ | |
1100 ;;; ^ --> harder_ | |
1101 ;;; .___.... | |
1102 ;;; --> nil | |
1103 | |
1104 | |
1105 | |
1106 ;;;--------------------------------------------------------------------------- | |
1107 ;;; Statistics Recording | |
1108 ;;;--------------------------------------------------------------------------- | |
1109 | |
1110 ;;; Note that the guts of this has been turned off. The guts | |
1111 ;;; are in completion-stats.el. | |
1112 | |
1113 ;;;----------------------------------------------- | |
1114 ;;; Conditionalizing code on *record-cmpl-statistics-p* | |
1115 ;;;----------------------------------------------- | |
1116 ;;; All statistics code outside this block should use this | |
1117 (defmacro cmpl-statistics-block (&rest body) | |
1118 "Only executes body if we are recording statistics." | |
1119 (list 'cond | |
1120 (list* '*record-cmpl-statistics-p* body) | |
1121 )) | |
1122 | |
1123 ;;;----------------------------------------------- | |
1124 ;;; Completion Sources | |
1125 ;;;----------------------------------------------- | |
1126 | |
1127 ;; ID numbers | |
1128 (defconst cmpl-source-unknown 0) | |
1129 (defconst cmpl-source-init-file 1) | |
1130 (defconst cmpl-source-file-parsing 2) | |
1131 (defconst cmpl-source-separator 3) | |
1132 (defconst cmpl-source-cursor-moves 4) | |
1133 (defconst cmpl-source-interactive 5) | |
1134 (defconst cmpl-source-cdabbrev 6) | |
1135 (defconst num-cmpl-sources 7) | |
1136 (defvar current-completion-source cmpl-source-unknown) | |
1137 | |
1138 | |
1139 | |
1140 ;;;--------------------------------------------------------------------------- | |
1141 ;;; Completion Method #2: dabbrev-expand style | |
1142 ;;;--------------------------------------------------------------------------- | |
1143 ;;; | |
1144 ;;; This method is used if there are no useful stored completions. It is | |
1145 ;;; based on dabbrev-expand with these differences : | |
1146 ;;; 1) Faster (we don't use regexps) | |
1147 ;;; 2) case coercion handled correctly | |
1148 ;;; This is called cdabbrev to differentiate it. | |
1149 ;;; We simply search backwards through the file looking for words which | |
1150 ;;; start with the same letters we are trying to complete. | |
1151 ;;; | |
1152 | |
1153 (defvar cdabbrev-completions-tried nil) | |
1154 ;;; "A list of all the cdabbrev completions since the last reset.") | |
1155 | |
1156 (defvar cdabbrev-current-point 0) | |
1157 ;;; "The current point position the cdabbrev search is at.") | |
1158 | |
1159 (defvar cdabbrev-current-window nil) | |
1160 ;;; "The current window we are looking for cdabbrevs in. T if looking in | |
1161 ;;; (other-buffer), NIL if no more cdabbrevs.") | |
1162 | |
1163 (defvar cdabbrev-wrapped-p nil) | |
1164 ;;; "T if the cdabbrev search has wrapped around the file.") | |
1165 | |
1166 (defvar cdabbrev-abbrev-string "") | |
1167 (defvar cdabbrev-start-point 0) | |
1168 | |
1169 ;;; Test strings for cdabbrev | |
1170 ;;; cdat-upcase ;;same namestring | |
1171 ;;; CDAT-UPCASE ;;ok | |
1172 ;;; cdat2 ;;too short | |
1173 ;;; cdat-1-2-3-4 ;;ok | |
1174 ;;; a-cdat-1 ;;doesn't start correctly | |
1175 ;;; cdat-simple ;;ok | |
1176 | |
1177 | |
1178 (defun reset-cdabbrev (abbrev-string &optional initial-completions-tried) | |
1179 "Resets the cdabbrev search to search for abbrev-string. | |
1180 initial-completions-tried is a list of downcased strings to ignore | |
1181 during the search." | |
1182 (setq cdabbrev-abbrev-string abbrev-string | |
1183 cdabbrev-completions-tried | |
1184 (cons (downcase abbrev-string) initial-completions-tried) | |
1185 ) | |
1186 (reset-cdabbrev-window t) | |
1187 ) | |
1188 | |
1189 (defun set-cdabbrev-buffer () | |
1190 ;; cdabbrev-current-window must not be NIL | |
1191 (set-buffer (if (eq cdabbrev-current-window t) | |
1192 (other-buffer) | |
1193 (window-buffer cdabbrev-current-window))) | |
1194 ) | |
1195 | |
1196 | |
1197 (defun reset-cdabbrev-window (&optional initializep) | |
1198 "Resets the cdabbrev search to search for abbrev-string. | |
1199 initial-completions-tried is a list of downcased strings to ignore | |
1200 during the search." | |
1201 ;; Set the window | |
1202 (cond (initializep | |
1203 (setq cdabbrev-current-window (selected-window)) | |
1204 ) | |
1205 ((eq cdabbrev-current-window t) | |
1206 ;; Everything has failed | |
1207 (setq cdabbrev-current-window nil)) | |
1208 (cdabbrev-current-window | |
1209 (setq cdabbrev-current-window (next-window cdabbrev-current-window)) | |
1210 (if (eq cdabbrev-current-window (selected-window)) | |
1211 ;; No more windows, try other buffer. | |
1212 (setq cdabbrev-current-window t))) | |
1213 ) | |
1214 (when cdabbrev-current-window | |
1215 (save-excursion | |
1216 (set-cdabbrev-buffer) | |
1217 (setq cdabbrev-current-point (point) | |
1218 cdabbrev-start-point cdabbrev-current-point | |
1219 cdabbrev-stop-point | |
1220 (if *cdabbrev-radius* | |
1221 (max (point-min) | |
1222 (- cdabbrev-start-point *cdabbrev-radius*)) | |
1223 (point-min)) | |
1224 cdabbrev-wrapped-p nil) | |
1225 ))) | |
1226 | |
1227 (defun next-cdabbrev () | |
1228 "Return the next possible cdabbrev expansion or nil if there isn't one. | |
1229 reset-cdabbrev must've been called. This is sensitive to case-fold-search." | |
1230 ;; note that case-fold-search affects the behavior of this function | |
1231 ;; Bug: won't pick up an expansion that starts at the top of buffer | |
1232 (when cdabbrev-current-window | |
1233 (let (saved-point | |
1234 saved-syntax | |
1235 (expansion nil) | |
1236 downcase-expansion tried-list syntax saved-point-2) | |
1237 (save-excursion | |
1238 (unwind-protect | |
1239 (progn | |
1240 ;; Switch to current completion buffer | |
1241 (set-cdabbrev-buffer) | |
1242 ;; Save current buffer state | |
1243 (setq saved-point (point) | |
1244 saved-syntax (syntax-table)) | |
1245 ;; Restore completion state | |
1246 (set-syntax-table cmpl-syntax-table) | |
1247 (goto-char cdabbrev-current-point) | |
1248 ;; Loop looking for completions | |
1249 (while | |
1250 ;; This code returns t if it should loop again | |
1251 (cond | |
1252 (;; search for the string | |
1253 (search-backward cdabbrev-abbrev-string cdabbrev-stop-point t) | |
1254 ;; return nil if the completion is valid | |
1255 (not | |
1256 (and | |
1257 ;; does it start with a separator char ? | |
1258 (or (= (setq syntax (char-syntax (preceding-char))) ? ) | |
1259 (and (= syntax ?w) | |
1260 ;; symbol char to ignore at end. Are we at end ? | |
1261 (progn | |
1262 (setq saved-point-2 (point)) | |
1263 (forward-word -1) | |
1264 (prog1 | |
1265 (= (char-syntax (preceding-char)) ? ) | |
1266 (goto-char saved-point-2) | |
1267 )))) | |
1268 ;; is the symbol long enough ? | |
1269 (setq expansion (symbol-under-point)) | |
1270 ;; have we not tried this one before | |
1271 (progn | |
1272 ;; See if we've already used it | |
1273 (setq tried-list cdabbrev-completions-tried | |
1274 downcase-expansion (downcase expansion)) | |
1275 (while (and tried-list | |
1276 (not (string-equal downcase-expansion | |
1277 (car tried-list)))) | |
1278 ;; Already tried, don't choose this one | |
1279 (setq tried-list (cdr tried-list)) | |
1280 ) | |
1281 ;; at this point tried-list will be nil if this | |
1282 ;; expansion has not yet been tried | |
1283 (if tried-list | |
1284 (setq expansion nil) | |
1285 t) | |
1286 )))) | |
1287 ;; search failed | |
1288 (cdabbrev-wrapped-p | |
1289 ;; If already wrapped, then we've failed completely | |
1290 nil) | |
1291 (t | |
1292 ;; need to wrap | |
1293 (goto-char (setq cdabbrev-current-point | |
1294 (if *cdabbrev-radius* | |
1295 (min (point-max) (+ cdabbrev-start-point *cdabbrev-radius*)) | |
1296 (point-max)))) | |
1297 | |
1298 (setq cdabbrev-wrapped-p t)) | |
1299 )) | |
1300 ;; end of while loop | |
1301 (cond (expansion | |
1302 ;; successful | |
1303 (setq cdabbrev-completions-tried | |
1304 (cons downcase-expansion cdabbrev-completions-tried) | |
1305 cdabbrev-current-point (point)))) | |
1306 ) | |
1307 (set-syntax-table saved-syntax) | |
1308 (goto-char saved-point) | |
1309 )) | |
1310 ;; If no expansion, go to next window | |
1311 (cond (expansion) | |
1312 (t (reset-cdabbrev-window) | |
1313 (next-cdabbrev))) | |
1314 ))) | |
1315 | |
1316 ;;; The following must be eval'd in the minibuffer :: | |
1317 ;;; (reset-cdabbrev "cdat") | |
1318 ;;; (next-cdabbrev) --> "cdat-simple" | |
1319 ;;; (next-cdabbrev) --> "cdat-1-2-3-4" | |
1320 ;;; (next-cdabbrev) --> "CDAT-UPCASE" | |
1321 ;;; (next-cdabbrev) --> "cdat-wrapping" | |
1322 ;;; (next-cdabbrev) --> "cdat_start_sym" | |
1323 ;;; (next-cdabbrev) --> nil | |
1324 ;;; (next-cdabbrev) --> nil | |
1325 ;;; (next-cdabbrev) --> nil | |
1326 | |
1327 ;;; _cdat_start_sym | |
1328 ;;; cdat-wrapping | |
1329 | |
1330 | |
1331 ;;;--------------------------------------------------------------------------- | |
1332 ;;; Completion Database | |
1333 ;;;--------------------------------------------------------------------------- | |
1334 | |
1335 ;;; We use two storage modes for the two search types :: | |
1336 ;;; 1) Prefix {cmpl-prefix-obarray} for looking up possible completions | |
1337 ;;; Used by search-completion-next | |
1338 ;;; the value of the symbol is nil or a cons of head and tail pointers | |
1339 ;;; 2) Interning {cmpl-obarray} to see if it's in the database | |
1340 ;;; Used by find-exact-completion, completion-in-database-p | |
1341 ;;; The value of the symbol is the completion entry | |
1342 | |
1343 ;;; bad things may happen if this length is changed due to the way | |
1344 ;;; GNU implements obarrays | |
1345 (defconst cmpl-obarray-length 511) | |
1346 | |
1347 (defvar cmpl-prefix-obarray (make-vector cmpl-obarray-length 0) | |
1348 "An obarray used to store the downcased completion prefices. | |
1349 Each symbol is bound to a list of completion entries.") | |
1350 | |
1351 (defvar cmpl-obarray (make-vector cmpl-obarray-length 0) | |
1352 "An obarray used to store the downcased completions. | |
1353 Each symbol is bound to a single completion entry.") | |
1354 | |
1355 ;;;----------------------------------------------- | |
1356 ;;; Completion Entry Structure Definition | |
1357 ;;;----------------------------------------------- | |
1358 | |
1359 ;;; A completion entry is a LIST of string, prefix-symbol num-uses, and | |
1360 ;;; last-use-time (the time the completion was last used) | |
1361 ;;; last-use-time is T if the string should be kept permanently | |
1362 ;;; num-uses is incremented everytime the completion is used. | |
1363 | |
1364 ;;; We chose lists because (car foo) is faster than (aref foo 0) and the | |
1365 ;;; creation time is about the same. | |
1366 | |
1367 ;;; READER MACROS | |
1368 | |
1369 (defmacro completion-string (completion-entry) | |
1370 (list 'car completion-entry)) | |
1371 | |
1372 (defmacro completion-num-uses (completion-entry) | |
1373 ;; "The number of times it has used. Used to decide whether to save | |
1374 ;; it." | |
1375 (list 'car (list 'cdr completion-entry))) | |
1376 | |
1377 (defmacro completion-last-use-time (completion-entry) | |
1378 ;; "The time it was last used. In hours since 1900. Used to decide | |
1379 ;; whether to save it. T if one should always save it." | |
1380 (list 'nth 2 completion-entry)) | |
1381 | |
1382 (defmacro completion-source (completion-entry) | |
1383 (list 'nth 3 completion-entry)) | |
1384 | |
1385 ;;; WRITER MACROS | |
1386 (defmacro set-completion-string (completion-entry string) | |
1387 (list 'setcar completion-entry string)) | |
1388 | |
1389 (defmacro set-completion-num-uses (completion-entry num-uses) | |
1390 (list 'setcar (list 'cdr completion-entry) num-uses)) | |
1391 | |
1392 (defmacro set-completion-last-use-time (completion-entry last-use-time) | |
1393 (list 'setcar (list 'cdr (list 'cdr completion-entry)) last-use-time)) | |
1394 | |
1395 ;;; CONSTRUCTOR | |
1396 (defun make-completion (string) | |
1397 "Returns a list of a completion entry." | |
1398 (list (list string 0 nil current-completion-source))) | |
1399 | |
1400 ;; Obsolete | |
1401 ;;(defmacro cmpl-prefix-entry-symbol (completion-entry) | |
1402 ;; (list 'car (list 'cdr completion-entry))) | |
1403 | |
1404 | |
1405 | |
1406 ;;;----------------------------------------------- | |
1407 ;;; Prefix symbol entry definition | |
1408 ;;;----------------------------------------------- | |
1409 ;;; A cons of (head . tail) | |
1410 | |
1411 ;;; READER Macros | |
1412 | |
1413 (defmacro cmpl-prefix-entry-head (prefix-entry) | |
1414 (list 'car prefix-entry)) | |
1415 | |
1416 (defmacro cmpl-prefix-entry-tail (prefix-entry) | |
1417 (list 'cdr prefix-entry)) | |
1418 | |
1419 ;;; WRITER Macros | |
1420 | |
1421 (defmacro set-cmpl-prefix-entry-head (prefix-entry new-head) | |
1422 (list 'setcar prefix-entry new-head)) | |
1423 | |
1424 (defmacro set-cmpl-prefix-entry-tail (prefix-entry new-tail) | |
1425 (list 'setcdr prefix-entry new-tail)) | |
1426 | |
1427 ;;; Contructor | |
1428 | |
1429 (defun make-cmpl-prefix-entry (completion-entry-list) | |
1430 "Makes a new prefix entry containing only completion-entry." | |
1431 (cons completion-entry-list completion-entry-list)) | |
1432 | |
1433 ;;;----------------------------------------------- | |
1434 ;;; Completion Database - Utilities | |
1435 ;;;----------------------------------------------- | |
1436 | |
1437 (defun clear-all-completions () | |
1438 "Initializes the completion storage. All existing completions are lost." | |
1439 (interactive) | |
1440 (setq cmpl-prefix-obarray (make-vector cmpl-obarray-length 0)) | |
1441 (setq cmpl-obarray (make-vector cmpl-obarray-length 0)) | |
1442 (cmpl-statistics-block | |
1443 (record-clear-all-completions)) | |
1444 ) | |
1445 | |
1446 (defun list-all-completions () | |
1447 "Returns a list of all the known completion entries." | |
1448 (let ((return-completions nil)) | |
1449 (mapatoms 'list-all-completions-1 cmpl-prefix-obarray) | |
1450 return-completions)) | |
1451 | |
1452 (defun list-all-completions-1 (prefix-symbol) | |
1453 (if (boundp prefix-symbol) | |
1454 (setq return-completions | |
1455 (append (cmpl-prefix-entry-head (symbol-value prefix-symbol)) | |
1456 return-completions)))) | |
1457 | |
1458 (defun list-all-completions-by-hash-bucket () | |
1459 "Returns a list of lists of all the known completion entries organized by | |
1460 hash bucket." | |
1461 (let ((return-completions nil)) | |
1462 (mapatoms 'list-all-completions-by-hash-bucket-1 cmpl-prefix-obarray) | |
1463 return-completions)) | |
1464 | |
1465 (defun list-all-completions-by-hash-bucket-1 (prefix-symbol) | |
1466 (if (boundp prefix-symbol) | |
1467 (setq return-completions | |
1468 (cons (cmpl-prefix-entry-head (symbol-value prefix-symbol)) | |
1469 return-completions)))) | |
1470 | |
1471 | |
1472 ;;;----------------------------------------------- | |
1473 ;;; Updating the database | |
1474 ;;;----------------------------------------------- | |
1475 ;;; | |
1476 ;;; These are the internal functions used to update the datebase | |
1477 ;;; | |
1478 ;;; | |
1479 (defvar completion-to-accept nil) | |
1480 ;;"Set to a string that is pending its acceptance." | |
1481 ;; this checked by the top level reading functions | |
1482 | |
1483 (defvar cmpl-db-downcase-string nil) | |
1484 ;; "Setup by find-exact-completion, etc. The given string, downcased." | |
1485 (defvar cmpl-db-symbol nil) | |
1486 ;; "The interned symbol corresponding to cmpl-db-downcase-string. | |
1487 ;; Set up by cmpl-db-symbol." | |
1488 (defvar cmpl-db-prefix-symbol nil) | |
1489 ;; "The interned prefix symbol corresponding to cmpl-db-downcase-string." | |
1490 (defvar cmpl-db-entry nil) | |
1491 (defvar cmpl-db-debug-p nil | |
1492 "Set to T if you want to debug the database.") | |
1493 | |
1494 ;;; READS | |
1495 (defun find-exact-completion (string) | |
1496 "Returns the completion entry for string or nil. | |
1497 Sets up cmpl-db-downcase-string and cmpl-db-symbol." | |
1498 (and (boundp (setq cmpl-db-symbol | |
1499 (intern (setq cmpl-db-downcase-string (downcase string)) | |
1500 cmpl-obarray))) | |
1501 (symbol-value cmpl-db-symbol) | |
1502 )) | |
1503 | |
1504 (defun find-cmpl-prefix-entry (prefix-string) | |
1356 | 1505 "Returns the prefix entry for string. |
1506 Sets cmpl-db-prefix-symbol. | |
56 | 1507 Prefix-string must be exactly *completion-prefix-min-length* long |
1508 and downcased. Sets up cmpl-db-prefix-symbol." | |
1509 (and (boundp (setq cmpl-db-prefix-symbol | |
1510 (intern prefix-string cmpl-prefix-obarray))) | |
1511 (symbol-value cmpl-db-prefix-symbol))) | |
1512 | |
1513 (defvar inside-locate-completion-entry nil) | |
1514 ;; used to trap lossage in silent error correction | |
1515 | |
1516 (defun locate-completion-entry (completion-entry prefix-entry) | |
1356 | 1517 "Locates the completion entry. |
1518 Returns a pointer to the element before the completion entry or nil if | |
1519 the completion entry is at the head. | |
56 | 1520 Must be called after find-exact-completion." |
1521 (let ((prefix-list (cmpl-prefix-entry-head prefix-entry)) | |
1522 next-prefix-list | |
1523 ) | |
1524 (cond | |
1525 ((not (eq (car prefix-list) completion-entry)) | |
1526 ;; not already at head | |
1527 (while (and prefix-list | |
1528 (not (eq completion-entry | |
1529 (car (setq next-prefix-list (cdr prefix-list))) | |
1530 ))) | |
1531 (setq prefix-list next-prefix-list)) | |
1532 (cond (;; found | |
1533 prefix-list) | |
1534 ;; Didn't find it. Database is messed up. | |
1535 (cmpl-db-debug-p | |
1536 ;; not found, error if debug mode | |
1537 (error "Completion entry exists but not on prefix list - %s" | |
1538 string)) | |
1539 (inside-locate-completion-entry | |
1540 ;; recursive error: really scrod | |
1541 (locate-completion-db-error)) | |
1542 (t | |
1543 ;; Patch out | |
1544 (set cmpl-db-symbol nil) | |
1545 ;; Retry | |
1546 (locate-completion-entry-retry completion-entry) | |
1547 )))))) | |
1548 | |
1549 (defun locate-completion-entry-retry (old-entry) | |
1550 (let ((inside-locate-completion-entry t)) | |
1551 (add-completion (completion-string old-entry) | |
1552 (completion-num-uses old-entry) | |
1553 (completion-last-use-time old-entry)) | |
1554 (let ((cmpl-entry (find-exact-completion (completion-string old-entry))) | |
1555 (pref-entry | |
1556 (if cmpl-entry | |
1557 (find-cmpl-prefix-entry | |
1558 (substring cmpl-db-downcase-string | |
1559 0 *completion-prefix-min-length*)))) | |
1560 ) | |
1561 (if (and cmpl-entry pref-entry) | |
1562 ;; try again | |
1563 (locate-completion-entry cmpl-entry pref-entry) | |
1564 ;; still losing | |
1565 (locate-completion-db-error)) | |
1566 ))) | |
1567 | |
1568 (defun locate-completion-db-error () | |
1569 ;; recursive error: really scrod | |
1570 (error "Completion database corrupted. Try M-x clear-all-completions. Send bug report.") | |
1571 ) | |
1572 | |
1573 ;;; WRITES | |
1574 (defun add-completion-to-tail-if-new (string) | |
1356 | 1575 "If STRING is not in the database add it to appropriate prefix list. |
1576 STRING is added to the end of the approppriate prefix list with | |
1577 num-uses = 0. The database is unchanged if it is there. STRING must be | |
1578 longer than *completion-prefix-min-length*. | |
56 | 1579 This must be very fast. |
1580 Returns the completion entry." | |
1581 (or (find-exact-completion string) | |
1582 ;; not there | |
1583 (let (;; create an entry | |
1584 (entry (make-completion string)) | |
1585 ;; setup the prefix | |
1586 (prefix-entry (find-cmpl-prefix-entry | |
1587 (substring cmpl-db-downcase-string 0 | |
1588 (read-time-eval | |
1589 *completion-prefix-min-length*)))) | |
1590 ) | |
1591 ;; The next two forms should happen as a unit (atomically) but | |
1592 ;; no fatal errors should result if that is not the case. | |
1593 (cond (prefix-entry | |
1594 ;; These two should be atomic, but nothing fatal will happen | |
1595 ;; if they're not. | |
1596 (setcdr (cmpl-prefix-entry-tail prefix-entry) entry) | |
1597 (set-cmpl-prefix-entry-tail prefix-entry entry)) | |
1598 (t | |
1599 (set cmpl-db-prefix-symbol (make-cmpl-prefix-entry entry)) | |
1600 )) | |
1601 ;; statistics | |
1602 (cmpl-statistics-block | |
1603 (note-added-completion)) | |
1604 ;; set symbol | |
1605 (set cmpl-db-symbol (car entry)) | |
1606 ))) | |
1607 | |
1608 (defun add-completion-to-head (string) | |
1356 | 1609 "If STRING is not in the database, add it to prefix list. |
1610 STRING is added to the head of the approppriate prefix list. Otherwise | |
1611 it is moved to the head of the list. STRING must be longer than | |
1612 *completion-prefix-min-length*. | |
56 | 1613 Updates the saved string with the supplied string. |
1614 This must be very fast. | |
1615 Returns the completion entry." | |
1616 ;; Handle pending acceptance | |
1617 (if completion-to-accept (accept-completion)) | |
1618 ;; test if already in database | |
1619 (if (setq cmpl-db-entry (find-exact-completion string)) | |
1620 ;; found | |
1621 (let* ((prefix-entry (find-cmpl-prefix-entry | |
1622 (substring cmpl-db-downcase-string 0 | |
1623 (read-time-eval | |
1624 *completion-prefix-min-length*)))) | |
1625 (splice-ptr (locate-completion-entry cmpl-db-entry prefix-entry)) | |
1626 (cmpl-ptr (cdr splice-ptr)) | |
1627 ) | |
1628 ;; update entry | |
1629 (set-completion-string cmpl-db-entry string) | |
1630 ;; move to head (if necessary) | |
1631 (cond (splice-ptr | |
1632 ;; These should all execute atomically but it is not fatal if | |
1633 ;; they don't. | |
1634 ;; splice it out | |
1635 (or (setcdr splice-ptr (cdr cmpl-ptr)) | |
1636 ;; fix up tail if necessary | |
1637 (set-cmpl-prefix-entry-tail prefix-entry splice-ptr)) | |
1638 ;; splice in at head | |
1639 (setcdr cmpl-ptr (cmpl-prefix-entry-head prefix-entry)) | |
1640 (set-cmpl-prefix-entry-head prefix-entry cmpl-ptr) | |
1641 )) | |
1642 cmpl-db-entry) | |
1643 ;; not there | |
1644 (let (;; create an entry | |
1645 (entry (make-completion string)) | |
1646 ;; setup the prefix | |
1647 (prefix-entry (find-cmpl-prefix-entry | |
1648 (substring cmpl-db-downcase-string 0 | |
1649 (read-time-eval | |
1650 *completion-prefix-min-length*)))) | |
1651 ) | |
1652 (cond (prefix-entry | |
1653 ;; Splice in at head | |
1654 (setcdr entry (cmpl-prefix-entry-head prefix-entry)) | |
1655 (set-cmpl-prefix-entry-head prefix-entry entry)) | |
1656 (t | |
1657 ;; Start new prefix entry | |
1658 (set cmpl-db-prefix-symbol (make-cmpl-prefix-entry entry)) | |
1659 )) | |
1660 ;; statistics | |
1661 (cmpl-statistics-block | |
1662 (note-added-completion)) | |
1663 ;; Add it to the symbol | |
1664 (set cmpl-db-symbol (car entry)) | |
1665 ))) | |
1666 | |
1667 (defun delete-completion (string) | |
1356 | 1668 "Deletes the completion from the database. |
1669 String must be longer than *completion-prefix-min-length*." | |
56 | 1670 ;; Handle pending acceptance |
1671 (if completion-to-accept (accept-completion)) | |
1672 (if (setq cmpl-db-entry (find-exact-completion string)) | |
1673 ;; found | |
1674 (let* ((prefix-entry (find-cmpl-prefix-entry | |
1675 (substring cmpl-db-downcase-string 0 | |
1676 (read-time-eval | |
1677 *completion-prefix-min-length*)))) | |
1678 (splice-ptr (locate-completion-entry cmpl-db-entry prefix-entry)) | |
1679 ) | |
1680 ;; delete symbol reference | |
1681 (set cmpl-db-symbol nil) | |
1682 ;; remove from prefix list | |
1683 (cond (splice-ptr | |
1684 ;; not at head | |
1685 (or (setcdr splice-ptr (cdr (cdr splice-ptr))) | |
1686 ;; fix up tail if necessary | |
1687 (set-cmpl-prefix-entry-tail prefix-entry splice-ptr)) | |
1688 ) | |
1689 (t | |
1690 ;; at head | |
1691 (or (set-cmpl-prefix-entry-head | |
1692 prefix-entry (cdr (cmpl-prefix-entry-head prefix-entry))) | |
1693 ;; List is now empty | |
1694 (set cmpl-db-prefix-symbol nil)) | |
1695 )) | |
1696 (cmpl-statistics-block | |
1697 (note-completion-deleted)) | |
1698 ) | |
1699 (error "Unknown completion: %s. Couldn't delete it." string) | |
1700 )) | |
1701 | |
1702 ;;; Tests -- | |
1703 ;;; - Add and Find - | |
1704 ;;; (add-completion-to-head "banana") --> ("banana" 0 nil 0) | |
1705 ;;; (find-exact-completion "banana") --> ("banana" 0 nil 0) | |
1706 ;;; (find-exact-completion "bana") --> nil | |
1707 ;;; (car (find-cmpl-prefix-entry "ban")) --> (("banana" ...)) | |
1708 ;;; (cdr (find-cmpl-prefix-entry "ban")) --> (("banana" ...)) | |
1709 ;;; (add-completion-to-head "banish") --> ("banish" 0 nil 0) | |
1710 ;;; (find-exact-completion "banish") --> ("banish" 0 nil 0) | |
1711 ;;; (car (find-cmpl-prefix-entry "ban")) --> (("banish" ...) ("banana" ...)) | |
1712 ;;; (cdr (find-cmpl-prefix-entry "ban")) --> (("banana" ...)) | |
1713 ;;; (add-completion-to-head "banana") --> ("banana" 0 nil 0) | |
1714 ;;; (car (find-cmpl-prefix-entry "ban")) --> (("banana" ...) ("banish" ...)) | |
1715 ;;; (cdr (find-cmpl-prefix-entry "ban")) --> (("banish" ...)) | |
1716 ;;; | |
1717 ;;; - Deleting - | |
1718 ;;; (add-completion-to-head "banner") --> ("banner" 0 nil 0) | |
1719 ;;; (delete-completion "banner") | |
1720 ;;; (find-exact-completion "banner") --> nil | |
1721 ;;; (car (find-cmpl-prefix-entry "ban")) --> (("banana" ...) ("banish" ...)) | |
1722 ;;; (cdr (find-cmpl-prefix-entry "ban")) --> (("banish" ...)) | |
1723 ;;; (add-completion-to-head "banner") --> ("banner" 0 nil 0) | |
1724 ;;; (delete-completion "banana") | |
1725 ;;; (car (find-cmpl-prefix-entry "ban")) --> (("banner" ...) ("banish" ...)) | |
1726 ;;; (cdr (find-cmpl-prefix-entry "ban")) --> (("banish" ...)) | |
1727 ;;; (delete-completion "banner") | |
1728 ;;; (delete-completion "banish") | |
1729 ;;; (find-cmpl-prefix-entry "ban") --> nil | |
1730 ;;; (delete-completion "banner") --> error | |
1731 ;;; | |
1732 ;;; - Tail - | |
1733 ;;; (add-completion-to-tail-if-new "banana") --> ("banana" 0 nil 0) | |
1734 ;;; (car (find-cmpl-prefix-entry "ban")) --> (("banana" ...)) | |
1735 ;;; (cdr (find-cmpl-prefix-entry "ban")) --> (("banana" ...)) | |
1736 ;;; (add-completion-to-tail-if-new "banish") --> ("banish" 0 nil 0) | |
1737 ;;; (car (find-cmpl-prefix-entry "ban")) -->(("banana" ...) ("banish" ...)) | |
1738 ;;; (cdr (find-cmpl-prefix-entry "ban")) -->(("banish" ...)) | |
1739 ;;; | |
1740 | |
1741 | |
1742 ;;;--------------------------------------------------------------------------- | |
1743 ;;; Database Update :: Interface level routines | |
1744 ;;;--------------------------------------------------------------------------- | |
1745 ;;; | |
1746 ;;; These lie on top of the database ref. functions but below the standard | |
1747 ;;; user interface level | |
1748 | |
1749 | |
1750 (defun interactive-completion-string-reader (prompt) | |
1751 (let* ((default (symbol-under-or-before-point)) | |
1752 (new-prompt | |
1753 (if default | |
1754 (format "%s: (default: %s) " prompt default) | |
1755 (format "%s: " prompt)) | |
1756 ) | |
1757 (read (completing-read new-prompt cmpl-obarray)) | |
1758 ) | |
1759 (if (zerop (length read)) (setq read (or default ""))) | |
1760 (list read) | |
1761 )) | |
1762 | |
1763 (defun check-completion-length (string) | |
1764 (if (< (length string) *completion-min-length*) | |
1765 (error "The string \"%s\" is too short to be saved as a completion." | |
1766 string) | |
1767 (list string))) | |
1768 | |
1769 (defun add-completion (string &optional num-uses last-use-time) | |
1770 "If the string is not there, it is added to the head of the completion list. | |
1771 Otherwise, it is moved to the head of the list. | |
1772 The completion is altered appropriately if num-uses and/or last-use-time is | |
1773 specified." | |
1774 (interactive (interactive-completion-string-reader "Completion to add")) | |
1775 (check-completion-length string) | |
1776 (let* ((current-completion-source (if (interactive-p) | |
1777 cmpl-source-interactive | |
1778 current-completion-source)) | |
1779 (entry (add-completion-to-head string))) | |
1780 | |
1781 (if num-uses (set-completion-num-uses entry num-uses)) | |
1782 (if last-use-time | |
1783 (set-completion-last-use-time entry last-use-time)) | |
1784 )) | |
1785 | |
1786 (defun add-permanent-completion (string) | |
1787 "Adds string if it isn't already there and and makes it a permanent string." | |
1788 (interactive | |
1789 (interactive-completion-string-reader "Completion to add permanently")) | |
1790 (let ((current-completion-source (if (interactive-p) | |
1791 cmpl-source-interactive | |
1792 current-completion-source)) | |
1793 ) | |
1794 (add-completion string nil t) | |
1795 )) | |
1796 | |
1797 (defun kill-completion (string) | |
1798 (interactive (interactive-completion-string-reader "Completion to kill")) | |
1799 (check-completion-length string) | |
1800 (delete-completion string) | |
1801 ) | |
1802 | |
1803 (defun accept-completion () | |
1804 "Accepts the pending completion in completion-to-accept. | |
1805 This bumps num-uses. Called by add-completion-to-head and | |
1806 completion-search-reset." | |
1807 (let ((string completion-to-accept) | |
1808 ;; if this is added afresh here, then it must be a cdabbrev | |
1809 (current-completion-source cmpl-source-cdabbrev) | |
1810 entry | |
1811 ) | |
1812 (setq completion-to-accept nil) | |
1813 (setq entry (add-completion-to-head string)) | |
1814 (set-completion-num-uses entry (1+ (completion-num-uses entry))) | |
1815 (setq cmpl-completions-accepted-p t) | |
1816 )) | |
1817 | |
1818 (defun use-completion-under-point () | |
1356 | 1819 "Adds the completion symbol underneath the point into the completion buffer." |
56 | 1820 (let ((string (and *completep* (symbol-under-point))) |
1821 (current-completion-source cmpl-source-cursor-moves)) | |
1822 (if string (add-completion-to-head string)))) | |
1823 | |
1824 (defun use-completion-before-point () | |
1356 | 1825 "Adds the completion symbol before point into |
56 | 1826 the completion buffer." |
1827 (let ((string (and *completep* (symbol-before-point))) | |
1828 (current-completion-source cmpl-source-cursor-moves)) | |
1829 (if string (add-completion-to-head string)))) | |
1830 | |
1831 (defun use-completion-under-or-before-point () | |
1356 | 1832 "Adds the completion symbol before point into the completion buffer." |
56 | 1833 (let ((string (and *completep* (symbol-under-or-before-point))) |
1834 (current-completion-source cmpl-source-cursor-moves)) | |
1835 (if string (add-completion-to-head string)))) | |
1836 | |
1837 (defun use-completion-before-separator () | |
1356 | 1838 "Adds the completion symbol before point into the completion buffer. |
1839 Completions added this way will automatically be saved if | |
1840 *separator-character-uses-completion-p* is non-nil." | |
56 | 1841 (let ((string (and *completep* (symbol-before-point))) |
1842 (current-completion-source cmpl-source-separator) | |
1843 entry) | |
1844 (cmpl-statistics-block | |
1845 (note-separator-character string) | |
1846 ) | |
1847 (cond (string | |
1848 (setq entry (add-completion-to-head string)) | |
1849 (when (and *separator-character-uses-completion-p* | |
1850 (zerop (completion-num-uses entry))) | |
1851 (set-completion-num-uses entry 1) | |
1852 (setq cmpl-completions-accepted-p t) | |
1853 ))) | |
1854 )) | |
1855 | |
1856 ;;; Tests -- | |
1857 ;;; - Add and Find - | |
1858 ;;; (add-completion "banana" 5 10) | |
1859 ;;; (find-exact-completion "banana") --> ("banana" 5 10 0) | |
1860 ;;; (add-completion "banana" 6) | |
1861 ;;; (find-exact-completion "banana") --> ("banana" 6 10 0) | |
1862 ;;; (add-completion "banish") | |
1863 ;;; (car (find-cmpl-prefix-entry "ban")) --> (("banish" ...) ("banana" ...)) | |
1864 ;;; | |
1865 ;;; - Accepting - | |
1866 ;;; (setq completion-to-accept "banana") | |
1867 ;;; (accept-completion) | |
1868 ;;; (find-exact-completion "banana") --> ("banana" 7 10) | |
1869 ;;; (car (find-cmpl-prefix-entry "ban")) --> (("banana" ...) ("banish" ...)) | |
1870 ;;; (setq completion-to-accept "banish") | |
1871 ;;; (add-completion "banner") | |
1872 ;;; (car (find-cmpl-prefix-entry "ban")) | |
1873 ;;; --> (("banner" ...) ("banish" 1 ...) ("banana" 7 ...)) | |
1874 ;;; | |
1875 ;;; - Deleting - | |
1876 ;;; (kill-completion "banish") | |
1877 ;;; (car (find-cmpl-prefix-entry "ban")) --> (("banner" ...) ("banana" ...)) | |
1878 | |
1879 | |
1880 ;;;--------------------------------------------------------------------------- | |
1881 ;;; Searching the database | |
1882 ;;;--------------------------------------------------------------------------- | |
1883 ;;; Functions outside this block must call completion-search-reset followed | |
1884 ;;; by calls to completion-search-next or completion-search-peek | |
1885 ;;; | |
1886 | |
1887 ;;; Status variables | |
1888 ;; Commented out to improve loading speed | |
1889 (defvar cmpl-test-string "") | |
1890 ;; "The current string used by completion-search-next." | |
1891 (defvar cmpl-test-regexp "") | |
1892 ;; "The current regexp used by completion-search-next. | |
1893 ;; (derived from cmpl-test-string)" | |
1894 (defvar cmpl-last-index 0) | |
1895 ;; "The last index that completion-search-next was called with." | |
1896 (defvar cmpl-cdabbrev-reset-p nil) | |
1897 ;; "Set to t when cdabbrevs have been reset." | |
1898 (defvar cmpl-next-possibilities nil) | |
1899 ;; "A pointer to the element BEFORE the next set of possible completions. | |
1900 ;; cadr of this is the cmpl-next-possibility" | |
1901 (defvar cmpl-starting-possibilities nil) | |
1902 ;; "The initial list of starting possibilities." | |
1903 (defvar cmpl-next-possibility nil) | |
1904 ;; "The cached next possibility." | |
1905 (defvar cmpl-tried-list nil) | |
1906 ;; "A downcased list of all the completions we have tried." | |
1907 | |
1908 | |
1909 (defun completion-search-reset (string) | |
1910 "Given a string, sets up the get-completion and completion-search-next functions. | |
1911 String must be longer than *completion-prefix-min-length*." | |
1912 (if completion-to-accept (accept-completion)) | |
1913 (setq cmpl-starting-possibilities | |
1914 (cmpl-prefix-entry-head | |
1915 (find-cmpl-prefix-entry (downcase (substring string 0 3)))) | |
1916 cmpl-test-string string | |
1917 cmpl-test-regexp (concat (regexp-quote string) ".")) | |
1918 (completion-search-reset-1) | |
1919 ) | |
1920 | |
1921 (defun completion-search-reset-1 () | |
1922 (setq cmpl-next-possibilities cmpl-starting-possibilities | |
1923 cmpl-next-possibility nil | |
1924 cmpl-cdabbrev-reset-p nil | |
1925 cmpl-last-index -1 | |
1926 cmpl-tried-list nil | |
1927 )) | |
1928 | |
1929 (defun completion-search-next (index) | |
1356 | 1930 "Returns the next completion entry. |
1931 If index is out of sequence it resets and starts from the top. | |
1932 If there are no more entries it tries cdabbrev and returns only a string." | |
56 | 1933 (cond |
1934 ((= index (setq cmpl-last-index (1+ cmpl-last-index))) | |
1935 (completion-search-peek t)) | |
1936 ((minusp index) | |
1937 (completion-search-reset-1) | |
1938 (setq cmpl-last-index index) | |
1939 ;; reverse the possibilities list | |
1940 (setq cmpl-next-possibilities (reverse cmpl-starting-possibilities)) | |
1941 ;; do a "normal" search | |
1942 (while (and (completion-search-peek nil) | |
1943 (minusp (setq index (1+ index)))) | |
1944 (setq cmpl-next-possibility nil) | |
1945 ) | |
1946 (cond ((not cmpl-next-possibilities)) | |
1947 ;; If no more possibilities, leave it that way | |
1948 ((= -1 cmpl-last-index) | |
1949 ;; next completion is at index 0. reset next-possibility list | |
1950 ;; to start at beginning | |
1951 (setq cmpl-next-possibilities cmpl-starting-possibilities)) | |
1952 (t | |
1953 ;; otherwise point to one before current | |
1954 (setq cmpl-next-possibilities | |
1955 (nthcdr (- (length cmpl-starting-possibilities) | |
1956 (length cmpl-next-possibilities)) | |
1957 cmpl-starting-possibilities)) | |
1958 ))) | |
1959 (t | |
1960 ;; non-negative index, reset and search | |
1961 ;;(prin1 'reset) | |
1962 (completion-search-reset-1) | |
1963 (setq cmpl-last-index index) | |
1964 (while (and (completion-search-peek t) | |
1965 (not (minusp (setq index (1- index))))) | |
1966 (setq cmpl-next-possibility nil) | |
1967 )) | |
1968 ) | |
1969 (prog1 | |
1970 cmpl-next-possibility | |
1971 (setq cmpl-next-possibility nil) | |
1972 )) | |
1973 | |
1974 | |
1975 (defun completion-search-peek (use-cdabbrev) | |
1976 "Returns the next completion entry without actually moving the pointers. | |
1977 Calling this again or calling completion-search-next will result in the same | |
1978 string being returned. Depends on case-fold-search. | |
1979 If there are no more entries it tries cdabbrev and then returns only a string." | |
1980 (cond | |
1981 ;; return the cached value if we have it | |
1982 (cmpl-next-possibility) | |
1983 ((and cmpl-next-possibilities | |
1984 ;; still a few possibilities left | |
1985 (progn | |
1986 (while | |
1987 (and (not (eq 0 (string-match cmpl-test-regexp | |
1988 (completion-string (car cmpl-next-possibilities))))) | |
1989 (setq cmpl-next-possibilities (cdr cmpl-next-possibilities)) | |
1990 )) | |
1991 cmpl-next-possibilities | |
1992 )) | |
1993 ;; successful match | |
1994 (setq cmpl-next-possibility (car cmpl-next-possibilities) | |
1995 cmpl-tried-list (cons (downcase (completion-string cmpl-next-possibility)) | |
1996 cmpl-tried-list) | |
1997 cmpl-next-possibilities (cdr cmpl-next-possibilities) | |
1998 ) | |
1999 cmpl-next-possibility) | |
2000 (use-cdabbrev | |
2001 ;; unsuccessful, use cdabbrev | |
2002 (cond ((not cmpl-cdabbrev-reset-p) | |
2003 (reset-cdabbrev cmpl-test-string cmpl-tried-list) | |
2004 (setq cmpl-cdabbrev-reset-p t) | |
2005 )) | |
2006 (setq cmpl-next-possibility (next-cdabbrev)) | |
2007 ) | |
2008 ;; Completely unsuccessful, return nil | |
2009 )) | |
2010 | |
2011 ;;; Tests -- | |
2012 ;;; - Add and Find - | |
2013 ;;; (add-completion "banana") | |
2014 ;;; (completion-search-reset "ban") | |
2015 ;;; (completion-search-next 0) --> "banana" | |
2016 ;;; | |
2017 ;;; - Discrimination - | |
2018 ;;; (add-completion "cumberland") | |
2019 ;;; (add-completion "cumberbund") | |
2020 ;;; cumbering | |
2021 ;;; (completion-search-reset "cumb") | |
2022 ;;; (completion-search-peek t) --> "cumberbund" | |
2023 ;;; (completion-search-next 0) --> "cumberbund" | |
2024 ;;; (completion-search-peek t) --> "cumberland" | |
2025 ;;; (completion-search-next 1) --> "cumberland" | |
2026 ;;; (completion-search-peek nil) --> nil | |
2027 ;;; (completion-search-next 2) --> "cumbering" {cdabbrev} | |
2028 ;;; (completion-search-next 3) --> nil or "cumming"{depends on context} | |
2029 ;;; (completion-search-next 1) --> "cumberland" | |
2030 ;;; (completion-search-peek t) --> "cumbering" {cdabbrev} | |
2031 ;;; | |
2032 ;;; - Accepting - | |
2033 ;;; (completion-search-next 1) --> "cumberland" | |
2034 ;;; (setq completion-to-accept "cumberland") | |
2035 ;;; (completion-search-reset "foo") | |
2036 ;;; (completion-search-reset "cum") | |
2037 ;;; (completion-search-next 0) --> "cumberland" | |
2038 ;;; | |
2039 ;;; - Deleting - | |
2040 ;;; (kill-completion "cumberland") | |
2041 ;;; cummings | |
2042 ;;; (completion-search-reset "cum") | |
2043 ;;; (completion-search-next 0) --> "cumberbund" | |
2044 ;;; (completion-search-next 1) --> "cummings" | |
2045 ;;; | |
2046 ;;; - Ignoring Capitalization - | |
2047 ;;; (completion-search-reset "CuMb") | |
2048 ;;; (completion-search-next 0) --> "cumberbund" | |
2049 | |
2050 | |
2051 | |
2052 ;;;----------------------------------------------- | |
2053 ;;; COMPLETE | |
2054 ;;;----------------------------------------------- | |
2055 | |
2056 (defun completion-mode () | |
2057 "Toggles whether or not new words are added to the database." | |
2058 (interactive) | |
2059 (setq *completep* (not *completep*)) | |
2060 (message "Completion mode is now %s." (if *completep* "ON" "OFF")) | |
2061 ) | |
2062 | |
2063 (defvar cmpl-current-index 0) | |
2064 (defvar cmpl-original-string nil) | |
2065 (defvar cmpl-last-insert-location -1) | |
2066 (defvar cmpl-leave-point-at-start nil) | |
2067 | |
2068 (defun complete (&optional arg) | |
2069 "Inserts a completion at point. | |
2070 Point is left at end. Consective calls rotate through all possibilities. | |
2071 Prefix args :: | |
2072 control-u :: leave the point at the beginning of the completion rather | |
2073 than at the end. | |
2074 a number :: rotate through the possible completions by that amount | |
2075 `-' :: same as -1 (insert previous completion) | |
2076 {See the comments at the top of completion.el for more info.} | |
2077 " | |
2078 (interactive "*p") | |
2079 ;;; Set up variables | |
2080 (cond ((eq last-command this-command) | |
2081 ;; Undo last one | |
2082 (delete-region cmpl-last-insert-location (point)) | |
2083 ;; get next completion | |
2084 (setq cmpl-current-index (+ cmpl-current-index (or arg 1))) | |
2085 ) | |
2086 (t | |
2087 (if (not cmpl-initialized-p) | |
2088 (initialize-completions)) ;; make sure everything's loaded | |
2089 (cond ((consp current-prefix-arg) ;; control-u | |
2090 (setq arg 0) | |
2091 (setq cmpl-leave-point-at-start t) | |
2092 ) | |
2093 (t | |
2094 (setq cmpl-leave-point-at-start nil) | |
2095 )) | |
2096 ;; get string | |
2097 (setq cmpl-original-string (symbol-before-point-for-complete)) | |
2098 (cond ((not cmpl-original-string) | |
2099 (setq this-command 'failed-complete) | |
2100 (error "To complete, the point must be after a symbol at least %d character long." | |
2101 *completion-prefix-min-length*))) | |
2102 ;; get index | |
2103 (setq cmpl-current-index (if current-prefix-arg arg 0)) | |
2104 ;; statistics | |
2105 (cmpl-statistics-block | |
2106 (note-complete-entered-afresh cmpl-original-string)) | |
2107 ;; reset database | |
2108 (completion-search-reset cmpl-original-string) | |
2109 ;; erase what we've got | |
2110 (delete-region cmpl-symbol-start cmpl-symbol-end) | |
2111 )) | |
2112 | |
2113 ;; point is at the point to insert the new symbol | |
2114 ;; Get the next completion | |
2115 (let* ((print-status-p | |
2116 (and (>= (cmpl19-baud-rate) *print-next-completion-speed-threshold*) | |
2117 (not (minibuffer-window-selected-p)))) | |
2118 (insert-point (point)) | |
2119 (entry (completion-search-next cmpl-current-index)) | |
2120 string | |
2121 ) | |
2122 ;; entry is either a completion entry or a string (if cdabbrev) | |
2123 | |
2124 ;; If found, insert | |
2125 (cond (entry | |
2126 ;; Setup for proper case | |
2127 (setq string (if (stringp entry) | |
2128 entry (completion-string entry))) | |
2129 (setq string (cmpl-merge-string-cases | |
2130 string cmpl-original-string)) | |
2131 ;; insert | |
2132 (insert string) | |
2133 ;; accept it | |
2134 (setq completion-to-accept string) | |
2135 ;; fixup and cache point | |
2136 (cond (cmpl-leave-point-at-start | |
2137 (setq cmpl-last-insert-location (point)) | |
2138 (goto-char insert-point)) | |
2139 (t;; point at end, | |
2140 (setq cmpl-last-insert-location insert-point)) | |
2141 ) | |
2142 ;; statistics | |
2143 (cmpl-statistics-block | |
2144 (note-complete-inserted entry cmpl-current-index)) | |
2145 ;; Done ! cmpl-stat-complete-successful | |
2146 ;;display the next completion | |
2147 (cond | |
2148 ((and print-status-p | |
2149 ;; This updates the display and only prints if there | |
2150 ;; is no typeahead | |
2151 (cmpl19-sit-for 0) | |
2152 (setq entry | |
2153 (completion-search-peek | |
2154 *print-next-completion-does-cdabbrev-search-p*))) | |
2155 (setq string (if (stringp entry) | |
2156 entry (completion-string entry))) | |
2157 (setq string (cmpl-merge-string-cases | |
2158 string cmpl-original-string)) | |
2159 (message "Next completion: %s" string) | |
2160 )) | |
2161 ) | |
2162 (t;; none found, insert old | |
2163 (insert cmpl-original-string) | |
2164 ;; Don't accept completions | |
2165 (setq completion-to-accept nil) | |
2166 ;; print message | |
2167 (if (and print-status-p (cmpl19-sit-for 0)) | |
2168 (message "No %scompletions." | |
2169 (if (eq this-command last-command) "more " ""))) | |
2170 ;; statistics | |
2171 (cmpl-statistics-block | |
2172 (record-complete-failed cmpl-current-index)) | |
2173 ;; Pretend that we were never here | |
2174 (setq this-command 'failed-complete) | |
2175 )))) | |
2176 | |
2177 ;;;----------------------------------------------- | |
2178 ;;; "Complete" Key Keybindings | |
2179 ;;;----------------------------------------------- | |
2180 | |
2181 ;;; Complete key definition | |
2182 ;;; These define c-return and meta-return | |
2183 ;;; In any case you really want to bind this to a single keystroke | |
2184 (if (fboundp 'key-for-others-chord) | |
2185 (condition-case e | |
2186 ;; this can fail if some of the prefix chars. are already used | |
2187 ;; as commands (this happens on wyses) | |
2188 (global-set-key (key-for-others-chord "return" '(control)) 'complete) | |
2189 (error) | |
2190 )) | |
2191 (if (fboundp 'gmacs-keycode) | |
2192 (global-set-key (gmacs-keycode "return" '(control)) 'complete) | |
2193 ) | |
2194 (global-set-key "\M-\r" 'complete) | |
2195 | |
2196 ;;; Tests - | |
2197 ;;; (add-completion "cumberland") | |
2198 ;;; (add-completion "cumberbund") | |
2199 ;;; cum | |
2200 ;;; Cumber | |
2201 ;;; cumbering | |
2202 ;;; cumb | |
2203 | |
2204 | |
2205 ;;;--------------------------------------------------------------------------- | |
2206 ;;; Parsing definitions from files into the database | |
2207 ;;;--------------------------------------------------------------------------- | |
2208 | |
2209 ;;;----------------------------------------------- | |
2210 ;;; Top Level functions :: | |
2211 ;;;----------------------------------------------- | |
2212 | |
2213 ;;; User interface | |
2214 (defun add-completions-from-file (file) | |
2215 "Parses all the definition names from a Lisp mode file and adds them to the | |
2216 completion database." | |
2217 (interactive "fFile: ") | |
2218 (setq file (if (fboundp 'expand-file-name-defaulting) | |
2219 (expand-file-name-defaulting file) | |
2220 (expand-file-name file))) | |
2221 (let* ((buffer (get-file-buffer file)) | |
2222 (buffer-already-there-p buffer) | |
2223 ) | |
2224 (when (not buffer-already-there-p) | |
2225 (let ((*modes-for-completion-find-file-hook* nil)) | |
2226 (setq buffer (find-file-noselect file)) | |
2227 )) | |
2228 (unwind-protect | |
2229 (save-excursion | |
2230 (set-buffer buffer) | |
2231 (add-completions-from-buffer) | |
2232 ) | |
2233 (when (not buffer-already-there-p) | |
2234 (kill-buffer buffer)) | |
2235 ))) | |
2236 | |
2237 (defun add-completions-from-buffer () | |
2238 (interactive) | |
2239 (let ((current-completion-source cmpl-source-file-parsing) | |
2240 (start-num | |
2241 (cmpl-statistics-block | |
2242 (aref completion-add-count-vector cmpl-source-file-parsing))) | |
2243 mode | |
2244 ) | |
2245 (cond ((memq major-mode '(emacs-lisp-mode lisp-mode)) | |
2246 (add-completions-from-lisp-buffer) | |
2247 (setq mode 'lisp) | |
2248 ) | |
2249 ((memq major-mode '(c-mode)) | |
2250 (add-completions-from-c-buffer) | |
2251 (setq mode 'c) | |
2252 ) | |
2253 (t | |
2254 (error "Do not know how to parse completions in %s buffers." | |
2255 major-mode) | |
2256 )) | |
2257 (cmpl-statistics-block | |
2258 (record-cmpl-parse-file | |
2259 mode (point-max) | |
2260 (- (aref completion-add-count-vector cmpl-source-file-parsing) | |
2261 start-num))) | |
2262 )) | |
2263 | |
2264 ;;; Find file hook | |
2265 (defun cmpl-find-file-hook () | |
2266 (cond (*completep* | |
2267 (cond ((and (memq major-mode '(emacs-lisp-mode lisp-mode)) | |
2268 (memq 'lisp *modes-for-completion-find-file-hook*) | |
2269 ) | |
2270 (add-completions-from-buffer)) | |
2271 ((and (memq major-mode '(c-mode)) | |
2272 (memq 'c *modes-for-completion-find-file-hook*) | |
2273 ) | |
2274 (add-completions-from-buffer) | |
2275 ))) | |
2276 )) | |
2277 | |
2278 (pushnew 'cmpl-find-file-hook find-file-hooks) | |
2279 | |
2280 ;;;----------------------------------------------- | |
2281 ;;; Tags Table Completions | |
2282 ;;;----------------------------------------------- | |
2283 | |
2284 (defun add-completions-from-tags-table () | |
2285 ;; Inspired by eero@media-lab.media.mit.edu | |
2286 "Add completions from the current tags-table-buffer." | |
2287 (interactive) | |
2288 (visit-tags-table-buffer) ;this will prompt if no tags-table | |
2289 (save-excursion | |
2290 (goto-char (point-min)) | |
2291 (let (string) | |
2292 (condition-case e | |
2293 (while t | |
2294 (search-forward "\177") | |
2295 (backward-char 3) | |
2296 (and (setq string (symbol-under-point)) | |
2297 (add-completion-to-tail-if-new string)) | |
2298 (forward-char 3) | |
2299 ) | |
2300 (search-failed) | |
2301 )))) | |
2302 | |
2303 | |
2304 ;;;----------------------------------------------- | |
2305 ;;; Lisp File completion parsing | |
2306 ;;;----------------------------------------------- | |
2307 ;;; This merely looks for phrases beginning with (def.... or | |
2308 ;;; (package:def ... and takes the next word. | |
2309 ;;; | |
2310 ;;; We tried using forward-lines and explicit searches but the regexp technique | |
2311 ;;; was faster. (About 100K characters per second) | |
2312 ;;; | |
2313 (defconst *lisp-def-regexp* | |
2314 "\n(\\(\\w*:\\)?def\\(\\w\\|\\s_\\)*\\s +(*" | |
2315 "A regexp that searches for lisp definition form." | |
2316 ) | |
2317 | |
2318 ;;; Tests - | |
2319 ;;; (and (string-match *lisp-def-regexp* "\n(defun foo") (match-end 0)) -> 8 | |
2320 ;;; (and (string-match *lisp-def-regexp* "\n(si:def foo") (match-end 0)) -> 9 | |
2321 ;;; (and (string-match *lisp-def-regexp* "\n(def-bar foo")(match-end 0)) -> 10 | |
2322 ;;; (and (string-match *lisp-def-regexp* "\n(defun (foo") (match-end 0)) -> 9 | |
2323 | |
2324 (defun add-completions-from-lisp-buffer () | |
2325 "Parses all the definition names from a Lisp mode buffer and adds them to | |
2326 the completion database." | |
2327 ;;; Benchmarks | |
2328 ;;; Sun-3/280 - 1500 to 3000 lines of lisp code per second | |
2329 (let (string) | |
2330 (save-excursion | |
2331 (goto-char (point-min)) | |
2332 (condition-case e | |
2333 (while t | |
2334 (re-search-forward *lisp-def-regexp*) | |
2335 (and (setq string (symbol-under-point)) | |
2336 (add-completion-to-tail-if-new string)) | |
2337 ) | |
2338 (search-failed) | |
2339 )))) | |
2340 | |
2341 | |
2342 ;;;----------------------------------------------- | |
2343 ;;; C file completion parsing | |
2344 ;;;----------------------------------------------- | |
2345 ;;; C : | |
2346 ;;; Looks for #define or [<storage class>] [<type>] <name>{,<name>} | |
2347 ;;; or structure, array or pointer defs. | |
2348 ;;; It gets most of the definition names. | |
2349 ;;; | |
2350 ;;; As you might suspect by now, we use some symbol table hackery | |
2351 ;;; | |
2352 ;;; Symbol separator chars (have whitespace syntax) --> , ; * = ( | |
2353 ;;; Opening char --> [ { | |
2354 ;;; Closing char --> ] } | |
2355 ;;; openning and closing must be skipped over | |
2356 ;;; Whitespace chars (have symbol syntax) | |
2357 ;;; Everything else has word syntax | |
2358 | |
2359 (defun make-c-def-completion-syntax-table () | |
2360 (let ((table (make-vector 256 0)) | |
2361 (whitespace-chars '(? ?\n ?\t ?\f ?\v ?\r)) | |
2362 ;; unforunately the ?( causes the parens to appear unbalanced | |
2363 (separator-chars '(?, ?* ?= ?\( ?\; | |
2364 )) | |
2365 ) | |
2366 ;; default syntax is whitespace | |
2367 (dotimes (i 256) | |
2368 (modify-syntax-entry i "w" table)) | |
2369 (dolist (char whitespace-chars) | |
2370 (modify-syntax-entry char "_" table)) | |
2371 (dolist (char separator-chars) | |
2372 (modify-syntax-entry char " " table)) | |
2373 (modify-syntax-entry ?\[ "(]" table) | |
2374 (modify-syntax-entry ?\{ "(}" table) | |
2375 (modify-syntax-entry ?\] ")[" table) | |
2376 (modify-syntax-entry ?\} "){" table) | |
2377 table)) | |
2378 | |
2379 (defconst cmpl-c-def-syntax-table (make-c-def-completion-syntax-table)) | |
2380 | |
2381 ;;; Regexps | |
2382 (defconst *c-def-regexp* | |
2383 ;; This stops on lines with possible definitions | |
2384 "\n[_a-zA-Z#]" | |
2385 ;; This stops after the symbol to add. | |
2386 ;;"\n\\(#define\\s +.\\|\\(\\(\\w\\|\\s_\\)+\\b\\s *\\)+[(;,[*{=]\\)" | |
2387 ;; This stops before the symbol to add. {Test cases in parens. below} | |
2388 ;;"\n\\(\\(\\w\\|\\s_\\)+\\s *(\\|\\(\\(#define\\|auto\\|extern\\|register\\|static\\|int\\|long\\|short\\|unsigned\\|char\\|void\\|float\\|double\\|enum\\|struct\\|union\\|typedef\\)\\s +\\)+\\)" | |
2389 ;; this simple version picks up too much extraneous stuff | |
2390 ;; "\n\\(\\w\\|\\s_\\|#\\)\\B" | |
2391 "A regexp that searches for a definition form." | |
2392 ) | |
2393 ; | |
2394 ;(defconst *c-cont-regexp* | |
2395 ; "\\(\\w\\|\\s_\\)+\\b\\s *\\({\\|\\(\\[[0-9\t ]*\\]\\s *\\)*,\\(*\\|\\s \\)*\\b\\)" | |
2396 ; "This regexp should be used in a looking-at to parse for lists of variables.") | |
2397 ; | |
2398 ;(defconst *c-struct-regexp* | |
2399 ; "\\(*\\|\\s \\)*\\b" | |
2400 ; "This regexp should be used to test whether a symbol follows a structure definition.") | |
2401 | |
2402 ;(defun test-c-def-regexp (regexp string) | |
2403 ; (and (eq 0 (string-match regexp string)) (match-end 0)) | |
2404 ; ) | |
2405 | |
2406 ;;; Tests - | |
2407 ;;; (test-c-def-regexp *c-def-regexp* "\n#define foo") -> 10 (9) | |
2408 ;;; (test-c-def-regexp *c-def-regexp* "\nfoo (x, y) {") -> 6 (6) | |
2409 ;;; (test-c-def-regexp *c-def-regexp* "\nint foo (x, y)") -> 10 (5) | |
2410 ;;; (test-c-def-regexp *c-def-regexp* "\n int foo (x, y)") -> nil | |
2411 ;;; (test-c-def-regexp *c-cont-regexp* "oo, bar") -> 4 | |
2412 ;;; (test-c-def-regexp *c-cont-regexp* "oo, *bar") -> 5 | |
2413 ;;; (test-c-def-regexp *c-cont-regexp* "a [5][6], bar") -> 10 | |
2414 ;;; (test-c-def-regexp *c-cont-regexp* "oo(x,y)") -> nil | |
2415 ;;; (test-c-def-regexp *c-cont-regexp* "a [6] ,\t bar") -> 9 | |
2416 ;;; (test-c-def-regexp *c-cont-regexp* "oo {trout =1} my_carp;") -> 14 | |
2417 ;;; (test-c-def-regexp *c-cont-regexp* "truct_p complex foon") -> nil | |
2418 | |
2419 (defun add-completions-from-c-buffer () | |
2420 "Parses all the definition names from a C mode buffer and adds them to the | |
2421 completion database." | |
2422 ;; Benchmark -- | |
2423 ;; Sun 3/280-- 1250 lines/sec. | |
2424 | |
2425 (let (string next-point char | |
2426 (saved-syntax (syntax-table)) | |
2427 ) | |
2428 (save-excursion | |
2429 (goto-char (point-min)) | |
2430 (catch 'finish-add-completions | |
2431 (unwind-protect | |
2432 (while t | |
2433 ;; we loop here only when scan-sexps fails | |
2434 ;; (i.e. unbalance exps.) | |
2435 (set-syntax-table cmpl-c-def-syntax-table) | |
2436 (condition-case e | |
2437 (while t | |
2438 (re-search-forward *c-def-regexp*) | |
2439 (cond | |
2440 ((= (preceding-char) ?#) | |
2441 ;; preprocessor macro, see if it's one we handle | |
2442 (setq string (buffer-substring (point) (+ (point) 6))) | |
2443 (cond ((or (string-equal string "define") | |
2444 (string-equal string "ifdef ") | |
2445 ) | |
2446 ;; skip forward over definition symbol | |
2447 ;; and add it to database | |
2448 (and (forward-word 2) | |
2449 (setq string (symbol-before-point)) | |
2450 ;;(push string foo) | |
2451 (add-completion-to-tail-if-new string) | |
2452 )))) | |
2453 (t | |
2454 ;; C definition | |
2455 (setq next-point (point)) | |
2456 (while (and | |
2457 next-point | |
2458 ;; scan to next separator char. | |
2459 (setq next-point (scan-sexps next-point 1)) | |
2460 ) | |
2461 ;; position the point on the word we want to add | |
2462 (goto-char next-point) | |
2463 (while (= (setq char (following-char)) ?*) | |
2464 ;; handle pointer ref | |
2465 ;; move to next separator char. | |
2466 (goto-char | |
2467 (setq next-point (scan-sexps (point) 1))) | |
2468 ) | |
2469 (forward-word -1) | |
2470 ;; add to database | |
2471 (if (setq string (symbol-under-point)) | |
2472 ;; (push string foo) | |
2473 (add-completion-to-tail-if-new string) | |
2474 ;; Local TMC hack (useful for parsing paris.h) | |
2475 (if (and (looking-at "_AP") ;; "ansi prototype" | |
2476 (progn | |
2477 (forward-word -1) | |
2478 (setq string | |
2479 (symbol-under-point)) | |
2480 )) | |
2481 (add-completion-to-tail-if-new string) | |
2482 ) | |
2483 ) | |
2484 ;; go to next | |
2485 (goto-char next-point) | |
2486 ;; (push (format "%c" (following-char)) foo) | |
2487 (if (= (char-syntax char) ?\() | |
2488 ;; if on an opening delimiter, go to end | |
2489 (while (= (char-syntax char) ?\() | |
2490 (setq next-point (scan-sexps next-point 1) | |
2491 char (char-after next-point)) | |
2492 ) | |
2493 (or (= char ?,) | |
2494 ;; Current char is an end char. | |
2495 (setq next-point nil) | |
2496 )) | |
2497 )))) | |
2498 (search-failed ;;done | |
2499 (throw 'finish-add-completions t) | |
2500 ) | |
2501 (error | |
2502 ;; Check for failure in scan-sexps | |
2503 (if (or (string-equal (second e) | |
2504 "Containing expression ends prematurely") | |
2505 (string-equal (second e) "Unbalanced parentheses")) | |
2506 ;; unbalanced paren., keep going | |
2507 ;;(ding) | |
2508 (forward-line 1) | |
2509 (message "Error parsing C buffer for completions. Please bug report.") | |
2510 (throw 'finish-add-completions t) | |
2511 )) | |
2512 )) | |
2513 (set-syntax-table saved-syntax) | |
2514 ))))) | |
2515 | |
2516 | |
2517 ;;;--------------------------------------------------------------------------- | |
2518 ;;; Init files | |
2519 ;;;--------------------------------------------------------------------------- | |
2520 | |
2521 (defun kill-emacs-save-completions () | |
1356 | 2522 "The version of save-completions-to-file called at kill-emacs time." |
56 | 2523 (when (and *save-completions-p* *completep* cmpl-initialized-p) |
2524 (cond | |
2525 ((not cmpl-completions-accepted-p) | |
2526 (message "Completions database has not changed - not writing.")) | |
2527 (t | |
2528 (save-completions-to-file) | |
2529 )) | |
2530 )) | |
2531 | |
2532 (defconst saved-cmpl-file-header | |
2533 ";;; Completion Initialization file. | |
2534 ;;; Version = %s | |
2535 ;;; Format is (<string> . <last-use-time>) | |
2536 ;;; <string> is the completion | |
2537 ;;; <last-use-time> is the time the completion was last used | |
2538 ;;; If it is t, the completion will never be pruned from the file. | |
2539 ;;; Otherwise it is in hours since 1900. | |
2540 \n") | |
2541 | |
2542 (defun completion-backup-filename (filename) | |
2543 (concat filename ".BAK")) | |
2544 | |
2545 (defun save-completions-to-file (&optional filename) | |
1356 | 2546 "Saves a completion init file. |
2547 If file is not specified, then *saved-completions-filename* is used." | |
56 | 2548 (interactive) |
2549 (setq filename (expand-file-name (or filename *saved-completions-filename*))) | |
2550 (when (file-writable-p filename) | |
2551 (if (not cmpl-initialized-p) | |
2552 (initialize-completions));; make sure everything's loaded | |
2553 (message "Saving completions to file %s" filename) | |
2554 | |
2555 (let* ((trim-versions-without-asking t) | |
2556 (kept-old-versions 0) | |
2557 (kept-new-versions *completion-file-versions-kept*) | |
2558 last-use-time | |
2559 (current-time (cmpl-hours-since-1900)) | |
2560 (total-in-db 0) | |
2561 (total-perm 0) | |
2562 (total-saved 0) | |
2563 (backup-filename (completion-backup-filename filename)) | |
2564 ) | |
2565 | |
2566 (save-excursion | |
2567 (get-buffer-create " *completion-save-buffer*") | |
2568 (set-buffer " *completion-save-buffer*") | |
2569 (setq buffer-file-name filename) | |
2570 | |
2571 (when (not (verify-visited-file-modtime (current-buffer))) | |
2572 ;; file has changed on disk. Bring us up-to-date | |
2573 (message "Completion file has changed. Merging. . .") | |
2574 (load-completions-from-file filename t) | |
2575 (message "Merging finished. Saving completions to file %s" filename) | |
2576 ) | |
2577 | |
2578 ;; prepare the buffer to be modified | |
2579 (clear-visited-file-modtime) | |
2580 (erase-buffer) | |
2581 ;; (/ 1 0) | |
2582 (insert (format saved-cmpl-file-header *completion-version*)) | |
2583 (dolist (completion (list-all-completions)) | |
2584 (setq total-in-db (1+ total-in-db)) | |
2585 (setq last-use-time (completion-last-use-time completion)) | |
2586 ;; Update num uses and maybe write completion to a file | |
2587 (cond ((or;; Write to file if | |
2588 ;; permanent | |
2589 (and (eq last-use-time t) | |
2590 (setq total-perm (1+ total-perm))) | |
2591 ;; or if | |
2592 (if (plusp (completion-num-uses completion)) | |
2593 ;; it's been used | |
2594 (setq last-use-time current-time) | |
2595 ;; or it was saved before and | |
2596 (and last-use-time | |
2597 ;; *saved-completion-retention-time* is nil | |
2598 (or (not *saved-completion-retention-time*) | |
2599 ;; or time since last use is < ...retention-time* | |
2600 (< (- current-time last-use-time) | |
2601 *saved-completion-retention-time*)) | |
2602 ))) | |
2603 ;; write to file | |
2604 (setq total-saved (1+ total-saved)) | |
2605 (insert (prin1-to-string (cons (completion-string completion) | |
2606 last-use-time)) "\n") | |
2607 ))) | |
2608 | |
2609 ;; write the buffer | |
2610 (condition-case e | |
2611 (let ((file-exists-p (file-exists-p filename))) | |
2612 (when file-exists-p | |
2613 ;; If file exists . . . | |
2614 ;; Save a backup(so GNU doesn't screw us when we're out of disk) | |
2615 ;; (GNU leaves a 0 length file if it gets a disk full error!) | |
2616 | |
2617 ;; If backup doesn't exit, Rename current to backup | |
2618 ;; {If backup exists the primary file is probably messed up} | |
2619 (unless (file-exists-p backup-filename) | |
2620 (rename-file filename backup-filename)) | |
2621 ;; Copy the backup back to the current name | |
2622 ;; (so versioning works) | |
2623 (copy-file backup-filename filename t) | |
2624 ) | |
2625 ;; Save it | |
2626 (save-buffer) | |
2627 (when file-exists-p | |
2628 ;; If successful, remove backup | |
2629 (delete-file backup-filename) | |
2630 )) | |
2631 (error | |
2632 (set-buffer-modified-p nil) | |
2633 (message "Couldn't save completion file %s." filename) | |
2634 )) | |
2635 ;; Reset accepted-p flag | |
2636 (setq cmpl-completions-accepted-p nil) | |
2637 ) | |
2638 (cmpl-statistics-block | |
2639 (record-save-completions total-in-db total-perm total-saved)) | |
2640 ))) | |
2641 | |
2642 (defun autosave-completions () | |
2643 (when (and *save-completions-p* *completep* cmpl-initialized-p | |
2644 *completion-auto-save-period* | |
2645 (> cmpl-emacs-idle-time *completion-auto-save-period*) | |
2646 cmpl-completions-accepted-p) | |
2647 (save-completions-to-file) | |
2648 )) | |
2649 | |
2650 (pushnew 'autosave-completions cmpl-emacs-idle-time-hooks) | |
2651 | |
2652 (defun load-completions-from-file (&optional filename no-message-p) | |
1356 | 2653 "Loads a completion init file. |
2654 If file is not specified, then *saved-completions-filename* is used." | |
56 | 2655 (interactive) |
2656 (setq filename (expand-file-name (or filename *saved-completions-filename*))) | |
2657 (let* ((backup-filename (completion-backup-filename filename)) | |
2658 (backup-readable-p (file-readable-p backup-filename)) | |
2659 ) | |
2660 (when backup-readable-p (setq filename backup-filename)) | |
2661 (when (file-readable-p filename) | |
2662 (if (not no-message-p) | |
2663 (message "Loading completions from %sfile %s . . ." | |
2664 (if backup-readable-p "backup " "") filename)) | |
2665 (save-excursion | |
2666 (get-buffer-create " *completion-save-buffer*") | |
2667 (set-buffer " *completion-save-buffer*") | |
2668 (setq buffer-file-name filename) | |
2669 ;; prepare the buffer to be modified | |
2670 (clear-visited-file-modtime) | |
2671 (erase-buffer) | |
2672 | |
2673 (let ((insert-okay-p nil) | |
2674 (buffer (current-buffer)) | |
2675 (current-time (cmpl-hours-since-1900)) | |
2676 string num-uses entry last-use-time | |
2677 cmpl-entry cmpl-last-use-time | |
2678 (current-completion-source cmpl-source-init-file) | |
2679 (start-num | |
2680 (cmpl-statistics-block | |
2681 (aref completion-add-count-vector cmpl-source-file-parsing))) | |
2682 (total-in-file 0) (total-perm 0) | |
2683 ) | |
2684 ;; insert the file into a buffer | |
2685 (condition-case e | |
2686 (progn (insert-file-contents filename t) | |
2687 (setq insert-okay-p t)) | |
2688 | |
2689 (file-error | |
2690 (message "File error trying to load completion file %s." | |
2691 filename))) | |
2692 ;; parse it | |
2693 (when insert-okay-p | |
2694 (goto-char (point-min)) | |
2695 | |
2696 (condition-case e | |
2697 (while t | |
2698 (setq entry (read buffer)) | |
2699 (setq total-in-file (1+ total-in-file)) | |
2700 (cond | |
2701 ((and (consp entry) | |
2702 (stringp (setq string (car entry))) | |
2703 (cond | |
2704 ((eq (setq last-use-time (cdr entry)) 'T) | |
2705 ;; handle case sensitivity | |
2706 (setq total-perm (1+ total-perm)) | |
2707 (setq last-use-time t)) | |
2708 ((eq last-use-time t) | |
2709 (setq total-perm (1+ total-perm))) | |
2710 ((integerp last-use-time)) | |
2711 )) | |
2712 ;; Valid entry | |
2713 ;; add it in | |
2714 (setq cmpl-last-use-time | |
2715 (completion-last-use-time | |
2716 (setq cmpl-entry | |
2717 (add-completion-to-tail-if-new string)) | |
2718 )) | |
2719 (if (or (eq last-use-time t) | |
2720 (and (> last-use-time 1000);;backcompatibility | |
2721 (not (eq cmpl-last-use-time t)) | |
2722 (or (not cmpl-last-use-time) | |
2723 ;; more recent | |
2724 (> last-use-time cmpl-last-use-time)) | |
2725 )) | |
2726 ;; update last-use-time | |
2727 (set-completion-last-use-time cmpl-entry last-use-time) | |
2728 )) | |
2729 (t | |
2730 ;; Bad format | |
2731 (message "Error: invalid saved completion - %s" | |
2732 (prin1-to-string entry)) | |
2733 ;; try to get back in sync | |
2734 (search-forward "\n(") | |
2735 ))) | |
2736 (search-failed | |
2737 (message "End of file while reading completions.") | |
2738 ) | |
2739 (end-of-file | |
2740 (if (= (point) (point-max)) | |
2741 (if (not no-message-p) | |
2742 (message "Loading completions from file %s . . . Done." | |
2743 filename)) | |
2744 (message "End of file while reading completions.") | |
2745 )) | |
2746 )) | |
2747 | |
2748 (cmpl-statistics-block | |
2749 (record-load-completions | |
2750 total-in-file total-perm | |
2751 (- (aref completion-add-count-vector cmpl-source-init-file) | |
2752 start-num))) | |
2753 | |
2754 ))))) | |
2755 | |
2756 (defun initialize-completions () | |
1356 | 2757 "Loads the default completions file. |
2758 Also sets up so that exiting emacs will automatically save the file." | |
56 | 2759 (interactive) |
2760 (cond ((not cmpl-initialized-p) | |
2761 (load-completions-from-file) | |
2762 )) | |
2763 (init-cmpl-emacs-idle-process) | |
2764 (setq cmpl-initialized-p t) | |
2765 ) | |
2766 | |
2767 | |
2768 ;;;----------------------------------------------- | |
2769 ;;; Kill EMACS patch | |
2770 ;;;----------------------------------------------- | |
2771 | |
2772 (completion-advise kill-emacs :before | |
2773 ;; | All completion code should go in here | |
2774 ;;\ / | |
2775 (kill-emacs-save-completions) | |
2776 ;;/ \ | |
2777 ;; | All completion code should go in here | |
2778 (cmpl-statistics-block | |
2779 (record-cmpl-kill-emacs)) | |
2780 ) | |
2781 | |
2782 | |
2783 ;;;----------------------------------------------- | |
2784 ;;; Kill region patch | |
2785 ;;;----------------------------------------------- | |
2786 | |
2787 ;;; Patched to remove the most recent completion | |
2788 (defvar $$$cmpl-old-kill-region (symbol-function 'kill-region)) | |
2789 | |
2790 (defun kill-region (&optional beg end) | |
2791 "Kill between point and mark. | |
2792 The text is deleted but saved in the kill ring. | |
2793 The command \\[yank] can retrieve it from there. | |
2794 /(If you want to kill and then yank immediately, use \\[copy-region-as-kill].) | |
2795 | |
2796 This is the primitive for programs to kill text (as opposed to deleting it). | |
2797 Supply two arguments, character numbers indicating the stretch of text | |
2798 to be killed. | |
2799 Any command that calls this function is a \"kill command\". | |
2800 If the previous command was also a kill command, | |
2801 the text killed this time appends to the text killed last time | |
2802 to make one entry in the kill ring. | |
2803 Patched to remove the most recent completion." | |
2804 (interactive "*") | |
2805 (cond ((and (eq last-command 'complete) (eq last-command-char ?\C-w)) | |
2806 (delete-region (point) cmpl-last-insert-location) | |
2807 (insert cmpl-original-string) | |
2808 (setq completion-to-accept nil) | |
2809 (cmpl-statistics-block | |
2810 (record-complete-failed)) | |
2811 ) | |
2812 (t | |
2813 (if (not beg) | |
2814 (setq beg (min (point) (mark)) | |
2815 end (max (point) (mark))) | |
2816 ) | |
2817 (funcall $$$cmpl-old-kill-region beg end) | |
2818 ))) | |
2819 | |
2820 ;;;----------------------------------------------- | |
2821 ;;; Patches to self-insert-command. | |
2822 ;;;----------------------------------------------- | |
2823 | |
2824 ;;; Need 2 versions: generic seperator chars. and space (to get auto fill | |
2825 ;;; to work) | |
2826 | |
2827 ;;; All common separators (eg. space "(" ")" """) characters go through a | |
2828 ;;; function to add new words to the list of words to complete from: | |
2829 ;;; COMPLETION-SEPARATOR-SELF-INSERT-COMMAND (arg). | |
2830 ;;; If the character before this was an alpha-numeric then this adds the | |
2831 ;;; symbol befoe point to the completion list (using ADD-COMPLETION). | |
2832 | |
2833 (defun completion-separator-self-insert-command (arg) | |
2834 (interactive "p") | |
2835 (use-completion-before-separator) | |
2836 (self-insert-command arg) | |
2837 ) | |
2838 | |
2839 (defun completion-separator-self-insert-autofilling (arg) | |
2840 (interactive "p") | |
2841 (use-completion-before-separator) | |
2842 (self-insert-command arg) | |
2843 (and (> (current-column) fill-column) | |
732 | 2844 auto-fill-function |
2845 (funcall auto-fill-function)) | |
56 | 2846 ) |
2847 | |
2848 ;;;----------------------------------------------- | |
2849 ;;; Wrapping Macro | |
2850 ;;;----------------------------------------------- | |
2851 | |
2852 ;;; Note that because of the way byte compiling works, none of | |
2853 ;;; the functions defined with this macro get byte compiled. | |
2854 | |
2855 (defmacro def-completion-wrapper (function-name type &optional new-name) | |
1356 | 2856 "Add a call to update the completion database before function execution. |
2857 TYPE is the type of the wrapper to be added. Can be :before or :under." | |
56 | 2858 (completion-advise-1 |
2859 function-name ':before | |
2860 (ecase type | |
2861 (:before '((use-completion-before-point))) | |
2862 (:separator '((use-completion-before-separator))) | |
2863 (:under '((use-completion-under-point))) | |
2864 (:under-or-before | |
2865 '((use-completion-under-or-before-point))) | |
2866 (:minibuffer-separator | |
2867 '((let ((cmpl-syntax-table cmpl-standard-syntax-table)) | |
2868 (use-completion-before-separator)))) | |
2869 ) | |
2870 new-name | |
2871 )) | |
2872 | |
2873 ;;;(defun foo (x y z) (+ x y z)) | |
2874 ;;;foo | |
2875 ;;;(macroexpand '(def-completion-wrapper foo :under)) | |
2876 ;;;(progn (defvar $$$cmpl-foo (symbol-function (quote foo))) (defun foo (&rest arglist) (progn (use-completion-under-point)) (cmpl-apply-as-top-level $$$cmpl-foo arglist))) | |
2877 ;;;(defun bar (x y z) "Documentation" (+ x y z)) | |
2878 ;;;bar | |
2879 ;;;(macroexpand '(def-completion-wrapper bar :under)) | |
2880 ;;;(progn (defvar $$$cmpl-bar (symbol-function (quote bar))) (defun bar (&rest arglist) "Documentation" (progn (use-completion-under-point)) (cmpl-apply-as-top-level $$$cmpl-bar arglist))) | |
2881 ;;;(defun quuz (x &optional y z) "Documentation" (interactive "P") (+ x y z)) | |
2882 ;;;quuz | |
2883 ;;;(macroexpand '(def-completion-wrapper quuz :before)) | |
2884 ;;;(progn (defvar $$$cmpl-quuz (symbol-function (quote quuz))) (defun quuz (&rest arglist) "Documentation" (interactive) (progn (use-completion-before-point)) (cmpl-apply-as-top-level $$$cmpl-quuz arglist))) | |
2885 | |
2886 | |
2887 ;;;--------------------------------------------------------------------------- | |
2888 ;;; Patches to standard keymaps insert completions | |
2889 ;;;--------------------------------------------------------------------------- | |
2890 | |
2891 ;;;----------------------------------------------- | |
2892 ;;; Separators | |
2893 ;;;----------------------------------------------- | |
2894 ;;; We've used the completion syntax table given as a guide. | |
2895 ;;; | |
2896 ;;; Global separator chars. | |
2897 ;;; We left out <tab> because there are too many special cases for it. Also, | |
2898 ;;; in normal coding it's rarely typed after a word. | |
2899 (global-set-key " " 'completion-separator-self-insert-autofilling) | |
2900 (global-set-key "!" 'completion-separator-self-insert-command) | |
2901 (global-set-key "%" 'completion-separator-self-insert-command) | |
2902 (global-set-key "^" 'completion-separator-self-insert-command) | |
2903 (global-set-key "&" 'completion-separator-self-insert-command) | |
2904 (global-set-key "(" 'completion-separator-self-insert-command) | |
2905 (global-set-key ")" 'completion-separator-self-insert-command) | |
2906 (global-set-key "=" 'completion-separator-self-insert-command) | |
2907 (global-set-key "`" 'completion-separator-self-insert-command) | |
2908 (global-set-key "|" 'completion-separator-self-insert-command) | |
2909 (global-set-key "{" 'completion-separator-self-insert-command) | |
2910 (global-set-key "}" 'completion-separator-self-insert-command) | |
2911 (global-set-key "[" 'completion-separator-self-insert-command) | |
2912 (global-set-key "]" 'completion-separator-self-insert-command) | |
2913 (global-set-key ";" 'completion-separator-self-insert-command) | |
2914 (global-set-key "\"" 'completion-separator-self-insert-command) | |
2915 (global-set-key "'" 'completion-separator-self-insert-command) | |
2916 (global-set-key "#" 'completion-separator-self-insert-command) | |
2917 (global-set-key "," 'completion-separator-self-insert-command) | |
2918 (global-set-key "?" 'completion-separator-self-insert-command) | |
2919 | |
2920 ;;; We include period and colon even though they are symbol chars because : | |
2921 ;;; - in text we want to pick up the last word in a sentence. | |
2922 ;;; - in C pointer refs. we want to pick up the first symbol | |
2923 ;;; - it won't make a difference for lisp mode (package names are short) | |
2924 (global-set-key "." 'completion-separator-self-insert-command) | |
2925 (global-set-key ":" 'completion-separator-self-insert-command) | |
2926 | |
2927 ;;; Lisp Mode diffs | |
2928 (define-key lisp-mode-map "!" 'self-insert-command) | |
2929 (define-key lisp-mode-map "&" 'self-insert-command) | |
2930 (define-key lisp-mode-map "%" 'self-insert-command) | |
2931 (define-key lisp-mode-map "?" 'self-insert-command) | |
2932 (define-key lisp-mode-map "=" 'self-insert-command) | |
2933 (define-key lisp-mode-map "^" 'self-insert-command) | |
2934 | |
2935 ;;; C mode diffs. | |
2936 (def-completion-wrapper electric-c-semi :separator) | |
2937 (define-key c-mode-map "+" 'completion-separator-self-insert-command) | |
2938 (define-key c-mode-map "*" 'completion-separator-self-insert-command) | |
2939 (define-key c-mode-map "/" 'completion-separator-self-insert-command) | |
2940 | |
2941 ;;; FORTRAN mode diffs. (these are defined when fortran is called) | |
2942 (defun completion-setup-fortran-mode () | |
2943 (define-key fortran-mode-map "+" 'completion-separator-self-insert-command) | |
2944 (define-key fortran-mode-map "-" 'completion-separator-self-insert-command) | |
2945 (define-key fortran-mode-map "*" 'completion-separator-self-insert-command) | |
2946 (define-key fortran-mode-map "/" 'completion-separator-self-insert-command) | |
2947 ) | |
2948 | |
2949 ;;;----------------------------------------------- | |
2950 ;;; End of line chars. | |
2951 ;;;----------------------------------------------- | |
2952 (def-completion-wrapper newline :separator) | |
2953 (def-completion-wrapper newline-and-indent :separator) | |
2954 (if (function-defined-and-loaded 'shell-send-input) | |
2955 (def-completion-wrapper shell-send-input :separator)) | |
2956 (def-completion-wrapper exit-minibuffer :minibuffer-separator) | |
2957 (def-completion-wrapper eval-print-last-sexp :separator) | |
2958 (def-completion-wrapper eval-last-sexp :separator) | |
2959 ;;(def-completion-wrapper minibuffer-complete-and-exit :minibuffer) | |
2960 | |
2961 ;;;----------------------------------------------- | |
2962 ;;; Cursor movement | |
2963 ;;;----------------------------------------------- | |
2964 | |
2965 (def-completion-wrapper next-line :under-or-before) | |
2966 (def-completion-wrapper previous-line :under-or-before) | |
2967 (def-completion-wrapper beginning-of-buffer :under-or-before) | |
2968 (def-completion-wrapper end-of-buffer :under-or-before) | |
2969 | |
2970 ;; we patch these explicitly so they byte compile and so we don't have to | |
2971 ;; patch the faster underlying function. | |
2972 | |
2973 (defun cmpl-beginning-of-line (&optional n) | |
2974 "Move point to beginning of current line.\n\ | |
2975 With argument ARG not nil or 1, move forward ARG - 1 lines first.\n\ | |
2976 If scan reaches end of buffer, stop there without error." | |
2977 (interactive "p") | |
2978 (use-completion-under-or-before-point) | |
2979 (beginning-of-line n) | |
2980 ) | |
2981 | |
2982 (defun cmpl-end-of-line (&optional n) | |
2983 "Move point to end of current line.\n\ | |
2984 With argument ARG not nil or 1, move forward ARG - 1 lines first.\n\ | |
2985 If scan reaches end of buffer, stop there without error." | |
2986 (interactive "p") | |
2987 (use-completion-under-or-before-point) | |
2988 (end-of-line n) | |
2989 ) | |
2990 | |
2991 (defun cmpl-forward-char (n) | |
2992 "Move point right ARG characters (left if ARG negative).\n\ | |
2993 On reaching end of buffer, stop and signal error." | |
2994 (interactive "p") | |
2995 (use-completion-under-or-before-point) | |
2996 (forward-char n) | |
2997 ) | |
2998 (defun cmpl-backward-char (n) | |
2999 "Move point left ARG characters (right if ARG negative).\n\ | |
3000 On attempt to pass beginning or end of buffer, stop and signal error." | |
3001 (interactive "p") | |
3002 (use-completion-under-point) | |
3003 (if (eq last-command 'complete) | |
3004 ;; probably a failed completion if you have to back up | |
3005 (cmpl-statistics-block (record-complete-failed))) | |
3006 (backward-char n) | |
3007 ) | |
3008 | |
3009 (defun cmpl-forward-word (n) | |
3010 "Move point forward ARG words (backward if ARG is negative).\n\ | |
3011 Normally returns t.\n\ | |
3012 If an edge of the buffer is reached, point is left there\n\ | |
3013 and nil is returned." | |
3014 (interactive "p") | |
3015 (use-completion-under-or-before-point) | |
3016 (forward-word n) | |
3017 ) | |
3018 (defun cmpl-backward-word (n) | |
3019 "Move backward until encountering the end of a word. | |
3020 With argument, do this that many times. | |
3021 In programs, it is faster to call forward-word with negative arg." | |
3022 (interactive "p") | |
3023 (use-completion-under-point) | |
3024 (if (eq last-command 'complete) | |
3025 ;; probably a failed completion if you have to back up | |
3026 (cmpl-statistics-block (record-complete-failed))) | |
3027 (forward-word (- n)) | |
3028 ) | |
3029 | |
3030 (defun cmpl-forward-sexp (n) | |
3031 "Move forward across one balanced expression. | |
3032 With argument, do this that many times." | |
3033 (interactive "p") | |
3034 (use-completion-under-or-before-point) | |
3035 (forward-sexp n) | |
3036 ) | |
3037 (defun cmpl-backward-sexp (n) | |
3038 "Move backward across one balanced expression. | |
3039 With argument, do this that many times." | |
3040 (interactive "p") | |
3041 (use-completion-under-point) | |
3042 (if (eq last-command 'complete) | |
3043 ;; probably a failed completion if you have to back up | |
3044 (cmpl-statistics-block (record-complete-failed))) | |
3045 (backward-sexp n) | |
3046 ) | |
3047 | |
3048 (defun cmpl-delete-backward-char (n killflag) | |
3049 "Delete the previous ARG characters (following, with negative ARG).\n\ | |
3050 Optional second arg KILLFLAG non-nil means kill instead (save in kill ring).\n\ | |
3051 Interactively, ARG is the prefix arg, and KILLFLAG is set if\n\ | |
3052 ARG was explicitly specified." | |
3053 (interactive "p\nP") | |
3054 (if (eq last-command 'complete) | |
3055 ;; probably a failed completion if you have to back up | |
3056 (cmpl-statistics-block (record-complete-failed))) | |
3057 (delete-backward-char n killflag) | |
3058 ) | |
3059 | |
3060 (defvar $$$cmpl-old-backward-delete-char-untabify | |
3061 (symbol-function 'backward-delete-char-untabify)) | |
3062 | |
3063 (defun backward-delete-char-untabify (arg &optional killp) | |
3064 "Delete characters backward, changing tabs into spaces. | |
3065 Delete ARG chars, and kill (save in kill ring) if KILLP is non-nil. | |
3066 Interactively, ARG is the prefix arg (default 1) | |
3067 and KILLP is t if prefix arg is was specified." | |
3068 (interactive "*p\nP") | |
3069 (if (eq last-command 'complete) | |
3070 ;; probably a failed completion if you have to back up | |
3071 (cmpl-statistics-block (record-complete-failed))) | |
3072 (funcall $$$cmpl-old-backward-delete-char-untabify arg killp) | |
3073 ) | |
3074 | |
3075 | |
3076 (global-set-key "\C-?" 'cmpl-delete-backward-char) | |
3077 (global-set-key "\M-\C-F" 'cmpl-forward-sexp) | |
3078 (global-set-key "\M-\C-B" 'cmpl-backward-sexp) | |
3079 (global-set-key "\M-F" 'cmpl-forward-word) | |
3080 (global-set-key "\M-B" 'cmpl-backward-word) | |
3081 (global-set-key "\C-F" 'cmpl-forward-char) | |
3082 (global-set-key "\C-B" 'cmpl-backward-char) | |
3083 (global-set-key "\C-A" 'cmpl-beginning-of-line) | |
3084 (global-set-key "\C-E" 'cmpl-end-of-line) | |
3085 | |
3086 ;;;----------------------------------------------- | |
3087 ;;; Misc. | |
3088 ;;;----------------------------------------------- | |
3089 | |
3090 (def-completion-wrapper electric-buffer-list :under-or-before) | |
3091 (def-completion-wrapper list-buffers :under-or-before) | |
3092 (def-completion-wrapper scroll-up :under-or-before) | |
3093 (def-completion-wrapper scroll-down :under-or-before) | |
3094 (def-completion-wrapper execute-extended-command | |
3095 :under-or-before) | |
3096 (def-completion-wrapper other-window :under-or-before) | |
3097 | |
3098 ;;;----------------------------------------------- | |
3099 ;;; Local Thinking Machines stuff | |
3100 ;;;----------------------------------------------- | |
3101 | |
3102 (if (fboundp 'up-ten-lines) | |
3103 (def-completion-wrapper up-ten-lines :under-or-before)) | |
3104 (if (fboundp 'down-ten-lines) | |
3105 (def-completion-wrapper down-ten-lines :under-or-before)) | |
3106 (if (fboundp 'tmc-scroll-up) | |
3107 (def-completion-wrapper tmc-scroll-up :under-or-before)) | |
3108 (if (fboundp 'tmc-scroll-down) | |
3109 (def-completion-wrapper tmc-scroll-down :under-or-before)) | |
3110 (if (fboundp 'execute-extended-command-and-check-for-bindings) | |
3111 (def-completion-wrapper execute-extended-command-and-check-for-bindings | |
3112 :under-or-before)) | |
3113 | |
3114 ;;; Tests -- | |
3115 ;;; foobarbiz | |
3116 ;;; foobar | |
3117 ;;; fooquux | |
3118 ;;; fooper | |
3119 | |
3120 (cmpl-statistics-block | |
3121 (record-completion-file-loaded)) | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
190
diff
changeset
|
3122 |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
190
diff
changeset
|
3123 ;;; completion.el ends here |