aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2005-11-28 01:43:28 +0000
committerStefan Monnier2005-11-28 01:43:28 +0000
commit36cc948ee02d01005ee451bd4696164e15f549a4 (patch)
treee0cc834a778c0e5ee498d69cc5e3022068f6d929
parent63de21602df3ac75ba3f2399e7547db1a68b790f (diff)
downloademacs-36cc948ee02d01005ee451bd4696164e15f549a4.tar.gz
emacs-36cc948ee02d01005ee451bd4696164e15f549a4.zip
Remove useless leading * in defcustom docstrings.
(save-completions-file-name): Use ~/.emacs.d if available. (completion-standard-syntax-table): Rename from cmpl-standard-syntax-table and fold initialization into declaration, thus removing cmpl-make-standard-completion-syntax-table. (completion-lisp-syntax-table, completion-c-syntax-table) (completion-fortran-syntax-table, completion-c-def-syntax-table): Idem. (cmpl-saved-syntax, cmpl-saved-point): Remove. (symbol-under-point, symbol-before-point) (symbol-under-or-before-point, symbol-before-point-for-complete) (add-completions-from-c-buffer): Use with-syntax-table. (make-completion): Don't return a list of completion entries. Update callers. (cmpl-prefix-entry-head, cmpl-prefix-entry-tail): Use defalias. (completion-initialize): Rename from initialize-completions. (completion-find-file-hook): Rename from cmpl-find-file-hook. (kill-emacs-save-completions): Collect stats here. (save-completions-to-file, load-completions-from-file): Use with-current-buffer. (completion-def-wrapper): Rename from def-completion-wrapper. Make it into a function. Move all calls to toplevel. (completion-lisp-mode-hook): New fun. (completion-c-mode-hook, completion-setup-fortran-mode): Set the syntax-table here. Use local-set-key. (completion-saved-bindings): New var. (dynamic-completion-mode): Make it into a proper minor mode. (load-completions-from-file): Remove unused var `num-uses'.
-rw-r--r--lisp/ChangeLog44
-rw-r--r--lisp/completion.el819
2 files changed, 432 insertions, 431 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d7012292416..368c2bc6180 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,47 @@
12005-11-27 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * completion.el: Remove useless leading * in defcustom docstrings.
4 (save-completions-file-name): Use ~/.emacs.d if available.
5 (completion-standard-syntax-table): Rename from
6 cmpl-standard-syntax-table and fold initialization into declaration,
7 thus removing cmpl-make-standard-completion-syntax-table.
8 (completion-lisp-syntax-table, completion-c-syntax-table)
9 (completion-fortran-syntax-table, completion-c-def-syntax-table): Idem.
10 (cmpl-saved-syntax, cmpl-saved-point): Remove.
11 (symbol-under-point, symbol-before-point)
12 (symbol-under-or-before-point, symbol-before-point-for-complete)
13 (add-completions-from-c-buffer): Use with-syntax-table.
14 (make-completion): Don't return a list of completion entries.
15 Update callers.
16 (cmpl-prefix-entry-head, cmpl-prefix-entry-tail): Use defalias.
17 (completion-initialize): Rename from initialize-completions.
18 (completion-find-file-hook): Rename from cmpl-find-file-hook.
19 (kill-emacs-save-completions): Collect stats here.
20 (save-completions-to-file, load-completions-from-file):
21 Use with-current-buffer.
22 (completion-def-wrapper): Rename from def-completion-wrapper. Make it
23 into a function. Move all calls to toplevel.
24 (completion-lisp-mode-hook): New fun.
25 (completion-c-mode-hook, completion-setup-fortran-mode):
26 Set the syntax-table here. Use local-set-key.
27 (completion-saved-bindings): New var.
28 (dynamic-completion-mode): Make it into a proper minor mode.
29 (load-completions-from-file): Remove unused var `num-uses'.
30
31 * emacs-lisp/cl-macs.el (defstruct): Don't define the default
32 constructor if it is explicitly overridden.
33
34 * complete.el (PC-completion-as-file-name-predicate):
35 Use minibuffer-completing-file-name.
36 (partial-completion-mode): Use find-file-not-found-functions.
37 (PC-lisp-complete-symbol): Use with-syntax-table.
38 (PC-look-for-include-file): Remove dead setq.
39 (PC-look-for-include-file, PC-expand-many-files, PC-do-completion)
40 (PC-complete): Use with-current-buffer.
41
42 * progmodes/sh-script.el (sh-font-lock-syntactic-keywords): \ doesn't
43 escape single quotes.
44
12005-11-27 Luc Teirlinck <teirllm@auburn.edu> 452005-11-27 Luc Teirlinck <teirllm@auburn.edu>
2 46
3 * dabbrev.el (dabbrev-completion): Simplify code, by getting rid 47 * dabbrev.el (dabbrev-completion): Simplify code, by getting rid
diff --git a/lisp/completion.el b/lisp/completion.el
index 12df9a52714..2cd30e6513f 100644
--- a/lisp/completion.el
+++ b/lisp/completion.el
@@ -82,11 +82,11 @@
82;; SAVING/LOADING COMPLETIONS 82;; SAVING/LOADING COMPLETIONS
83;; Completions are automatically saved from one session to another 83;; Completions are automatically saved from one session to another
84;; (unless save-completions-flag or enable-completion is nil). 84;; (unless save-completions-flag or enable-completion is nil).
85;; Loading this file (or calling initialize-completions) causes EMACS 85;; Activating this minor-mode calling completion-initialize) causes Emacs
86;; to load a completions database for a saved completions file 86;; to load a completions database for a saved completions file
87;; (default: ~/.completions). When you exit, EMACS saves a copy of the 87;; (default: ~/.completions). When you exit, Emacs saves a copy of the
88;; completions that you 88;; completions that you
89;; often use. When you next start, EMACS loads in the saved completion file. 89;; often use. When you next start, Emacs loads in the saved completion file.
90;; 90;;
91;; The number of completions saved depends loosely on 91;; The number of completions saved depends loosely on
92;; *saved-completions-decay-factor*. Completions that have never been 92;; *saved-completions-decay-factor*. Completions that have never been
@@ -141,8 +141,8 @@
141;; App --> Appropriately] 141;; App --> Appropriately]
142;; 142;;
143;; INITIALIZATION 143;; INITIALIZATION
144;; The form `(initialize-completions)' initializes the completion system by 144;; The form `(completion-initialize)' initializes the completion system by
145;; trying to load in the user's completions. After the first cal, further 145;; trying to load in the user's completions. After the first call, further
146;; calls have no effect so one should be careful not to put the form in a 146;; calls have no effect so one should be careful not to put the form in a
147;; site's standard site-init file. 147;; site's standard site-init file.
148;; 148;;
@@ -180,7 +180,7 @@
180;; complete 180;; complete
181;; Inserts a completion at point 181;; Inserts a completion at point
182;; 182;;
183;; initialize-completions 183;; completion-initialize
184;; Loads the completions file and sets up so that exiting emacs will 184;; Loads the completions file and sets up so that exiting emacs will
185;; save them. 185;; save them.
186;; 186;;
@@ -286,59 +286,65 @@
286 286
287 287
288(defcustom enable-completion t 288(defcustom enable-completion t
289 "*Non-nil means enable recording and saving of completions. 289 "Non-nil means enable recording and saving of completions.
290If nil, no new words are added to the database or saved to the init file." 290If nil, no new words are added to the database or saved to the init file."
291 :type 'boolean 291 :type 'boolean
292 :group 'completion) 292 :group 'completion)
293 293
294(defcustom save-completions-flag t 294(defcustom save-completions-flag t
295 "*Non-nil means save most-used completions when exiting Emacs. 295 "Non-nil means save most-used completions when exiting Emacs.
296See also `save-completions-retention-time'." 296See also `save-completions-retention-time'."
297 :type 'boolean 297 :type 'boolean
298 :group 'completion) 298 :group 'completion)
299 299
300(defcustom save-completions-file-name (convert-standard-filename "~/.completions") 300(defcustom save-completions-file-name
301 "*The filename to save completions to." 301 (let ((olddef (convert-standard-filename "~/.completions")))
302 (cond
303 ((file-readable-p olddef) olddef)
304 ((file-directory-p (convert-standard-filename "~/.emacs.d/"))
305 (convert-standard-filename (expand-file-name completions "~/.emacs.d/")))
306 (t olddef)))
307 "The filename to save completions to."
302 :type 'file 308 :type 'file
303 :group 'completion) 309 :group 'completion)
304 310
305(defcustom save-completions-retention-time 336 311(defcustom save-completions-retention-time 336
306 "*Discard a completion if unused for this many hours. 312 "Discard a completion if unused for this many hours.
307\(1 day = 24, 1 week = 168). If this is 0, non-permanent completions 313\(1 day = 24, 1 week = 168). If this is 0, non-permanent completions
308will not be saved unless these are used. Default is two weeks." 314will not be saved unless these are used. Default is two weeks."
309 :type 'integer 315 :type 'integer
310 :group 'completion) 316 :group 'completion)
311 317
312(defcustom completion-on-separator-character nil 318(defcustom completion-on-separator-character nil
313 "*Non-nil means separator characters mark previous word as used. 319 "Non-nil means separator characters mark previous word as used.
314This means the word will be saved as a completion." 320This means the word will be saved as a completion."
315 :type 'boolean 321 :type 'boolean
316 :group 'completion) 322 :group 'completion)
317 323
318(defcustom completions-file-versions-kept kept-new-versions 324(defcustom completions-file-versions-kept kept-new-versions
319 "*Number of versions to keep for the saved completions file." 325 "Number of versions to keep for the saved completions file."
320 :type 'integer 326 :type 'integer
321 :group 'completion) 327 :group 'completion)
322 328
323(defcustom completion-prompt-speed-threshold 4800 329(defcustom completion-prompt-speed-threshold 4800
324 "*Minimum output speed at which to display next potential completion." 330 "Minimum output speed at which to display next potential completion."
325 :type 'integer 331 :type 'integer
326 :group 'completion) 332 :group 'completion)
327 333
328(defcustom completion-cdabbrev-prompt-flag nil 334(defcustom completion-cdabbrev-prompt-flag nil
329 "*If non-nil, the next completion prompt does a cdabbrev search. 335 "If non-nil, the next completion prompt does a cdabbrev search.
330This can be time consuming." 336This can be time consuming."
331 :type 'boolean 337 :type 'boolean
332 :group 'completion) 338 :group 'completion)
333 339
334(defcustom completion-search-distance 15000 340(defcustom completion-search-distance 15000
335 "*How far to search in the buffer when looking for completions. 341 "How far to search in the buffer when looking for completions.
336In number of characters. If nil, search the whole buffer." 342In number of characters. If nil, search the whole buffer."
337 :type 'integer 343 :type 'integer
338 :group 'completion) 344 :group 'completion)
339 345
340(defcustom completions-merging-modes '(lisp c) 346(defcustom completions-merging-modes '(lisp c)
341 "*List of modes {`c' or `lisp'} for automatic completions merging. 347 "List of modes {`c' or `lisp'} for automatic completions merging.
342Definitions from visited files which have these modes 348Definitions from visited files which have these modes
343are automatically added to the completion database." 349are automatically added to the completion database."
344 :type '(set (const lisp) (const c)) 350 :type '(set (const lisp) (const c))
@@ -495,7 +501,7 @@ Used to decide whether to save completions.")
495;; Table definitions 501;; Table definitions
496;;----------------------------------------------- 502;;-----------------------------------------------
497 503
498(defun cmpl-make-standard-completion-syntax-table () 504(defconst completion-standard-syntax-table
499 (let ((table (make-syntax-table)) 505 (let ((table (make-syntax-table))
500 i) 506 i)
501 ;; Default syntax is whitespace. 507 ;; Default syntax is whitespace.
@@ -523,36 +529,9 @@ Used to decide whether to save completions.")
523 (modify-syntax-entry char "w" table))) 529 (modify-syntax-entry char "w" table)))
524 table)) 530 table))
525 531
526(defconst cmpl-standard-syntax-table (cmpl-make-standard-completion-syntax-table)) 532(defvar completion-syntax-table completion-standard-syntax-table
527
528(defun cmpl-make-lisp-completion-syntax-table ()
529 (let ((table (copy-syntax-table cmpl-standard-syntax-table))
530 (symbol-chars '(?! ?& ?? ?= ?^)))
531 (dolist (char symbol-chars)
532 (modify-syntax-entry char "_" table))
533 table))
534
535(defun cmpl-make-c-completion-syntax-table ()
536 (let ((table (copy-syntax-table cmpl-standard-syntax-table))
537 (separator-chars '(?+ ?* ?/ ?: ?%)))
538 (dolist (char separator-chars)
539 (modify-syntax-entry char " " table))
540 table))
541
542(defun cmpl-make-fortran-completion-syntax-table ()
543 (let ((table (copy-syntax-table cmpl-standard-syntax-table))
544 (separator-chars '(?+ ?- ?* ?/ ?:)))
545 (dolist (char separator-chars)
546 (modify-syntax-entry char " " table))
547 table))
548
549(defconst cmpl-lisp-syntax-table (cmpl-make-lisp-completion-syntax-table))
550(defconst cmpl-c-syntax-table (cmpl-make-c-completion-syntax-table))
551(defconst cmpl-fortran-syntax-table (cmpl-make-fortran-completion-syntax-table))
552
553(defvar cmpl-syntax-table cmpl-standard-syntax-table
554 "This variable holds the current completion syntax table.") 533 "This variable holds the current completion syntax table.")
555(make-variable-buffer-local 'cmpl-syntax-table) 534(make-variable-buffer-local 'completion-syntax-table)
556 535
557;;----------------------------------------------- 536;;-----------------------------------------------
558;; Symbol functions 537;; Symbol functions
@@ -561,43 +540,34 @@ Used to decide whether to save completions.")
561 "Holds first character of symbol, after any completion symbol function.") 540 "Holds first character of symbol, after any completion symbol function.")
562(defvar cmpl-symbol-end nil 541(defvar cmpl-symbol-end nil
563 "Holds last character of symbol, after any completion symbol function.") 542 "Holds last character of symbol, after any completion symbol function.")
564;; These are temp. vars. we use to avoid using let.
565;; Why ? Small speed improvement.
566(defvar cmpl-saved-syntax nil)
567(defvar cmpl-saved-point nil)
568 543
569(defun symbol-under-point () 544(defun symbol-under-point ()
570 "Return the symbol that the point is currently on. 545 "Return the symbol that the point is currently on.
571But only if it is longer than `completion-min-length'." 546But only if it is longer than `completion-min-length'."
572 (setq cmpl-saved-syntax (syntax-table)) 547 (with-syntax-table completion-syntax-table
573 (unwind-protect 548 (when (memq (char-syntax (following-char)) '(?w ?_))
574 (progn 549 ;; Cursor is on following-char and after preceding-char
575 (set-syntax-table cmpl-syntax-table) 550 (let ((saved-point (point)))
576 (cond 551 (setq cmpl-symbol-start (scan-sexps (1+ saved-point) -1)
577 ;; Cursor is on following-char and after preceding-char 552 cmpl-symbol-end (scan-sexps saved-point 1))
578 ((memq (char-syntax (following-char)) '(?w ?_)) 553 ;; Remove chars to ignore at the start.
579 (setq cmpl-saved-point (point) 554 (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w)
580 cmpl-symbol-start (scan-sexps (1+ cmpl-saved-point) -1) 555 (goto-char cmpl-symbol-start)
581 cmpl-symbol-end (scan-sexps cmpl-saved-point 1)) 556 (forward-word 1)
582 ;; Remove chars to ignore at the start. 557 (setq cmpl-symbol-start (point))
583 (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w) 558 (goto-char saved-point)))
584 (goto-char cmpl-symbol-start) 559 ;; Remove chars to ignore at the end.
585 (forward-word 1) 560 (cond ((= (char-syntax (char-after (1- cmpl-symbol-end))) ?w)
586 (setq cmpl-symbol-start (point)) 561 (goto-char cmpl-symbol-end)
587 (goto-char cmpl-saved-point))) 562 (forward-word -1)
588 ;; Remove chars to ignore at the end. 563 (setq cmpl-symbol-end (point))
589 (cond ((= (char-syntax (char-after (1- cmpl-symbol-end))) ?w) 564 (goto-char saved-point)))
590 (goto-char cmpl-symbol-end) 565 ;; Return completion if the length is reasonable.
591 (forward-word -1) 566 (if (and (<= completion-min-length
592 (setq cmpl-symbol-end (point)) 567 (- cmpl-symbol-end cmpl-symbol-start))
593 (goto-char cmpl-saved-point))) 568 (<= (- cmpl-symbol-end cmpl-symbol-start)
594 ;; Return completion if the length is reasonable. 569 completion-max-length))
595 (if (and (<= completion-min-length 570 (buffer-substring cmpl-symbol-start cmpl-symbol-end))))))
596 (- cmpl-symbol-end cmpl-symbol-start))
597 (<= (- cmpl-symbol-end cmpl-symbol-start)
598 completion-max-length))
599 (buffer-substring cmpl-symbol-start cmpl-symbol-end)))))
600 (set-syntax-table cmpl-saved-syntax)))
601 571
602;; tests for symbol-under-point 572;; tests for symbol-under-point
603;; `^' indicates cursor pos. where value is returned 573;; `^' indicates cursor pos. where value is returned
@@ -615,46 +585,42 @@ But only if it is longer than `completion-min-length'."
615 "Return a string of the symbol immediately before point. 585 "Return a string of the symbol immediately before point.
616Returns nil if there isn't one longer than `completion-min-length'." 586Returns nil if there isn't one longer than `completion-min-length'."
617 ;; This is called when a word separator is typed so it must be FAST ! 587 ;; This is called when a word separator is typed so it must be FAST !
618 (setq cmpl-saved-syntax (syntax-table)) 588 (with-syntax-table completion-syntax-table
619 (unwind-protect 589 ;; Cursor is on following-char and after preceding-char
620 (progn 590 (cond ((= (setq cmpl-preceding-syntax (char-syntax (preceding-char))) ?_)
621 (set-syntax-table cmpl-syntax-table) 591 ;; Number of chars to ignore at end.
622 ;; Cursor is on following-char and after preceding-char 592 (setq cmpl-symbol-end (point)
623 (cond ((= (setq cmpl-preceding-syntax (char-syntax (preceding-char))) ?_) 593 cmpl-symbol-start (scan-sexps cmpl-symbol-end -1))
624 ;; Number of chars to ignore at end. 594 ;; Remove chars to ignore at the start.
625 (setq cmpl-symbol-end (point) 595 (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w)
626 cmpl-symbol-start (scan-sexps cmpl-symbol-end -1)) 596 (goto-char cmpl-symbol-start)
627 ;; Remove chars to ignore at the start. 597 (forward-word 1)
628 (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w) 598 (setq cmpl-symbol-start (point))
629 (goto-char cmpl-symbol-start) 599 (goto-char cmpl-symbol-end)))
630 (forward-word 1) 600 ;; Return value if long enough.
631 (setq cmpl-symbol-start (point)) 601 (if (>= cmpl-symbol-end
632 (goto-char cmpl-symbol-end))) 602 (+ cmpl-symbol-start completion-min-length))
633 ;; Return value if long enough. 603 (buffer-substring cmpl-symbol-start cmpl-symbol-end)))
634 (if (>= cmpl-symbol-end 604 ((= cmpl-preceding-syntax ?w)
635 (+ cmpl-symbol-start completion-min-length)) 605 ;; chars to ignore at end
636 (buffer-substring cmpl-symbol-start cmpl-symbol-end))) 606 (let ((saved-point (point)))
637 ((= cmpl-preceding-syntax ?w) 607 (setq cmpl-symbol-start (scan-sexps saved-point -1))
638 ;; chars to ignore at end 608 ;; take off chars. from end
639 (setq cmpl-saved-point (point) 609 (forward-word -1)
640 cmpl-symbol-start (scan-sexps cmpl-saved-point -1)) 610 (setq cmpl-symbol-end (point))
641 ;; take off chars. from end 611 ;; remove chars to ignore at the start
642 (forward-word -1) 612 (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w)
643 (setq cmpl-symbol-end (point)) 613 (goto-char cmpl-symbol-start)
644 ;; remove chars to ignore at the start 614 (forward-word 1)
645 (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w) 615 (setq cmpl-symbol-start (point))))
646 (goto-char cmpl-symbol-start) 616 ;; Restore state.
647 (forward-word 1) 617 (goto-char saved-point)
648 (setq cmpl-symbol-start (point)))) 618 ;; Return completion if the length is reasonable
649 ;; Restore state. 619 (if (and (<= completion-min-length
650 (goto-char cmpl-saved-point) 620 (- cmpl-symbol-end cmpl-symbol-start))
651 ;; Return completion if the length is reasonable 621 (<= (- cmpl-symbol-end cmpl-symbol-start)
652 (if (and (<= completion-min-length 622 completion-max-length))
653 (- cmpl-symbol-end cmpl-symbol-start)) 623 (buffer-substring cmpl-symbol-start cmpl-symbol-end)))))))
654 (<= (- cmpl-symbol-end cmpl-symbol-start)
655 completion-max-length))
656 (buffer-substring cmpl-symbol-start cmpl-symbol-end)))))
657 (set-syntax-table cmpl-saved-syntax)))
658 624
659;; tests for symbol-before-point 625;; tests for symbol-before-point
660;; `^' indicates cursor pos. where value is returned 626;; `^' indicates cursor pos. where value is returned
@@ -675,17 +641,11 @@ Returns nil if there isn't one longer than `completion-min-length'."
675 ;; copying all the code. 641 ;; copying all the code.
676 ;; However, it is only used by the completion string prompter. 642 ;; However, it is only used by the completion string prompter.
677 ;; If it comes into common use, it could be rewritten. 643 ;; If it comes into common use, it could be rewritten.
678 (cond ((memq (progn 644 (if (memq (with-syntax-table completion-syntax-table
679 (setq cmpl-saved-syntax (syntax-table)) 645 (char-syntax (following-char)))
680 (unwind-protect 646 '(?w ?_))
681 (progn 647 (symbol-under-point)
682 (set-syntax-table cmpl-syntax-table) 648 (symbol-before-point)))
683 (char-syntax (following-char)))
684 (set-syntax-table cmpl-saved-syntax)))
685 '(?w ?_))
686 (symbol-under-point))
687 (t
688 (symbol-before-point))))
689 649
690 650
691(defun symbol-before-point-for-complete () 651(defun symbol-before-point-for-complete ()
@@ -693,28 +653,23 @@ Returns nil if there isn't one longer than `completion-min-length'."
693 ;; or nil if there isn't one. Like symbol-before-point but doesn't trim the 653 ;; or nil if there isn't one. Like symbol-before-point but doesn't trim the
694 ;; end chars." 654 ;; end chars."
695 ;; Cursor is on following-char and after preceding-char 655 ;; Cursor is on following-char and after preceding-char
696 (setq cmpl-saved-syntax (syntax-table)) 656 (with-syntax-table completion-syntax-table
697 (unwind-protect 657 (cond ((memq (setq cmpl-preceding-syntax (char-syntax (preceding-char)))
698 (progn 658 '(?_ ?w))
699 (set-syntax-table cmpl-syntax-table) 659 (setq cmpl-symbol-end (point)
700 (cond ((memq (setq cmpl-preceding-syntax (char-syntax (preceding-char))) 660 cmpl-symbol-start (scan-sexps cmpl-symbol-end -1))
701 '(?_ ?w)) 661 ;; Remove chars to ignore at the start.
702 (setq cmpl-symbol-end (point) 662 (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w)
703 cmpl-symbol-start (scan-sexps cmpl-symbol-end -1)) 663 (goto-char cmpl-symbol-start)
704 ;; Remove chars to ignore at the start. 664 (forward-word 1)
705 (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w) 665 (setq cmpl-symbol-start (point))
706 (goto-char cmpl-symbol-start) 666 (goto-char cmpl-symbol-end)))
707 (forward-word 1) 667 ;; Return completion if the length is reasonable.
708 (setq cmpl-symbol-start (point)) 668 (if (and (<= completion-prefix-min-length
709 (goto-char cmpl-symbol-end))) 669 (- cmpl-symbol-end cmpl-symbol-start))
710 ;; Return completion if the length is reasonable. 670 (<= (- cmpl-symbol-end cmpl-symbol-start)
711 (if (and (<= completion-prefix-min-length 671 completion-max-length))
712 (- cmpl-symbol-end cmpl-symbol-start)) 672 (buffer-substring cmpl-symbol-start cmpl-symbol-end))))))
713 (<= (- cmpl-symbol-end cmpl-symbol-start)
714 completion-max-length))
715 (buffer-substring cmpl-symbol-start cmpl-symbol-end)))))
716 ;; Restore syntax table.
717 (set-syntax-table cmpl-saved-syntax)))
718 673
719;; tests for symbol-before-point-for-complete 674;; tests for symbol-before-point-for-complete
720;; `^' indicates cursor pos. where value is returned 675;; `^' indicates cursor pos. where value is returned
@@ -866,7 +821,7 @@ This is sensitive to `case-fold-search'."
866 (setq saved-point (point) 821 (setq saved-point (point)
867 saved-syntax (syntax-table)) 822 saved-syntax (syntax-table))
868 ;; Restore completion state 823 ;; Restore completion state
869 (set-syntax-table cmpl-syntax-table) 824 (set-syntax-table completion-syntax-table)
870 (goto-char cdabbrev-current-point) 825 (goto-char cdabbrev-current-point)
871 ;; Loop looking for completions 826 ;; Loop looking for completions
872 (while 827 (while
@@ -1010,8 +965,8 @@ Each symbol is bound to a single completion entry.")
1010 965
1011;; CONSTRUCTOR 966;; CONSTRUCTOR
1012(defun make-completion (string) 967(defun make-completion (string)
1013 "Return a list of a completion entry." 968 "Return a completion entry."
1014 (list (list string 0 nil current-completion-source))) 969 (list string 0 nil current-completion-source))
1015 970
1016;; Obsolete 971;; Obsolete
1017;;(defmacro cmpl-prefix-entry-symbol (completion-entry) 972;;(defmacro cmpl-prefix-entry-symbol (completion-entry)
@@ -1026,11 +981,9 @@ Each symbol is bound to a single completion entry.")
1026 981
1027;; READER Macros 982;; READER Macros
1028 983
1029(defmacro cmpl-prefix-entry-head (prefix-entry) 984(defalias 'cmpl-prefix-entry-head 'car)
1030 (list 'car prefix-entry))
1031 985
1032(defmacro cmpl-prefix-entry-tail (prefix-entry) 986(defalias 'cmpl-prefix-entry-tail 'cdr)
1033 (list 'cdr prefix-entry))
1034 987
1035;; WRITER Macros 988;; WRITER Macros
1036 989
@@ -1092,17 +1045,17 @@ Each symbol is bound to a single completion entry.")
1092;; These are the internal functions used to update the datebase 1045;; These are the internal functions used to update the datebase
1093;; 1046;;
1094;; 1047;;
1095(defvar completion-to-accept nil) 1048(defvar completion-to-accept nil
1096 ;;"Set to a string that is pending its acceptance." 1049 "Set to a string that is pending its acceptance.")
1097 ;; this checked by the top level reading functions 1050 ;; this checked by the top level reading functions
1098 1051
1099(defvar cmpl-db-downcase-string nil) 1052(defvar cmpl-db-downcase-string nil
1100 ;; "Setup by find-exact-completion, etc. The given string, downcased." 1053 "Setup by `find-exact-completion', etc. The given string, downcased.")
1101(defvar cmpl-db-symbol nil) 1054(defvar cmpl-db-symbol nil
1102 ;; "The interned symbol corresponding to cmpl-db-downcase-string. 1055 "The interned symbol corresponding to `cmpl-db-downcase-string'.
1103 ;; Set up by cmpl-db-symbol." 1056Set up by `cmpl-db-symbol'.")
1104(defvar cmpl-db-prefix-symbol nil) 1057(defvar cmpl-db-prefix-symbol nil
1105 ;; "The interned prefix symbol corresponding to cmpl-db-downcase-string." 1058 "The interned prefix symbol corresponding to `cmpl-db-downcase-string'.")
1106(defvar cmpl-db-entry nil) 1059(defvar cmpl-db-entry nil)
1107(defvar cmpl-db-debug-p nil 1060(defvar cmpl-db-debug-p nil
1108 "Set to t if you want to debug the database.") 1061 "Set to t if you want to debug the database.")
@@ -1190,7 +1143,7 @@ Returns the completion entry."
1190 (or (find-exact-completion string) 1143 (or (find-exact-completion string)
1191 ;; not there 1144 ;; not there
1192 (let (;; create an entry 1145 (let (;; create an entry
1193 (entry (make-completion string)) 1146 (entry (list (make-completion string)))
1194 ;; setup the prefix 1147 ;; setup the prefix
1195 (prefix-entry (find-cmpl-prefix-entry 1148 (prefix-entry (find-cmpl-prefix-entry
1196 (substring cmpl-db-downcase-string 0 1149 (substring cmpl-db-downcase-string 0
@@ -1244,7 +1197,7 @@ Returns the completion entry."
1244 cmpl-db-entry) 1197 cmpl-db-entry)
1245 ;; not there 1198 ;; not there
1246 (let (;; create an entry 1199 (let (;; create an entry
1247 (entry (make-completion completion-string)) 1200 (entry (list (make-completion completion-string)))
1248 ;; setup the prefix 1201 ;; setup the prefix
1249 (prefix-entry (find-cmpl-prefix-entry 1202 (prefix-entry (find-cmpl-prefix-entry
1250 (substring cmpl-db-downcase-string 0 1203 (substring cmpl-db-downcase-string 0
@@ -1650,7 +1603,7 @@ Prefix args ::
1650 (setq cmpl-current-index (+ cmpl-current-index (or arg 1)))) 1603 (setq cmpl-current-index (+ cmpl-current-index (or arg 1))))
1651 (t 1604 (t
1652 (if (not cmpl-initialized-p) 1605 (if (not cmpl-initialized-p)
1653 (initialize-completions)) ;; make sure everything's loaded 1606 (completion-initialize)) ;; make sure everything's loaded
1654 (cond ((consp current-prefix-arg) ;; control-u 1607 (cond ((consp current-prefix-arg) ;; control-u
1655 (setq arg 0) 1608 (setq arg 0)
1656 (setq cmpl-leave-point-at-start t)) 1609 (setq cmpl-leave-point-at-start t))
@@ -1752,9 +1705,8 @@ Prefix args ::
1752 (let ((completions-merging-modes nil)) 1705 (let ((completions-merging-modes nil))
1753 (setq buffer (find-file-noselect file)))) 1706 (setq buffer (find-file-noselect file))))
1754 (unwind-protect 1707 (unwind-protect
1755 (save-excursion 1708 (with-current-buffer buffer
1756 (set-buffer buffer) 1709 (add-completions-from-buffer))
1757 (add-completions-from-buffer))
1758 (if (not buffer-already-there-p) 1710 (if (not buffer-already-there-p)
1759 (kill-buffer buffer))))) 1711 (kill-buffer buffer)))))
1760 1712
@@ -1781,7 +1733,7 @@ Prefix args ::
1781 start-num))))) 1733 start-num)))))
1782 1734
1783;; Find file hook 1735;; Find file hook
1784(defun cmpl-find-file-hook () 1736(defun completion-find-file-hook ()
1785 (cond (enable-completion 1737 (cond (enable-completion
1786 (cond ((and (memq major-mode '(emacs-lisp-mode lisp-mode)) 1738 (cond ((and (memq major-mode '(emacs-lisp-mode lisp-mode))
1787 (memq 'lisp completions-merging-modes)) 1739 (memq 'lisp completions-merging-modes))
@@ -1864,7 +1816,7 @@ Prefix args ::
1864;; Whitespace chars (have symbol syntax) 1816;; Whitespace chars (have symbol syntax)
1865;; Everything else has word syntax 1817;; Everything else has word syntax
1866 1818
1867(defun cmpl-make-c-def-completion-syntax-table () 1819(defconst completion-c-def-syntax-table
1868 (let ((table (make-syntax-table)) 1820 (let ((table (make-syntax-table))
1869 (whitespace-chars '(? ?\n ?\t ?\f ?\v ?\r)) 1821 (whitespace-chars '(? ?\n ?\t ?\f ?\v ?\r))
1870 ;; unfortunately the ?( causes the parens to appear unbalanced 1822 ;; unfortunately the ?( causes the parens to appear unbalanced
@@ -1885,8 +1837,6 @@ Prefix args ::
1885 (modify-syntax-entry ?\} "){" table) 1837 (modify-syntax-entry ?\} "){" table)
1886 table)) 1838 table))
1887 1839
1888(defconst cmpl-c-def-syntax-table (cmpl-make-c-def-completion-syntax-table))
1889
1890;; Regexps 1840;; Regexps
1891(defconst *c-def-regexp* 1841(defconst *c-def-regexp*
1892 ;; This stops on lines with possible definitions 1842 ;; This stops on lines with possible definitions
@@ -1930,81 +1880,77 @@ Prefix args ::
1930 ;; Benchmark -- 1880 ;; Benchmark --
1931 ;; Sun 3/280-- 1250 lines/sec. 1881 ;; Sun 3/280-- 1250 lines/sec.
1932 1882
1933 (let (string next-point char 1883 (let (string next-point char)
1934 (saved-syntax (syntax-table)))
1935 (save-excursion 1884 (save-excursion
1936 (goto-char (point-min)) 1885 (goto-char (point-min))
1937 (catch 'finish-add-completions 1886 (catch 'finish-add-completions
1938 (unwind-protect 1887 (with-syntax-table completion-c-def-syntax-table
1939 (while t 1888 (while t
1940 ;; we loop here only when scan-sexps fails 1889 ;; we loop here only when scan-sexps fails
1941 ;; (i.e. unbalance exps.) 1890 ;; (i.e. unbalance exps.)
1942 (set-syntax-table cmpl-c-def-syntax-table) 1891 (condition-case e
1943 (condition-case e 1892 (while t
1944 (while t 1893 (re-search-forward *c-def-regexp*)
1945 (re-search-forward *c-def-regexp*) 1894 (cond
1946 (cond 1895 ((= (preceding-char) ?#)
1947 ((= (preceding-char) ?#) 1896 ;; preprocessor macro, see if it's one we handle
1948 ;; preprocessor macro, see if it's one we handle 1897 (setq string (buffer-substring (point) (+ (point) 6)))
1949 (setq string (buffer-substring (point) (+ (point) 6))) 1898 (cond ((member string '("define" "ifdef "))
1950 (cond ((or (string-equal string "define") 1899 ;; skip forward over definition symbol
1951 (string-equal string "ifdef ")) 1900 ;; and add it to database
1952 ;; skip forward over definition symbol 1901 (and (forward-word 2)
1953 ;; and add it to database 1902 (setq string (symbol-before-point))
1954 (and (forward-word 2) 1903 ;;(push string foo)
1955 (setq string (symbol-before-point)) 1904 (add-completion-to-tail-if-new string)))))
1956 ;;(push string foo) 1905 (t
1957 (add-completion-to-tail-if-new string))))) 1906 ;; C definition
1958 (t 1907 (setq next-point (point))
1959 ;; C definition 1908 (while (and
1960 (setq next-point (point)) 1909 next-point
1961 (while (and 1910 ;; scan to next separator char.
1962 next-point 1911 (setq next-point (scan-sexps next-point 1)))
1963 ;; scan to next separator char. 1912 ;; position the point on the word we want to add
1964 (setq next-point (scan-sexps next-point 1))) 1913 (goto-char next-point)
1965 ;; position the point on the word we want to add 1914 (while (= (setq char (following-char)) ?*)
1966 (goto-char next-point) 1915 ;; handle pointer ref
1967 (while (= (setq char (following-char)) ?*) 1916 ;; move to next separator char.
1968 ;; handle pointer ref 1917 (goto-char
1969 ;; move to next separator char. 1918 (setq next-point (scan-sexps (point) 1))))
1970 (goto-char 1919 (forward-word -1)
1971 (setq next-point (scan-sexps (point) 1)))) 1920 ;; add to database
1972 (forward-word -1) 1921 (if (setq string (symbol-under-point))
1973 ;; add to database 1922 ;; (push string foo)
1974 (if (setq string (symbol-under-point)) 1923 (add-completion-to-tail-if-new string)
1975 ;; (push string foo) 1924 ;; Local TMC hack (useful for parsing paris.h)
1976 (add-completion-to-tail-if-new string) 1925 (if (and (looking-at "_AP") ;; "ansi prototype"
1977 ;; Local TMC hack (useful for parsing paris.h) 1926 (progn
1978 (if (and (looking-at "_AP") ;; "ansi prototype" 1927 (forward-word -1)
1979 (progn 1928 (setq string
1980 (forward-word -1) 1929 (symbol-under-point))))
1981 (setq string 1930 (add-completion-to-tail-if-new string)))
1982 (symbol-under-point)))) 1931 ;; go to next
1983 (add-completion-to-tail-if-new string))) 1932 (goto-char next-point)
1984 ;; go to next 1933 ;; (push (format "%c" (following-char)) foo)
1985 (goto-char next-point) 1934 (if (= (char-syntax char) ?\()
1986 ;; (push (format "%c" (following-char)) foo) 1935 ;; if on an opening delimiter, go to end
1987 (if (= (char-syntax char) ?\() 1936 (while (= (char-syntax char) ?\()
1988 ;; if on an opening delimiter, go to end 1937 (setq next-point (scan-sexps next-point 1)
1989 (while (= (char-syntax char) ?\() 1938 char (char-after next-point)))
1990 (setq next-point (scan-sexps next-point 1) 1939 (or (= char ?,)
1991 char (char-after next-point))) 1940 ;; Current char is an end char.
1992 (or (= char ?,) 1941 (setq next-point nil)))))))
1993 ;; Current char is an end char. 1942 (search-failed ;;done
1994 (setq next-point nil))))))) 1943 (throw 'finish-add-completions t))
1995 (search-failed ;;done 1944 (error
1996 (throw 'finish-add-completions t)) 1945 ;; Check for failure in scan-sexps
1997 (error 1946 (if (or (string-equal (nth 1 e)
1998 ;; Check for failure in scan-sexps 1947 "Containing expression ends prematurely")
1999 (if (or (string-equal (nth 1 e) 1948 (string-equal (nth 1 e) "Unbalanced parentheses"))
2000 "Containing expression ends prematurely") 1949 ;; unbalanced paren., keep going
2001 (string-equal (nth 1 e) "Unbalanced parentheses")) 1950 ;;(ding)
2002 ;; unbalanced paren., keep going 1951 (forward-line 1)
2003 ;;(ding) 1952 (message "Error parsing C buffer for completions--please send bug report")
2004 (forward-line 1) 1953 (throw 'finish-add-completions t))))))))))
2005 (message "Error parsing C buffer for completions--please send bug report")
2006 (throw 'finish-add-completions t)))))
2007 (set-syntax-table saved-syntax))))))
2008 1954
2009 1955
2010;;--------------------------------------------------------------------------- 1956;;---------------------------------------------------------------------------
@@ -2018,7 +1964,8 @@ Prefix args ::
2018 ((not cmpl-completions-accepted-p) 1964 ((not cmpl-completions-accepted-p)
2019 (message "Completions database has not changed - not writing.")) 1965 (message "Completions database has not changed - not writing."))
2020 (t 1966 (t
2021 (save-completions-to-file))))) 1967 (save-completions-to-file))))
1968 (cmpl-statistics-block (record-cmpl-kill-emacs)))
2022 1969
2023;; There is no point bothering to change this again 1970;; There is no point bothering to change this again
2024;; unless the package changes so much that it matters 1971;; unless the package changes so much that it matters
@@ -2046,7 +1993,7 @@ If file name is not specified, use `save-completions-file-name'."
2046 (if (file-writable-p filename) 1993 (if (file-writable-p filename)
2047 (progn 1994 (progn
2048 (if (not cmpl-initialized-p) 1995 (if (not cmpl-initialized-p)
2049 (initialize-completions));; make sure everything's loaded 1996 (completion-initialize)) ;; make sure everything's loaded
2050 (message "Saving completions to file %s" filename) 1997 (message "Saving completions to file %s" filename)
2051 1998
2052 (let* ((delete-old-versions t) 1999 (let* ((delete-old-versions t)
@@ -2059,9 +2006,7 @@ If file name is not specified, use `save-completions-file-name'."
2059 (total-saved 0) 2006 (total-saved 0)
2060 (backup-filename (completion-backup-filename filename))) 2007 (backup-filename (completion-backup-filename filename)))
2061 2008
2062 (save-excursion 2009 (with-current-buffer (get-buffer-create " *completion-save-buffer*")
2063 (get-buffer-create " *completion-save-buffer*")
2064 (set-buffer " *completion-save-buffer*")
2065 (setq buffer-file-name filename) 2010 (setq buffer-file-name filename)
2066 2011
2067 (if (not (verify-visited-file-modtime (current-buffer))) 2012 (if (not (verify-visited-file-modtime (current-buffer)))
@@ -2151,9 +2096,7 @@ If file is not specified, then use `save-completions-file-name'."
2151 (if (not no-message-p) 2096 (if (not no-message-p)
2152 (message "Loading completions from %sfile %s . . ." 2097 (message "Loading completions from %sfile %s . . ."
2153 (if backup-readable-p "backup " "") filename)) 2098 (if backup-readable-p "backup " "") filename))
2154 (save-excursion 2099 (with-current-buffer (get-buffer-create " *completion-save-buffer*")
2155 (get-buffer-create " *completion-save-buffer*")
2156 (set-buffer " *completion-save-buffer*")
2157 (setq buffer-file-name filename) 2100 (setq buffer-file-name filename)
2158 ;; prepare the buffer to be modified 2101 ;; prepare the buffer to be modified
2159 (clear-visited-file-modtime) 2102 (clear-visited-file-modtime)
@@ -2161,8 +2104,7 @@ If file is not specified, then use `save-completions-file-name'."
2161 2104
2162 (let ((insert-okay-p nil) 2105 (let ((insert-okay-p nil)
2163 (buffer (current-buffer)) 2106 (buffer (current-buffer))
2164 (current-time (cmpl-hours-since-origin)) 2107 string entry last-use-time
2165 string num-uses entry last-use-time
2166 cmpl-entry cmpl-last-use-time 2108 cmpl-entry cmpl-last-use-time
2167 (current-completion-source cmpl-source-init-file) 2109 (current-completion-source cmpl-source-init-file)
2168 (start-num 2110 (start-num
@@ -2233,13 +2175,13 @@ If file is not specified, then use `save-completions-file-name'."
2233 start-num))) 2175 start-num)))
2234)))))) 2176))))))
2235 2177
2236(defun initialize-completions () 2178(defun completion-initialize ()
2237 "Load the default completions file. 2179 "Load the default completions file.
2238Also sets up so that exiting Emacs will automatically save the file." 2180Also sets up so that exiting Emacs will automatically save the file."
2239 (interactive) 2181 (interactive)
2240 (cond ((not cmpl-initialized-p) 2182 (unless cmpl-initialized-p
2241 (load-completions-from-file))) 2183 (load-completions-from-file)
2242 (setq cmpl-initialized-p t)) 2184 (setq cmpl-initialized-p t)))
2243 2185
2244;;----------------------------------------------- 2186;;-----------------------------------------------
2245;; Kill region patch 2187;; Kill region patch
@@ -2302,33 +2244,21 @@ Patched to remove the most recent completion."
2302;; Note that because of the way byte compiling works, none of 2244;; Note that because of the way byte compiling works, none of
2303;; the functions defined with this macro get byte compiled. 2245;; the functions defined with this macro get byte compiled.
2304 2246
2305(defmacro def-completion-wrapper (function-name type &optional new-name) 2247(defun completion-def-wrapper (function-name type)
2306 "Add a call to update the completion database before function execution. 2248 "Add a call to update the completion database before function execution.
2307TYPE is the type of the wrapper to be added. Can be :before or :under." 2249TYPE is the type of the wrapper to be added. Can be :before or :under."
2308 (cond ((eq type :separator) 2250 (put function-name 'completion-function
2309 (list 'put (list 'quote function-name) ''completion-function 2251 (cdr (assq type
2310 ''use-completion-before-separator)) 2252 '((:separator 'use-completion-before-separator)
2311 ((eq type :before) 2253 (:before 'use-completion-before-point)
2312 (list 'put (list 'quote function-name) ''completion-function 2254 (:backward-under 'use-completion-backward-under)
2313 ''use-completion-before-point)) 2255 (:backward 'use-completion-backward)
2314 ((eq type :backward-under) 2256 (:under 'use-completion-under-point)
2315 (list 'put (list 'quote function-name) ''completion-function 2257 (:under-or-before 'use-completion-under-or-before-point)
2316 ''use-completion-backward-under)) 2258 (:minibuffer-separator 'use-completion-minibuffer-separator))))))
2317 ((eq type :backward)
2318 (list 'put (list 'quote function-name) ''completion-function
2319 ''use-completion-backward))
2320 ((eq type :under)
2321 (list 'put (list 'quote function-name) ''completion-function
2322 ''use-completion-under-point))
2323 ((eq type :under-or-before)
2324 (list 'put (list 'quote function-name) ''completion-function
2325 ''use-completion-under-or-before-point))
2326 ((eq type :minibuffer-separator)
2327 (list 'put (list 'quote function-name) ''completion-function
2328 ''use-completion-minibuffer-separator))))
2329 2259
2330(defun use-completion-minibuffer-separator () 2260(defun use-completion-minibuffer-separator ()
2331 (let ((cmpl-syntax-table cmpl-standard-syntax-table)) 2261 (let ((completion-syntax-table completion-standard-syntax-table))
2332 (use-completion-before-separator))) 2262 (use-completion-before-separator)))
2333 2263
2334(defun use-completion-backward-under () 2264(defun use-completion-backward-under ()
@@ -2347,170 +2277,197 @@ TYPE is the type of the wrapper to be added. Can be :before or :under."
2347 (get this-command 'completion-function)) 2277 (get this-command 'completion-function))
2348 'use-completion-under-or-before-point))) 2278 'use-completion-under-or-before-point)))
2349 2279
2280;; Lisp mode diffs.
2281
2282(defconst completion-lisp-syntax-table
2283 (let ((table (copy-syntax-table completion-standard-syntax-table))
2284 (symbol-chars '(?! ?& ?? ?= ?^)))
2285 (dolist (char symbol-chars)
2286 (modify-syntax-entry char "_" table))
2287 table))
2288
2289(defun completion-lisp-mode-hook ()
2290 (setq completion-syntax-table completion-lisp-syntax-table)
2291 ;; Lisp Mode diffs
2292 (local-set-key "!" 'self-insert-command)
2293 (local-set-key "&" 'self-insert-command)
2294 (local-set-key "%" 'self-insert-command)
2295 (local-set-key "?" 'self-insert-command)
2296 (local-set-key "=" 'self-insert-command)
2297 (local-set-key "^" 'self-insert-command))
2298
2350;; C mode diffs. 2299;; C mode diffs.
2351 2300
2352(defvar c-mode-map) 2301(defconst completion-c-syntax-table
2302 (let ((table (copy-syntax-table completion-standard-syntax-table))
2303 (separator-chars '(?+ ?* ?/ ?: ?%)))
2304 (dolist (char separator-chars)
2305 (modify-syntax-entry char " " table))
2306 table))
2353 2307
2308(completion-def-wrapper 'electric-c-semi :separator)
2354(defun completion-c-mode-hook () 2309(defun completion-c-mode-hook ()
2355 (def-completion-wrapper electric-c-semi :separator) 2310 (setq completion-syntax-table completion-c-syntax-table)
2356 (define-key c-mode-map "+" 'completion-separator-self-insert-command) 2311 (local-set-key "+" 'completion-separator-self-insert-command)
2357 (define-key c-mode-map "*" 'completion-separator-self-insert-command) 2312 (local-set-key "*" 'completion-separator-self-insert-command)
2358 (define-key c-mode-map "/" 'completion-separator-self-insert-command)) 2313 (local-set-key "/" 'completion-separator-self-insert-command))
2359;; Do this either now or whenever C mode is loaded.
2360(if (featurep 'cc-mode)
2361 (completion-c-mode-hook)
2362 (add-hook 'c-mode-hook 'completion-c-mode-hook))
2363 2314
2364;; FORTRAN mode diffs. (these are defined when fortran is called) 2315;; FORTRAN mode diffs. (these are defined when fortran is called)
2365 2316
2366(defvar fortran-mode-map) 2317(defconst completion-fortran-syntax-table
2318 (let ((table (copy-syntax-table completion-standard-syntax-table))
2319 (separator-chars '(?+ ?- ?* ?/ ?:)))
2320 (dolist (char separator-chars)
2321 (modify-syntax-entry char " " table))
2322 table))
2367 2323
2368(defun completion-setup-fortran-mode () 2324(defun completion-setup-fortran-mode ()
2369 (define-key fortran-mode-map "+" 'completion-separator-self-insert-command) 2325 (setq completion-syntax-table completion-fortran-syntax-table)
2370 (define-key fortran-mode-map "-" 'completion-separator-self-insert-command) 2326 (local-set-key "+" 'completion-separator-self-insert-command)
2371 (define-key fortran-mode-map "*" 'completion-separator-self-insert-command) 2327 (local-set-key "-" 'completion-separator-self-insert-command)
2372 (define-key fortran-mode-map "/" 'completion-separator-self-insert-command)) 2328 (local-set-key "*" 'completion-separator-self-insert-command)
2329 (local-set-key "/" 'completion-separator-self-insert-command))
2373 2330
2374;;; Enable completion mode. 2331;; Enable completion mode.
2332
2333(defvar fortran-mode-hook)
2334
2335(defvar completion-saved-bindings nil)
2375 2336
2376;;;###autoload 2337;;;###autoload
2377(defun dynamic-completion-mode () 2338(define-minor-mode dynamic-completion-mode
2378 "Enable dynamic word-completion." 2339 "Enable dynamic word-completion."
2379 (interactive) 2340 :global t
2380 (add-hook 'find-file-hook 'cmpl-find-file-hook) 2341 ;; This is always good, not specific to dynamic-completion-mode.
2381 (add-hook 'pre-command-hook 'completion-before-command)
2382
2383 ;; Install the appropriate mode tables.
2384 (add-hook 'lisp-mode-hook
2385 (lambda ()
2386 (setq cmpl-syntax-table cmpl-lisp-syntax-table)))
2387 (add-hook 'c-mode-hook
2388 (lambda ()
2389 (setq cmpl-syntax-table cmpl-c-syntax-table)))
2390 (add-hook 'fortran-mode-hook
2391 (lambda ()
2392 (setq cmpl-syntax-table cmpl-fortran-syntax-table)
2393 (completion-setup-fortran-mode)))
2394
2395 ;; "Complete" Key Keybindings.
2396
2397 (global-set-key "\M-\r" 'complete)
2398 (global-set-key [?\C-\r] 'complete)
2399 (define-key function-key-map [C-return] [?\C-\r]) 2342 (define-key function-key-map [C-return] [?\C-\r])
2400 2343
2401 ;; Tests - 2344 (dolist (x '((find-file-hook . completion-find-file-hook)
2402 ;; (add-completion "cumberland") 2345 (pre-command-hook . completion-before-command)
2403 ;; (add-completion "cumberbund") 2346 ;; Save completions when killing Emacs.
2404 ;; cum 2347 (kill-emacs-hook . kill-emacs-save-completions)
2405 ;; Cumber 2348
2406 ;; cumbering 2349 ;; Install the appropriate mode tables.
2407 ;; cumb 2350 (lisp-mode-hook . completion-lisp-mode-hook)
2408 2351 (c-mode-hook . completion-c-mode-hook)
2409 ;; Save completions when killing Emacs. 2352 (fortran-mode-hook . completion-setup-fortran-mode)))
2410 2353 (if dynamic-completion-mode
2411 (add-hook 'kill-emacs-hook 2354 (add-hook (car x) (cdr x))
2412 (lambda () 2355 (remove-hook (car x) (cdr x))))
2413 (kill-emacs-save-completions) 2356
2414 (cmpl-statistics-block 2357 ;; "Complete" Key Keybindings. We don't want to use a minor-mode
2415 (record-cmpl-kill-emacs)))) 2358 ;; map because these have too high a priority. We could/should
2416 2359 ;; probably change the interpretation of minor-mode-map-alist such
2417 ;; Patches to standard keymaps insert completions 2360 ;; that a map has lower precedence if the symbol is not buffer-local.
2418 (substitute-key-definition 'kill-region 'completion-kill-region 2361 (while completion-saved-bindings
2419 global-map) 2362 (let ((binding (pop completion-saved-bindings)))
2420 2363 (global-set-key (car binding) (cdr binding))))
2421 ;; Separators 2364 (when dynamic-completion-mode
2422 ;; We've used the completion syntax table given as a guide. 2365 (dolist (binding
2423 ;; 2366 '(("\M-\r" . complete)
2424 ;; Global separator chars. 2367 ([?\C-\r] . complete)
2425 ;; We left out <tab> because there are too many special cases for it. Also, 2368
2426 ;; in normal coding it's rarely typed after a word. 2369 ;; Tests -
2427 (global-set-key " " 'completion-separator-self-insert-autofilling) 2370 ;; (add-completion "cumberland")
2428 (global-set-key "!" 'completion-separator-self-insert-command) 2371 ;; (add-completion "cumberbund")
2429 (global-set-key "%" 'completion-separator-self-insert-command) 2372 ;; cum
2430 (global-set-key "^" 'completion-separator-self-insert-command) 2373 ;; Cumber
2431 (global-set-key "&" 'completion-separator-self-insert-command) 2374 ;; cumbering
2432 (global-set-key "(" 'completion-separator-self-insert-command) 2375 ;; cumb
2433 (global-set-key ")" 'completion-separator-self-insert-command) 2376
2434 (global-set-key "=" 'completion-separator-self-insert-command) 2377 ;; Patches to standard keymaps insert completions
2435 (global-set-key "`" 'completion-separator-self-insert-command) 2378 ([remap kill-region] . completion-kill-region)
2436 (global-set-key "|" 'completion-separator-self-insert-command) 2379
2437 (global-set-key "{" 'completion-separator-self-insert-command) 2380 ;; Separators
2438 (global-set-key "}" 'completion-separator-self-insert-command) 2381 ;; We've used the completion syntax table given as a guide.
2439 (global-set-key "[" 'completion-separator-self-insert-command) 2382 ;;
2440 (global-set-key "]" 'completion-separator-self-insert-command) 2383 ;; Global separator chars.
2441 (global-set-key ";" 'completion-separator-self-insert-command) 2384 ;; We left out <tab> because there are too many special
2442 (global-set-key "\"" 'completion-separator-self-insert-command) 2385 ;; cases for it. Also, in normal coding it's rarely typed
2443 (global-set-key "'" 'completion-separator-self-insert-command) 2386 ;; after a word.
2444 (global-set-key "#" 'completion-separator-self-insert-command) 2387 (" " . completion-separator-self-insert-autofilling)
2445 (global-set-key "," 'completion-separator-self-insert-command) 2388 ("!" . completion-separator-self-insert-command)
2446 (global-set-key "?" 'completion-separator-self-insert-command) 2389 ("%" . completion-separator-self-insert-command)
2447 2390 ("^" . completion-separator-self-insert-command)
2448 ;; We include period and colon even though they are symbol chars because : 2391 ("&" . completion-separator-self-insert-command)
2449 ;; - in text we want to pick up the last word in a sentence. 2392 ("(" . completion-separator-self-insert-command)
2450 ;; - in C pointer refs. we want to pick up the first symbol 2393 (")" . completion-separator-self-insert-command)
2451 ;; - it won't make a difference for lisp mode (package names are short) 2394 ("=" . completion-separator-self-insert-command)
2452 (global-set-key "." 'completion-separator-self-insert-command) 2395 ("`" . completion-separator-self-insert-command)
2453 (global-set-key ":" 'completion-separator-self-insert-command) 2396 ("|" . completion-separator-self-insert-command)
2397 ("{" . completion-separator-self-insert-command)
2398 ("}" . completion-separator-self-insert-command)
2399 ("[" . completion-separator-self-insert-command)
2400 ("]" . completion-separator-self-insert-command)
2401 (";" . completion-separator-self-insert-command)
2402 ("\"". completion-separator-self-insert-command)
2403 ("'" . completion-separator-self-insert-command)
2404 ("#" . completion-separator-self-insert-command)
2405 ("," . completion-separator-self-insert-command)
2406 ("?" . completion-separator-self-insert-command)
2407
2408 ;; We include period and colon even though they are symbol
2409 ;; chars because :
2410 ;; - in text we want to pick up the last word in a sentence.
2411 ;; - in C pointer refs. we want to pick up the first symbol
2412 ;; - it won't make a difference for lisp mode (package names
2413 ;; are short)
2414 ("." . completion-separator-self-insert-command)
2415 (":" . completion-separator-self-insert-command)))
2416 (push (cons (car binding) (lookup-key global-map (car binding)))
2417 completion-saved-bindings)
2418 (global-set-key (car binding) (cdr binding)))
2419
2420 ;; Tests --
2421 ;; foobarbiz
2422 ;; foobar
2423 ;; fooquux
2424 ;; fooper
2454 2425
2455 ;; Lisp Mode diffs 2426 (cmpl-statistics-block
2456 (define-key lisp-mode-map "!" 'self-insert-command) 2427 (record-completion-file-loaded))
2457 (define-key lisp-mode-map "&" 'self-insert-command)
2458 (define-key lisp-mode-map "%" 'self-insert-command)
2459 (define-key lisp-mode-map "?" 'self-insert-command)
2460 (define-key lisp-mode-map "=" 'self-insert-command)
2461 (define-key lisp-mode-map "^" 'self-insert-command)
2462
2463 ;; Avoid warnings.
2464 (defvar c-mode-map)
2465 (defvar fortran-mode-map)
2466
2467 ;;-----------------------------------------------
2468 ;; End of line chars.
2469 ;;-----------------------------------------------
2470 (def-completion-wrapper newline :separator)
2471 (def-completion-wrapper newline-and-indent :separator)
2472 (def-completion-wrapper comint-send-input :separator)
2473 (def-completion-wrapper exit-minibuffer :minibuffer-separator)
2474 (def-completion-wrapper eval-print-last-sexp :separator)
2475 (def-completion-wrapper eval-last-sexp :separator)
2476 ;;(def-completion-wrapper minibuffer-complete-and-exit :minibuffer)
2477
2478 ;;-----------------------------------------------
2479 ;; Cursor movement
2480 ;;-----------------------------------------------
2481
2482 (def-completion-wrapper next-line :under-or-before)
2483 (def-completion-wrapper previous-line :under-or-before)
2484 (def-completion-wrapper beginning-of-buffer :under-or-before)
2485 (def-completion-wrapper end-of-buffer :under-or-before)
2486 (def-completion-wrapper beginning-of-line :under-or-before)
2487 (def-completion-wrapper end-of-line :under-or-before)
2488 (def-completion-wrapper forward-char :under-or-before)
2489 (def-completion-wrapper forward-word :under-or-before)
2490 (def-completion-wrapper forward-sexp :under-or-before)
2491 (def-completion-wrapper backward-char :backward-under)
2492 (def-completion-wrapper backward-word :backward-under)
2493 (def-completion-wrapper backward-sexp :backward-under)
2494
2495 (def-completion-wrapper delete-backward-char :backward)
2496 (def-completion-wrapper delete-backward-char-untabify :backward)
2497
2498 ;; Tests --
2499 ;; foobarbiz
2500 ;; foobar
2501 ;; fooquux
2502 ;; fooper
2503 2428
2504 (cmpl-statistics-block 2429 (completion-initialize)))
2505 (record-completion-file-loaded)) 2430
2431;;-----------------------------------------------
2432;; End of line chars.
2433;;-----------------------------------------------
2434(completion-def-wrapper 'newline :separator)
2435(completion-def-wrapper 'newline-and-indent :separator)
2436(completion-def-wrapper 'comint-send-input :separator)
2437(completion-def-wrapper 'exit-minibuffer :minibuffer-separator)
2438(completion-def-wrapper 'eval-print-last-sexp :separator)
2439(completion-def-wrapper 'eval-last-sexp :separator)
2440;;(completion-def-wrapper 'minibuffer-complete-and-exit :minibuffer)
2506 2441
2507 (initialize-completions)) 2442;;-----------------------------------------------
2443;; Cursor movement
2444;;-----------------------------------------------
2508 2445
2509(mapc (lambda (x) (add-to-list 'debug-ignored-errors x)) 2446(completion-def-wrapper 'next-line :under-or-before)
2510 '("^To complete, the point must be after a symbol at least [0-9]* character long\\.$" 2447(completion-def-wrapper 'previous-line :under-or-before)
2448(completion-def-wrapper 'beginning-of-buffer :under-or-before)
2449(completion-def-wrapper 'end-of-buffer :under-or-before)
2450(completion-def-wrapper 'beginning-of-line :under-or-before)
2451(completion-def-wrapper 'end-of-line :under-or-before)
2452(completion-def-wrapper 'forward-char :under-or-before)
2453(completion-def-wrapper 'forward-word :under-or-before)
2454(completion-def-wrapper 'forward-sexp :under-or-before)
2455(completion-def-wrapper 'backward-char :backward-under)
2456(completion-def-wrapper 'backward-word :backward-under)
2457(completion-def-wrapper 'backward-sexp :backward-under)
2458
2459(completion-def-wrapper 'delete-backward-char :backward)
2460(completion-def-wrapper 'delete-backward-char-untabify :backward)
2461
2462;; Old names, non-namespace-clean.
2463(defvaralias 'cmpl-syntax-table 'completion-syntax-table)
2464(defalias 'initialize-completions 'completion-initialize)
2465
2466(dolist (x '("^To complete, the point must be after a symbol at least [0-9]* character long\\.$"
2511 "^The string \".*\" is too short to be saved as a completion\\.$")) 2467 "^The string \".*\" is too short to be saved as a completion\\.$"))
2468 (add-to-list 'debug-ignored-errors x))
2512 2469
2513(provide 'completion) 2470(provide 'completion)
2514 2471
2515;;; arch-tag: 6990dafe-4abd-4a1f-8c42-ffb25e120f5e 2472;; arch-tag: 6990dafe-4abd-4a1f-8c42-ffb25e120f5e
2516;;; completion.el ends here 2473;;; completion.el ends here