diff options
| author | Richard M. Stallman | 1998-11-01 08:45:25 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-11-01 08:45:25 +0000 |
| commit | bb310d1ea9cd0e7d7952d5519ee3808022d1065c (patch) | |
| tree | 548259de4593aec375988b9c87ac06d13bd909e5 /lisp/completion.el | |
| parent | ebd32d7b078926ccfb6980e001aff6599a15171b (diff) | |
| download | emacs-bb310d1ea9cd0e7d7952d5519ee3808022d1065c.tar.gz emacs-bb310d1ea9cd0e7d7952d5519ee3808022d1065c.zip | |
(dynamic-completion-mode): New function to enable
the mode. (Just loading the file now does not change anything.)
Diffstat (limited to 'lisp/completion.el')
| -rw-r--r-- | lisp/completion.el | 284 |
1 files changed, 138 insertions, 146 deletions
diff --git a/lisp/completion.el b/lisp/completion.el index 297184e99bb..24b5326afee 100644 --- a/lisp/completion.el +++ b/lisp/completion.el | |||
| @@ -28,8 +28,7 @@ | |||
| 28 | 28 | ||
| 29 | ;; What to put in .emacs | 29 | ;; What to put in .emacs |
| 30 | ;;----------------------- | 30 | ;;----------------------- |
| 31 | ;; (load "completion") | 31 | ;; (dynamic-completion-mode) |
| 32 | ;; (initialize-completions) | ||
| 33 | 32 | ||
| 34 | ;;--------------------------------------------------------------------------- | 33 | ;;--------------------------------------------------------------------------- |
| 35 | ;; Documentation [Slightly out of date] | 34 | ;; Documentation [Slightly out of date] |
| @@ -617,23 +616,6 @@ Used to decide whether to save completions.") | |||
| 617 | (make-variable-buffer-local 'cmpl-syntax-table) | 616 | (make-variable-buffer-local 'cmpl-syntax-table) |
| 618 | 617 | ||
| 619 | ;;----------------------------------------------- | 618 | ;;----------------------------------------------- |
| 620 | ;; Installing the appropriate mode tables | ||
| 621 | ;;----------------------------------------------- | ||
| 622 | |||
| 623 | (add-hook 'lisp-mode-hook | ||
| 624 | '(lambda () | ||
| 625 | (setq cmpl-syntax-table cmpl-lisp-syntax-table))) | ||
| 626 | |||
| 627 | (add-hook 'c-mode-hook | ||
| 628 | '(lambda () | ||
| 629 | (setq cmpl-syntax-table cmpl-c-syntax-table))) | ||
| 630 | |||
| 631 | (add-hook 'fortran-mode-hook | ||
| 632 | '(lambda () | ||
| 633 | (setq cmpl-syntax-table cmpl-fortran-syntax-table) | ||
| 634 | (completion-setup-fortran-mode))) | ||
| 635 | |||
| 636 | ;;----------------------------------------------- | ||
| 637 | ;; Symbol functions | 619 | ;; Symbol functions |
| 638 | ;;----------------------------------------------- | 620 | ;;----------------------------------------------- |
| 639 | (defvar cmpl-symbol-start nil | 621 | (defvar cmpl-symbol-start nil |
| @@ -875,11 +857,11 @@ Returns nil if there isn't one longer than `completion-min-length'." | |||
| 875 | ;; "The current point position the cdabbrev search is at.") | 857 | ;; "The current point position the cdabbrev search is at.") |
| 876 | 858 | ||
| 877 | (defvar cdabbrev-current-window nil) | 859 | (defvar cdabbrev-current-window nil) |
| 878 | ;; "The current window we are looking for cdabbrevs in. T if looking in | 860 | ;; "The current window we are looking for cdabbrevs in. |
| 879 | ;; (other-buffer), NIL if no more cdabbrevs.") | 861 | ;; Return t if looking in (other-buffer), nil if no more cdabbrevs.") |
| 880 | 862 | ||
| 881 | (defvar cdabbrev-wrapped-p nil) | 863 | (defvar cdabbrev-wrapped-p nil) |
| 882 | ;; "T if the cdabbrev search has wrapped around the file.") | 864 | ;; "Return t if the cdabbrev search has wrapped around the file.") |
| 883 | 865 | ||
| 884 | (defvar cdabbrev-abbrev-string "") | 866 | (defvar cdabbrev-abbrev-string "") |
| 885 | (defvar cdabbrev-start-point 0) | 867 | (defvar cdabbrev-start-point 0) |
| @@ -1891,23 +1873,6 @@ Prefix args :: | |||
| 1891 | ;; Pretend that we were never here | 1873 | ;; Pretend that we were never here |
| 1892 | (setq this-command 'failed-complete) | 1874 | (setq this-command 'failed-complete) |
| 1893 | )))) | 1875 | )))) |
| 1894 | |||
| 1895 | ;;----------------------------------------------- | ||
| 1896 | ;; "Complete" Key Keybindings | ||
| 1897 | ;;----------------------------------------------- | ||
| 1898 | |||
| 1899 | (global-set-key "\M-\r" 'complete) | ||
| 1900 | (global-set-key [?\C-\r] 'complete) | ||
| 1901 | (define-key function-key-map [C-return] [?\C-\r]) | ||
| 1902 | |||
| 1903 | ;; Tests - | ||
| 1904 | ;; (add-completion "cumberland") | ||
| 1905 | ;; (add-completion "cumberbund") | ||
| 1906 | ;; cum | ||
| 1907 | ;; Cumber | ||
| 1908 | ;; cumbering | ||
| 1909 | ;; cumb | ||
| 1910 | |||
| 1911 | 1876 | ||
| 1912 | ;;--------------------------------------------------------------------------- | 1877 | ;;--------------------------------------------------------------------------- |
| 1913 | ;; Parsing definitions from files into the database | 1878 | ;; Parsing definitions from files into the database |
| @@ -1976,8 +1941,6 @@ Prefix args :: | |||
| 1976 | (add-completions-from-buffer) | 1941 | (add-completions-from-buffer) |
| 1977 | ))) | 1942 | ))) |
| 1978 | )) | 1943 | )) |
| 1979 | |||
| 1980 | (add-hook 'find-file-hooks 'cmpl-find-file-hook) | ||
| 1981 | 1944 | ||
| 1982 | ;;----------------------------------------------- | 1945 | ;;----------------------------------------------- |
| 1983 | ;; Tags Table Completions | 1946 | ;; Tags Table Completions |
| @@ -2470,17 +2433,6 @@ Also sets up so that exiting emacs will automatically save the file." | |||
| 2470 | )) | 2433 | )) |
| 2471 | (setq cmpl-initialized-p t) | 2434 | (setq cmpl-initialized-p t) |
| 2472 | ) | 2435 | ) |
| 2473 | |||
| 2474 | |||
| 2475 | ;;----------------------------------------------- | ||
| 2476 | ;; Kill EMACS patch | ||
| 2477 | ;;----------------------------------------------- | ||
| 2478 | |||
| 2479 | (add-hook 'kill-emacs-hook | ||
| 2480 | '(lambda () | ||
| 2481 | (kill-emacs-save-completions) | ||
| 2482 | (cmpl-statistics-block | ||
| 2483 | (record-cmpl-kill-emacs)))) | ||
| 2484 | 2436 | ||
| 2485 | ;;----------------------------------------------- | 2437 | ;;----------------------------------------------- |
| 2486 | ;; Kill region patch | 2438 | ;; Kill region patch |
| @@ -2510,7 +2462,6 @@ Patched to remove the most recent completion." | |||
| 2510 | (t | 2462 | (t |
| 2511 | (kill-region beg end)))) | 2463 | (kill-region beg end)))) |
| 2512 | 2464 | ||
| 2513 | (global-set-key "\C-w" 'completion-kill-region) | ||
| 2514 | 2465 | ||
| 2515 | ;;----------------------------------------------- | 2466 | ;;----------------------------------------------- |
| 2516 | ;; Patches to self-insert-command. | 2467 | ;; Patches to self-insert-command. |
| @@ -2590,61 +2541,7 @@ TYPE is the type of the wrapper to be added. Can be :before or :under." | |||
| 2590 | (funcall (or (and (symbolp this-command) | 2541 | (funcall (or (and (symbolp this-command) |
| 2591 | (get this-command 'completion-function)) | 2542 | (get this-command 'completion-function)) |
| 2592 | 'use-completion-under-or-before-point))) | 2543 | 'use-completion-under-or-before-point))) |
| 2593 | (add-hook 'pre-command-hook 'completion-before-command) | 2544 | |
| 2594 | |||
| 2595 | |||
| 2596 | ;;--------------------------------------------------------------------------- | ||
| 2597 | ;; Patches to standard keymaps insert completions | ||
| 2598 | ;;--------------------------------------------------------------------------- | ||
| 2599 | |||
| 2600 | ;;----------------------------------------------- | ||
| 2601 | ;; Separators | ||
| 2602 | ;;----------------------------------------------- | ||
| 2603 | ;; We've used the completion syntax table given as a guide. | ||
| 2604 | ;; | ||
| 2605 | ;; Global separator chars. | ||
| 2606 | ;; We left out <tab> because there are too many special cases for it. Also, | ||
| 2607 | ;; in normal coding it's rarely typed after a word. | ||
| 2608 | (global-set-key " " 'completion-separator-self-insert-autofilling) | ||
| 2609 | (global-set-key "!" 'completion-separator-self-insert-command) | ||
| 2610 | (global-set-key "%" 'completion-separator-self-insert-command) | ||
| 2611 | (global-set-key "^" 'completion-separator-self-insert-command) | ||
| 2612 | (global-set-key "&" 'completion-separator-self-insert-command) | ||
| 2613 | (global-set-key "(" 'completion-separator-self-insert-command) | ||
| 2614 | (global-set-key ")" 'completion-separator-self-insert-command) | ||
| 2615 | (global-set-key "=" 'completion-separator-self-insert-command) | ||
| 2616 | (global-set-key "`" 'completion-separator-self-insert-command) | ||
| 2617 | (global-set-key "|" 'completion-separator-self-insert-command) | ||
| 2618 | (global-set-key "{" 'completion-separator-self-insert-command) | ||
| 2619 | (global-set-key "}" 'completion-separator-self-insert-command) | ||
| 2620 | (global-set-key "[" 'completion-separator-self-insert-command) | ||
| 2621 | (global-set-key "]" 'completion-separator-self-insert-command) | ||
| 2622 | (global-set-key ";" 'completion-separator-self-insert-command) | ||
| 2623 | (global-set-key "\"" 'completion-separator-self-insert-command) | ||
| 2624 | (global-set-key "'" 'completion-separator-self-insert-command) | ||
| 2625 | (global-set-key "#" 'completion-separator-self-insert-command) | ||
| 2626 | (global-set-key "," 'completion-separator-self-insert-command) | ||
| 2627 | (global-set-key "?" 'completion-separator-self-insert-command) | ||
| 2628 | |||
| 2629 | ;; We include period and colon even though they are symbol chars because : | ||
| 2630 | ;; - in text we want to pick up the last word in a sentence. | ||
| 2631 | ;; - in C pointer refs. we want to pick up the first symbol | ||
| 2632 | ;; - it won't make a difference for lisp mode (package names are short) | ||
| 2633 | (global-set-key "." 'completion-separator-self-insert-command) | ||
| 2634 | (global-set-key ":" 'completion-separator-self-insert-command) | ||
| 2635 | |||
| 2636 | ;; Lisp Mode diffs | ||
| 2637 | (define-key lisp-mode-map "!" 'self-insert-command) | ||
| 2638 | (define-key lisp-mode-map "&" 'self-insert-command) | ||
| 2639 | (define-key lisp-mode-map "%" 'self-insert-command) | ||
| 2640 | (define-key lisp-mode-map "?" 'self-insert-command) | ||
| 2641 | (define-key lisp-mode-map "=" 'self-insert-command) | ||
| 2642 | (define-key lisp-mode-map "^" 'self-insert-command) | ||
| 2643 | |||
| 2644 | ;; Avoid warnings. | ||
| 2645 | (defvar c-mode-map) | ||
| 2646 | (defvar fortran-mode-map) | ||
| 2647 | |||
| 2648 | ;; C mode diffs. | 2545 | ;; C mode diffs. |
| 2649 | (defun completion-c-mode-hook () | 2546 | (defun completion-c-mode-hook () |
| 2650 | (def-completion-wrapper electric-c-semi :separator) | 2547 | (def-completion-wrapper electric-c-semi :separator) |
| @@ -2663,46 +2560,141 @@ TYPE is the type of the wrapper to be added. Can be :before or :under." | |||
| 2663 | (define-key fortran-mode-map "*" 'completion-separator-self-insert-command) | 2560 | (define-key fortran-mode-map "*" 'completion-separator-self-insert-command) |
| 2664 | (define-key fortran-mode-map "/" 'completion-separator-self-insert-command) | 2561 | (define-key fortran-mode-map "/" 'completion-separator-self-insert-command) |
| 2665 | ) | 2562 | ) |
| 2563 | |||
| 2564 | ;;; Enable completion mode. | ||
| 2565 | |||
| 2566 | ;;;###autoload | ||
| 2567 | (defun dynamic-completion-mode () | ||
| 2568 | "Enable dynamic word-completion." | ||
| 2569 | (interactive) | ||
| 2570 | (add-hook 'find-file-hooks 'cmpl-find-file-hook) | ||
| 2571 | (add-hook 'pre-command-hook 'completion-before-command) | ||
| 2572 | |||
| 2573 | ;; Install the appropriate mode tables. | ||
| 2574 | (add-hook 'lisp-mode-hook | ||
| 2575 | '(lambda () | ||
| 2576 | (setq cmpl-syntax-table cmpl-lisp-syntax-table))) | ||
| 2577 | (add-hook 'c-mode-hook | ||
| 2578 | '(lambda () | ||
| 2579 | (setq cmpl-syntax-table cmpl-c-syntax-table))) | ||
| 2580 | (add-hook 'fortran-mode-hook | ||
| 2581 | '(lambda () | ||
| 2582 | (setq cmpl-syntax-table cmpl-fortran-syntax-table) | ||
| 2583 | (completion-setup-fortran-mode))) | ||
| 2584 | |||
| 2585 | ;; "Complete" Key Keybindings. | ||
| 2586 | |||
| 2587 | (global-set-key "\M-\r" 'complete) | ||
| 2588 | (global-set-key [?\C-\r] 'complete) | ||
| 2589 | (define-key function-key-map [C-return] [?\C-\r]) | ||
| 2590 | |||
| 2591 | ;; Tests - | ||
| 2592 | ;; (add-completion "cumberland") | ||
| 2593 | ;; (add-completion "cumberbund") | ||
| 2594 | ;; cum | ||
| 2595 | ;; Cumber | ||
| 2596 | ;; cumbering | ||
| 2597 | ;; cumb | ||
| 2598 | |||
| 2599 | ;; Save completions when killing Emacs. | ||
| 2600 | |||
| 2601 | (add-hook 'kill-emacs-hook | ||
| 2602 | '(lambda () | ||
| 2603 | (kill-emacs-save-completions) | ||
| 2604 | (cmpl-statistics-block | ||
| 2605 | (record-cmpl-kill-emacs)))) | ||
| 2606 | |||
| 2607 | ;; Patches to standard keymaps insert completions | ||
| 2608 | (substitute-key-definition 'kill-region 'completion-kill-region | ||
| 2609 | global-map) | ||
| 2610 | |||
| 2611 | ;; Separators | ||
| 2612 | ;; We've used the completion syntax table given as a guide. | ||
| 2613 | ;; | ||
| 2614 | ;; Global separator chars. | ||
| 2615 | ;; We left out <tab> because there are too many special cases for it. Also, | ||
| 2616 | ;; in normal coding it's rarely typed after a word. | ||
| 2617 | (global-set-key " " 'completion-separator-self-insert-autofilling) | ||
| 2618 | (global-set-key "!" 'completion-separator-self-insert-command) | ||
| 2619 | (global-set-key "%" 'completion-separator-self-insert-command) | ||
| 2620 | (global-set-key "^" 'completion-separator-self-insert-command) | ||
| 2621 | (global-set-key "&" 'completion-separator-self-insert-command) | ||
| 2622 | (global-set-key "(" 'completion-separator-self-insert-command) | ||
| 2623 | (global-set-key ")" 'completion-separator-self-insert-command) | ||
| 2624 | (global-set-key "=" 'completion-separator-self-insert-command) | ||
| 2625 | (global-set-key "`" 'completion-separator-self-insert-command) | ||
| 2626 | (global-set-key "|" 'completion-separator-self-insert-command) | ||
| 2627 | (global-set-key "{" 'completion-separator-self-insert-command) | ||
| 2628 | (global-set-key "}" 'completion-separator-self-insert-command) | ||
| 2629 | (global-set-key "[" 'completion-separator-self-insert-command) | ||
| 2630 | (global-set-key "]" 'completion-separator-self-insert-command) | ||
| 2631 | (global-set-key ";" 'completion-separator-self-insert-command) | ||
| 2632 | (global-set-key "\"" 'completion-separator-self-insert-command) | ||
| 2633 | (global-set-key "'" 'completion-separator-self-insert-command) | ||
| 2634 | (global-set-key "#" 'completion-separator-self-insert-command) | ||
| 2635 | (global-set-key "," 'completion-separator-self-insert-command) | ||
| 2636 | (global-set-key "?" 'completion-separator-self-insert-command) | ||
| 2637 | |||
| 2638 | ;; We include period and colon even though they are symbol chars because : | ||
| 2639 | ;; - in text we want to pick up the last word in a sentence. | ||
| 2640 | ;; - in C pointer refs. we want to pick up the first symbol | ||
| 2641 | ;; - it won't make a difference for lisp mode (package names are short) | ||
| 2642 | (global-set-key "." 'completion-separator-self-insert-command) | ||
| 2643 | (global-set-key ":" 'completion-separator-self-insert-command) | ||
| 2644 | |||
| 2645 | ;; Lisp Mode diffs | ||
| 2646 | (define-key lisp-mode-map "!" 'self-insert-command) | ||
| 2647 | (define-key lisp-mode-map "&" 'self-insert-command) | ||
| 2648 | (define-key lisp-mode-map "%" 'self-insert-command) | ||
| 2649 | (define-key lisp-mode-map "?" 'self-insert-command) | ||
| 2650 | (define-key lisp-mode-map "=" 'self-insert-command) | ||
| 2651 | (define-key lisp-mode-map "^" 'self-insert-command) | ||
| 2652 | |||
| 2653 | ;; Avoid warnings. | ||
| 2654 | (defvar c-mode-map) | ||
| 2655 | (defvar fortran-mode-map) | ||
| 2656 | |||
| 2657 | ;;----------------------------------------------- | ||
| 2658 | ;; End of line chars. | ||
| 2659 | ;;----------------------------------------------- | ||
| 2660 | (def-completion-wrapper newline :separator) | ||
| 2661 | (def-completion-wrapper newline-and-indent :separator) | ||
| 2662 | (def-completion-wrapper comint-send-input :separator) | ||
| 2663 | (def-completion-wrapper exit-minibuffer :minibuffer-separator) | ||
| 2664 | (def-completion-wrapper eval-print-last-sexp :separator) | ||
| 2665 | (def-completion-wrapper eval-last-sexp :separator) | ||
| 2666 | ;;(def-completion-wrapper minibuffer-complete-and-exit :minibuffer) | ||
| 2667 | |||
| 2668 | ;;----------------------------------------------- | ||
| 2669 | ;; Cursor movement | ||
| 2670 | ;;----------------------------------------------- | ||
| 2671 | |||
| 2672 | (def-completion-wrapper next-line :under-or-before) | ||
| 2673 | (def-completion-wrapper previous-line :under-or-before) | ||
| 2674 | (def-completion-wrapper beginning-of-buffer :under-or-before) | ||
| 2675 | (def-completion-wrapper end-of-buffer :under-or-before) | ||
| 2676 | (def-completion-wrapper beginning-of-line :under-or-before) | ||
| 2677 | (def-completion-wrapper end-of-line :under-or-before) | ||
| 2678 | (def-completion-wrapper forward-char :under-or-before) | ||
| 2679 | (def-completion-wrapper forward-word :under-or-before) | ||
| 2680 | (def-completion-wrapper forward-sexp :under-or-before) | ||
| 2681 | (def-completion-wrapper backward-char :backward-under) | ||
| 2682 | (def-completion-wrapper backward-word :backward-under) | ||
| 2683 | (def-completion-wrapper backward-sexp :backward-under) | ||
| 2684 | |||
| 2685 | (def-completion-wrapper delete-backward-char :backward) | ||
| 2686 | (def-completion-wrapper delete-backward-char-untabify :backward) | ||
| 2687 | |||
| 2688 | ;; Tests -- | ||
| 2689 | ;; foobarbiz | ||
| 2690 | ;; foobar | ||
| 2691 | ;; fooquux | ||
| 2692 | ;; fooper | ||
| 2666 | 2693 | ||
| 2667 | ;;----------------------------------------------- | 2694 | (cmpl-statistics-block |
| 2668 | ;; End of line chars. | 2695 | (record-completion-file-loaded)) |
| 2669 | ;;----------------------------------------------- | ||
| 2670 | (def-completion-wrapper newline :separator) | ||
| 2671 | (def-completion-wrapper newline-and-indent :separator) | ||
| 2672 | (def-completion-wrapper comint-send-input :separator) | ||
| 2673 | (def-completion-wrapper exit-minibuffer :minibuffer-separator) | ||
| 2674 | (def-completion-wrapper eval-print-last-sexp :separator) | ||
| 2675 | (def-completion-wrapper eval-last-sexp :separator) | ||
| 2676 | ;;(def-completion-wrapper minibuffer-complete-and-exit :minibuffer) | ||
| 2677 | |||
| 2678 | ;;----------------------------------------------- | ||
| 2679 | ;; Cursor movement | ||
| 2680 | ;;----------------------------------------------- | ||
| 2681 | |||
| 2682 | (def-completion-wrapper next-line :under-or-before) | ||
| 2683 | (def-completion-wrapper previous-line :under-or-before) | ||
| 2684 | (def-completion-wrapper beginning-of-buffer :under-or-before) | ||
| 2685 | (def-completion-wrapper end-of-buffer :under-or-before) | ||
| 2686 | (def-completion-wrapper beginning-of-line :under-or-before) | ||
| 2687 | (def-completion-wrapper end-of-line :under-or-before) | ||
| 2688 | (def-completion-wrapper forward-char :under-or-before) | ||
| 2689 | (def-completion-wrapper forward-word :under-or-before) | ||
| 2690 | (def-completion-wrapper forward-sexp :under-or-before) | ||
| 2691 | (def-completion-wrapper backward-char :backward-under) | ||
| 2692 | (def-completion-wrapper backward-word :backward-under) | ||
| 2693 | (def-completion-wrapper backward-sexp :backward-under) | ||
| 2694 | |||
| 2695 | (def-completion-wrapper delete-backward-char :backward) | ||
| 2696 | (def-completion-wrapper delete-backward-char-untabify :backward) | ||
| 2697 | |||
| 2698 | ;; Tests -- | ||
| 2699 | ;; foobarbiz | ||
| 2700 | ;; foobar | ||
| 2701 | ;; fooquux | ||
| 2702 | ;; fooper | ||
| 2703 | 2696 | ||
| 2704 | (cmpl-statistics-block | 2697 | (initialize-completions)) |
| 2705 | (record-completion-file-loaded)) | ||
| 2706 | 2698 | ||
| 2707 | (provide 'completion) | 2699 | (provide 'completion) |
| 2708 | 2700 | ||