]> code.delx.au - gnu-emacs/blobdiff - lisp/completion.el
(list-faces-display): Multiline case of previous fix.
[gnu-emacs] / lisp / completion.el
index 67127020c1c8b0005090a7e517fc0dff155de025..24b5326afeedbb568849a7aef4fe2369f8c7942d 100644 (file)
@@ -3,7 +3,7 @@
 ;; Copyright (C) 1990, 1993, 1995, 1997 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
-;; Keywords: abbrev
+;; Keywords: abbrev convenience
 ;; Author: Jim Salem <alem@bbnplanet.com> of Thinking Machines Inc.
 ;;  (ideas suggested by Brewster Kahle)
 
@@ -28,8 +28,7 @@
 
 ;; What to put in .emacs
 ;;-----------------------
-;; (load "completion")
-;; (initialize-completions)
+;; (dynamic-completion-mode)
 \f
 ;;---------------------------------------------------------------------------
 ;; Documentation [Slightly out of date]
 
 (defgroup completion nil
   "Dynamic word-completion code."
-  :group 'matching)
+  :group 'matching
+  :group 'convenience)
 
 
 (defcustom enable-completion t
@@ -292,7 +292,7 @@ If nil, no new words added to the database or saved to the init file."
 
 (defcustom save-completions-flag t
   "*Non-nil means save most-used completions when exiting Emacs.
-See also `saved-completions-retention-time'."
+See also `save-completions-retention-time'."
   :type 'boolean
   :group 'completion)
 
@@ -615,23 +615,6 @@ Used to decide whether to save completions.")
   "This variable holds the current completion syntax table.")
 (make-variable-buffer-local 'cmpl-syntax-table)
 
-;;-----------------------------------------------
-;; Installing the appropriate mode tables
-;;-----------------------------------------------
-
-(add-hook 'lisp-mode-hook
-         '(lambda ()
-            (setq cmpl-syntax-table cmpl-lisp-syntax-table)))
-
-(add-hook 'c-mode-hook
-         '(lambda ()
-            (setq cmpl-syntax-table cmpl-c-syntax-table)))
-
-(add-hook 'fortran-mode-hook
-         '(lambda ()
-            (setq cmpl-syntax-table cmpl-fortran-syntax-table)
-            (completion-setup-fortran-mode)))
-
 ;;-----------------------------------------------
 ;; Symbol functions
 ;;-----------------------------------------------
@@ -874,11 +857,11 @@ Returns nil if there isn't one longer than `completion-min-length'."
 ;;  "The current point position the cdabbrev search is at.")
 
 (defvar cdabbrev-current-window nil)
-;;  "The current window we are looking for cdabbrevs in.  T if looking in
-;; (other-buffer), NIL if no more  cdabbrevs.")
+;;  "The current window we are looking for cdabbrevs in.
+;; Return t if looking in (other-buffer), nil if no more  cdabbrevs.")
 
 (defvar cdabbrev-wrapped-p nil)
-;;  "T if the cdabbrev search has wrapped around the file.")
+;;  "Return t if the cdabbrev search has wrapped around the file.")
 
 (defvar cdabbrev-abbrev-string "")
 (defvar cdabbrev-start-point 0)
@@ -1890,23 +1873,6 @@ Prefix args ::
           ;; Pretend that we were never here
           (setq this-command 'failed-complete)
           ))))
-
-;;-----------------------------------------------
-;; "Complete" Key Keybindings
-;;-----------------------------------------------
-
-(global-set-key "\M-\r" 'complete)
-(global-set-key [?\C-\r] 'complete)
-(define-key function-key-map [C-return] [?\C-\r])
-
-;; Tests -
-;; (add-completion "cumberland")
-;; (add-completion "cumberbund")
-;; cum
-;; Cumber
-;; cumbering
-;; cumb
-
 \f
 ;;---------------------------------------------------------------------------
 ;; Parsing definitions from files into the database
@@ -1975,8 +1941,6 @@ Prefix args ::
                (add-completions-from-buffer)
                )))
        ))
-    
-(add-hook 'find-file-hooks 'cmpl-find-file-hook)
 
 ;;-----------------------------------------------
 ;; Tags Table Completions
@@ -2345,14 +2309,14 @@ If file name is not specified, use `save-completions-file-name'."
           (record-save-completions total-in-db total-perm total-saved))
          ))))
 
-;;(defun autosave-completions ()
+;;(defun auto-save-completions ()
 ;;  (if (and save-completions-flag enable-completion cmpl-initialized-p
 ;;           *completion-auto-save-period*
 ;;           (> cmpl-emacs-idle-time *completion-auto-save-period*)
 ;;           cmpl-completions-accepted-p)
 ;;    (save-completions-to-file)))
 
-;;(add-hook 'cmpl-emacs-idle-time-hooks 'autosave-completions)
+;;(add-hook 'cmpl-emacs-idle-time-hooks 'auto-save-completions)
 
 (defun load-completions-from-file (&optional filename no-message-p)
   "Loads a completion init file FILENAME.
@@ -2469,17 +2433,6 @@ Also sets up so that exiting emacs will automatically save the file."
         ))
   (setq cmpl-initialized-p t)
   )
-
-
-;;-----------------------------------------------
-;; Kill EMACS patch
-;;-----------------------------------------------
-
-(add-hook 'kill-emacs-hook
-         '(lambda ()
-            (kill-emacs-save-completions)
-            (cmpl-statistics-block
-             (record-cmpl-kill-emacs))))
 \f
 ;;-----------------------------------------------
 ;; Kill region patch
@@ -2509,7 +2462,6 @@ Patched to remove the most recent completion."
        (t
         (kill-region beg end))))
 
-(global-set-key "\C-w" 'completion-kill-region)
 \f
 ;;-----------------------------------------------
 ;; Patches to self-insert-command.
@@ -2589,61 +2541,7 @@ TYPE is the type of the wrapper to be added.  Can be :before or :under."
   (funcall (or (and (symbolp this-command)
                    (get this-command 'completion-function))
               'use-completion-under-or-before-point)))
-(add-hook 'pre-command-hook 'completion-before-command)
-
-
-;;---------------------------------------------------------------------------
-;; Patches to standard keymaps insert completions
-;;---------------------------------------------------------------------------
-
-;;-----------------------------------------------
-;; Separators
-;;-----------------------------------------------
-;; We've used the completion syntax table given  as a guide.
-;;
-;; Global separator chars.
-;;  We left out <tab> because there are too many special cases for it.  Also,
-;; in normal coding it's rarely typed after a word.
-(global-set-key " " 'completion-separator-self-insert-autofilling)
-(global-set-key "!" 'completion-separator-self-insert-command)
-(global-set-key "%" 'completion-separator-self-insert-command)
-(global-set-key "^" 'completion-separator-self-insert-command)
-(global-set-key "&" 'completion-separator-self-insert-command)
-(global-set-key "(" 'completion-separator-self-insert-command)
-(global-set-key ")" 'completion-separator-self-insert-command)
-(global-set-key "=" 'completion-separator-self-insert-command)
-(global-set-key "`" 'completion-separator-self-insert-command)
-(global-set-key "|" 'completion-separator-self-insert-command)
-(global-set-key "{" 'completion-separator-self-insert-command)
-(global-set-key "}" 'completion-separator-self-insert-command)
-(global-set-key "[" 'completion-separator-self-insert-command)
-(global-set-key "]" 'completion-separator-self-insert-command)
-(global-set-key ";" 'completion-separator-self-insert-command)
-(global-set-key "\"" 'completion-separator-self-insert-command)
-(global-set-key "'" 'completion-separator-self-insert-command)
-(global-set-key "#" 'completion-separator-self-insert-command)
-(global-set-key "," 'completion-separator-self-insert-command)
-(global-set-key "?" 'completion-separator-self-insert-command)
-
-;; We include period and colon even though they are symbol chars because :
-;;  - in text we want to pick up the last word in a sentence.
-;;  - in C pointer refs. we want to pick up the first symbol
-;;  - it won't make a difference for lisp mode (package names are short)
-(global-set-key "." 'completion-separator-self-insert-command)
-(global-set-key ":" 'completion-separator-self-insert-command)
-
-;; Lisp Mode diffs
-(define-key lisp-mode-map "!" 'self-insert-command)
-(define-key lisp-mode-map "&" 'self-insert-command)
-(define-key lisp-mode-map "%" 'self-insert-command)
-(define-key lisp-mode-map "?" 'self-insert-command)
-(define-key lisp-mode-map "=" 'self-insert-command)
-(define-key lisp-mode-map "^" 'self-insert-command)
-
-;; Avoid warnings.
-(defvar c-mode-map)
-(defvar fortran-mode-map)
-
+\f
 ;; C mode diffs.
 (defun completion-c-mode-hook ()
   (def-completion-wrapper electric-c-semi :separator)
@@ -2662,46 +2560,141 @@ TYPE is the type of the wrapper to be added.  Can be :before or :under."
   (define-key fortran-mode-map "*" 'completion-separator-self-insert-command)
   (define-key fortran-mode-map "/" 'completion-separator-self-insert-command)
   )
+\f
+;;; Enable completion mode.
+  
+;;;###autoload
+(defun dynamic-completion-mode ()
+  "Enable dynamic word-completion."
+  (interactive)
+  (add-hook 'find-file-hooks 'cmpl-find-file-hook)
+  (add-hook 'pre-command-hook 'completion-before-command)
+
+  ;; Install the appropriate mode tables.
+  (add-hook 'lisp-mode-hook
+           '(lambda ()
+              (setq cmpl-syntax-table cmpl-lisp-syntax-table)))
+  (add-hook 'c-mode-hook
+           '(lambda ()
+              (setq cmpl-syntax-table cmpl-c-syntax-table)))
+  (add-hook 'fortran-mode-hook
+           '(lambda ()
+              (setq cmpl-syntax-table cmpl-fortran-syntax-table)
+              (completion-setup-fortran-mode)))
+
+  ;; "Complete" Key Keybindings.
+
+  (global-set-key "\M-\r" 'complete)
+  (global-set-key [?\C-\r] 'complete)
+  (define-key function-key-map [C-return] [?\C-\r])
+
+  ;; Tests -
+  ;; (add-completion "cumberland")
+  ;; (add-completion "cumberbund")
+  ;; cum
+  ;; Cumber
+  ;; cumbering
+  ;; cumb
+
+  ;; Save completions when killing Emacs.
+
+  (add-hook 'kill-emacs-hook
+           '(lambda ()
+              (kill-emacs-save-completions)
+              (cmpl-statistics-block
+               (record-cmpl-kill-emacs))))
+
+  ;; Patches to standard keymaps insert completions
+  (substitute-key-definition 'kill-region 'completion-kill-region
+                            global-map)
+
+  ;; Separators
+  ;; We've used the completion syntax table given  as a guide.
+  ;;
+  ;; Global separator chars.
+  ;;  We left out <tab> because there are too many special cases for it.  Also,
+  ;; in normal coding it's rarely typed after a word.
+  (global-set-key " " 'completion-separator-self-insert-autofilling)
+  (global-set-key "!" 'completion-separator-self-insert-command)
+  (global-set-key "%" 'completion-separator-self-insert-command)
+  (global-set-key "^" 'completion-separator-self-insert-command)
+  (global-set-key "&" 'completion-separator-self-insert-command)
+  (global-set-key "(" 'completion-separator-self-insert-command)
+  (global-set-key ")" 'completion-separator-self-insert-command)
+  (global-set-key "=" 'completion-separator-self-insert-command)
+  (global-set-key "`" 'completion-separator-self-insert-command)
+  (global-set-key "|" 'completion-separator-self-insert-command)
+  (global-set-key "{" 'completion-separator-self-insert-command)
+  (global-set-key "}" 'completion-separator-self-insert-command)
+  (global-set-key "[" 'completion-separator-self-insert-command)
+  (global-set-key "]" 'completion-separator-self-insert-command)
+  (global-set-key ";" 'completion-separator-self-insert-command)
+  (global-set-key "\"" 'completion-separator-self-insert-command)
+  (global-set-key "'" 'completion-separator-self-insert-command)
+  (global-set-key "#" 'completion-separator-self-insert-command)
+  (global-set-key "," 'completion-separator-self-insert-command)
+  (global-set-key "?" 'completion-separator-self-insert-command)
+
+  ;; We include period and colon even though they are symbol chars because :
+  ;;  - in text we want to pick up the last word in a sentence.
+  ;;  - in C pointer refs. we want to pick up the first symbol
+  ;;  - it won't make a difference for lisp mode (package names are short)
+  (global-set-key "." 'completion-separator-self-insert-command)
+  (global-set-key ":" 'completion-separator-self-insert-command)
+
+  ;; Lisp Mode diffs
+  (define-key lisp-mode-map "!" 'self-insert-command)
+  (define-key lisp-mode-map "&" 'self-insert-command)
+  (define-key lisp-mode-map "%" 'self-insert-command)
+  (define-key lisp-mode-map "?" 'self-insert-command)
+  (define-key lisp-mode-map "=" 'self-insert-command)
+  (define-key lisp-mode-map "^" 'self-insert-command)
+
+  ;; Avoid warnings.
+  (defvar c-mode-map)
+  (defvar fortran-mode-map)
+
+  ;;-----------------------------------------------
+  ;; End of line chars.
+  ;;-----------------------------------------------
+  (def-completion-wrapper newline :separator)
+  (def-completion-wrapper newline-and-indent :separator)
+  (def-completion-wrapper comint-send-input :separator)
+  (def-completion-wrapper exit-minibuffer :minibuffer-separator)
+  (def-completion-wrapper eval-print-last-sexp :separator)
+  (def-completion-wrapper eval-last-sexp :separator)
+  ;;(def-completion-wrapper minibuffer-complete-and-exit :minibuffer)
+
+  ;;-----------------------------------------------
+  ;; Cursor movement
+  ;;-----------------------------------------------
+
+  (def-completion-wrapper next-line :under-or-before)
+  (def-completion-wrapper previous-line :under-or-before)
+  (def-completion-wrapper beginning-of-buffer :under-or-before)
+  (def-completion-wrapper end-of-buffer :under-or-before)
+  (def-completion-wrapper beginning-of-line :under-or-before)
+  (def-completion-wrapper end-of-line :under-or-before)
+  (def-completion-wrapper forward-char :under-or-before)
+  (def-completion-wrapper forward-word :under-or-before)
+  (def-completion-wrapper forward-sexp :under-or-before)
+  (def-completion-wrapper backward-char :backward-under)
+  (def-completion-wrapper backward-word :backward-under)
+  (def-completion-wrapper backward-sexp :backward-under)
+
+  (def-completion-wrapper delete-backward-char :backward)
+  (def-completion-wrapper delete-backward-char-untabify :backward)
+
+  ;; Tests --
+  ;; foobarbiz
+  ;; foobar 
+  ;; fooquux 
+  ;; fooper
 
-;;-----------------------------------------------
-;; End of line chars.
-;;-----------------------------------------------
-(def-completion-wrapper newline :separator)
-(def-completion-wrapper newline-and-indent :separator)
-(def-completion-wrapper comint-send-input :separator)
-(def-completion-wrapper exit-minibuffer :minibuffer-separator)
-(def-completion-wrapper eval-print-last-sexp :separator)
-(def-completion-wrapper eval-last-sexp :separator)
-;;(def-completion-wrapper minibuffer-complete-and-exit :minibuffer)
-
-;;-----------------------------------------------
-;; Cursor movement
-;;-----------------------------------------------
-
-(def-completion-wrapper next-line :under-or-before)
-(def-completion-wrapper previous-line :under-or-before)
-(def-completion-wrapper beginning-of-buffer :under-or-before)
-(def-completion-wrapper end-of-buffer :under-or-before)
-(def-completion-wrapper beginning-of-line :under-or-before)
-(def-completion-wrapper end-of-line :under-or-before)
-(def-completion-wrapper forward-char :under-or-before)
-(def-completion-wrapper forward-word :under-or-before)
-(def-completion-wrapper forward-sexp :under-or-before)
-(def-completion-wrapper backward-char :backward-under)
-(def-completion-wrapper backward-word :backward-under)
-(def-completion-wrapper backward-sexp :backward-under)
-
-(def-completion-wrapper delete-backward-char :backward)
-(def-completion-wrapper delete-backward-char-untabify :backward)
-
-;; Tests --
-;; foobarbiz
-;; foobar 
-;; fooquux 
-;; fooper
+  (cmpl-statistics-block
+   (record-completion-file-loaded))
 
-(cmpl-statistics-block
-  (record-completion-file-loaded))
+  (initialize-completions))
 
 (provide 'completion)