]> code.delx.au - gnu-emacs/blobdiff - lisp/completion.el
*** empty log message ***
[gnu-emacs] / lisp / completion.el
index 2f89a68147d0a1f457337488af5e91c4f2ca8329..12df9a52714767d8b3f112be945761070420302e 100644 (file)
@@ -1,6 +1,7 @@
 ;;; completion.el --- dynamic word-completion code
 
-;; Copyright (C) 1990, 1993, 1995, 1997 Free Software Foundation, Inc.
+;; Copyright (C) 1990, 1993, 1995, 1997, 2002, 2003, 2004,
+;;   2005 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: abbrev convenience
@@ -21,8 +22,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -75,7 +76,7 @@
 ;;   When you load this file, completion will be on.  I suggest you use the
 ;; compiled version (because it is noticeably faster).
 ;;
-;;  M-X completion-mode toggles whether or not new words are added to the
+;;  M-x completion-mode toggles whether or not new words are added to the
 ;; database by changing the value of enable-completion.
 ;;
 ;;  SAVING/LOADING COMPLETIONS
@@ -350,32 +351,18 @@ are automatically added to the completion database."
 ;;  "*The period in seconds to wait for emacs to be idle before autosaving
 ;;the completions.  Default is a 1/2 hour.")
 
-(defconst completion-min-length nil ;; defined below in eval-when
+(defvar completion-min-length 6
   "*The minimum length of a stored completion.
 DON'T CHANGE WITHOUT RECOMPILING !  This is used by macros.")
 
-(defconst completion-max-length nil ;; defined below in eval-when
+(defvar completion-max-length 200
   "*The maximum length of a stored completion.
 DON'T CHANGE WITHOUT RECOMPILING !  This is used by macros.")
 
-(defconst completion-prefix-min-length nil ;; defined below in eval-when
+(defvar completion-prefix-min-length 3
   "The minimum length of a completion search string.
 DON'T CHANGE WITHOUT RECOMPILING !  This is used by macros.")
 
-(defmacro eval-when-compile-load-eval (&rest body)
-  ;; eval everything before expanding
-  (mapcar 'eval body)
-  (cons 'progn body))
-
-(defun completion-eval-when ()
-  (eval-when-compile-load-eval
-   ;; These vars. are defined at both compile and load time.
-   (setq completion-min-length 6)
-   (setq completion-max-length 200)
-   (setq completion-prefix-min-length 3)))
-
-(completion-eval-when)
-
 ;;---------------------------------------------------------------------------
 ;; Internal Variables
 ;;---------------------------------------------------------------------------
@@ -396,18 +383,6 @@ Used to decide whether to save completions.")
 ;; Low level tools
 ;;---------------------------------------------------------------------------
 
-;;-----------------------------------------------
-;; Misc.
-;;-----------------------------------------------
-
-(defun minibuffer-window-selected-p ()
-  "True iff the current window is the minibuffer."
-  (window-minibuffer-p (selected-window)))
-
-;; This used to be `(eval form)'.  Eval FORM at run time now.
-(defmacro cmpl-read-time-eval (form)
-  form)
-
 ;;-----------------------------------------------
 ;; String case coercion
 ;;-----------------------------------------------
@@ -592,7 +567,7 @@ Used to decide whether to save completions.")
 (defvar cmpl-saved-point nil)
 
 (defun symbol-under-point ()
-  "Returns the symbol that the point is currently on.
+  "Return the symbol that the point is currently on.
 But only if it is longer than `completion-min-length'."
   (setq cmpl-saved-syntax (syntax-table))
   (unwind-protect
@@ -617,10 +592,10 @@ But only if it is longer than `completion-min-length'."
                  (setq cmpl-symbol-end (point))
                  (goto-char cmpl-saved-point)))
           ;; Return completion if the length is reasonable.
-          (if (and (<= (cmpl-read-time-eval completion-min-length)
+          (if (and (<= completion-min-length
                        (- cmpl-symbol-end cmpl-symbol-start))
                    (<= (- cmpl-symbol-end cmpl-symbol-start)
-                       (cmpl-read-time-eval completion-max-length)))
+                       completion-max-length))
               (buffer-substring cmpl-symbol-start cmpl-symbol-end)))))
     (set-syntax-table cmpl-saved-syntax)))
 
@@ -637,7 +612,7 @@ But only if it is longer than `completion-min-length'."
 ;;
 
 (defun symbol-before-point ()
-  "Returns a string of the symbol immediately before point.
+  "Return a string of the symbol immediately before point.
 Returns nil if there isn't one longer than `completion-min-length'."
   ;; This is called when a word separator is typed so it must be FAST !
   (setq cmpl-saved-syntax (syntax-table))
@@ -657,8 +632,7 @@ Returns nil if there isn't one longer than `completion-min-length'."
                      (goto-char cmpl-symbol-end)))
               ;; Return value if long enough.
               (if (>= cmpl-symbol-end
-                      (+ cmpl-symbol-start
-                         (cmpl-read-time-eval completion-min-length)))
+                      (+ cmpl-symbol-start completion-min-length))
                   (buffer-substring cmpl-symbol-start cmpl-symbol-end)))
              ((= cmpl-preceding-syntax ?w)
               ;; chars to ignore at end
@@ -675,10 +649,10 @@ Returns nil if there isn't one longer than `completion-min-length'."
               ;; Restore state.
               (goto-char cmpl-saved-point)
               ;; Return completion if the length is reasonable
-              (if (and (<= (cmpl-read-time-eval completion-min-length)
+              (if (and (<= completion-min-length
                            (- cmpl-symbol-end cmpl-symbol-start))
                        (<= (- cmpl-symbol-end cmpl-symbol-start)
-                           (cmpl-read-time-eval completion-max-length)))
+                           completion-max-length))
                   (buffer-substring cmpl-symbol-start cmpl-symbol-end)))))
     (set-syntax-table cmpl-saved-syntax)))
 
@@ -734,11 +708,10 @@ Returns nil if there isn't one longer than `completion-min-length'."
                      (setq cmpl-symbol-start (point))
                      (goto-char cmpl-symbol-end)))
               ;; Return completion if the length is reasonable.
-              (if (and (<= (cmpl-read-time-eval
-                            completion-prefix-min-length)
+              (if (and (<= completion-prefix-min-length
                            (- cmpl-symbol-end cmpl-symbol-start))
                        (<= (- cmpl-symbol-end cmpl-symbol-start)
-                           (cmpl-read-time-eval completion-max-length)))
+                           completion-max-length))
                   (buffer-substring cmpl-symbol-start cmpl-symbol-end)))))
     ;; Restore syntax table.
     (set-syntax-table cmpl-saved-syntax)))
@@ -833,7 +806,7 @@ Returns nil if there isn't one longer than `completion-min-length'."
 
 
 (defun reset-cdabbrev (abbrev-string &optional initial-completions-tried)
-  "Resets the cdabbrev search to search for abbrev-string.
+  "Reset the cdabbrev search to search for ABBREV-STRING.
 INITIAL-COMPLETIONS-TRIED is a list of downcased strings to ignore
 during the search."
   (setq cdabbrev-abbrev-string abbrev-string
@@ -849,7 +822,7 @@ during the search."
 
 
 (defun reset-cdabbrev-window (&optional initializep)
-  "Resets the cdabbrev search to search for abbrev-string."
+  "Reset the cdabbrev search to search for abbrev-string."
   ;; Set the window
   (cond (initializep
         (setq cdabbrev-current-window (selected-window)))
@@ -1037,7 +1010,7 @@ Each symbol is bound to a single completion entry.")
 
 ;; CONSTRUCTOR
 (defun make-completion (string)
-  "Returns a list of a completion entry."
+  "Return a list of a completion entry."
   (list (list string 0 nil current-completion-source)))
 
 ;; Obsolete
@@ -1070,7 +1043,7 @@ Each symbol is bound to a single completion entry.")
 ;; Constructor
 
 (defun make-cmpl-prefix-entry (completion-entry-list)
-  "Makes a new prefix entry containing only completion-entry."
+  "Make a new prefix entry containing only completion-entry."
   (cons completion-entry-list completion-entry-list))
 
 ;;-----------------------------------------------
@@ -1221,8 +1194,7 @@ Returns the completion entry."
            ;; setup the prefix
            (prefix-entry (find-cmpl-prefix-entry
                            (substring cmpl-db-downcase-string 0
-                                      (cmpl-read-time-eval
-                                       completion-prefix-min-length)))))
+                                      completion-prefix-min-length))))
        ;; The next two forms should happen as a unit (atomically) but
        ;; no fatal errors should result if that is not the case.
        (cond (prefix-entry
@@ -1253,8 +1225,7 @@ Returns the completion entry."
       ;; found
       (let* ((prefix-entry (find-cmpl-prefix-entry
                             (substring cmpl-db-downcase-string 0
-                                       (cmpl-read-time-eval
-                                        completion-prefix-min-length))))
+                                       completion-prefix-min-length)))
             (splice-ptr (locate-completion-entry cmpl-db-entry prefix-entry))
             (cmpl-ptr (cdr splice-ptr)))
        ;; update entry
@@ -1277,8 +1248,7 @@ Returns the completion entry."
          ;; setup the prefix
          (prefix-entry (find-cmpl-prefix-entry
                          (substring cmpl-db-downcase-string 0
-                                    (cmpl-read-time-eval
-                                     completion-prefix-min-length)))))
+                                    completion-prefix-min-length))))
       (cond (prefix-entry
             ;; Splice in at head
             (setcdr entry (cmpl-prefix-entry-head prefix-entry))
@@ -1301,8 +1271,7 @@ String must be longer than `completion-prefix-min-length'."
       ;; found
       (let* ((prefix-entry (find-cmpl-prefix-entry
                             (substring cmpl-db-downcase-string 0
-                                       (cmpl-read-time-eval
-                                        completion-prefix-min-length))))
+                                       completion-prefix-min-length)))
             (splice-ptr (locate-completion-entry cmpl-db-entry prefix-entry)))
         ;; delete symbol reference
         (set cmpl-db-symbol nil)
@@ -1374,7 +1343,7 @@ String must be longer than `completion-prefix-min-length'."
   (let* ((default (symbol-under-or-before-point))
         (new-prompt
          (if default
-             (format "%s: (default: %s) " prompt default)
+             (format "%s (default %s): " prompt default)
              (format "%s: " prompt)))
         (read (completing-read new-prompt cmpl-obarray)))
     (if (zerop (length read)) (setq read (or default "")))
@@ -1577,7 +1546,7 @@ If there are no more entries, try cdabbrev and returns only a string."
 
 
 (defun completion-search-peek (use-cdabbrev)
-  "Returns the next completion entry without actually moving the pointers.
+  "Return the next completion entry without actually moving the pointers.
 Calling this again or calling `completion-search-next' results in the same
 string being returned.  Depends on `case-fold-search'.
 If there are no more entries, try cdabbrev and then return only a string."
@@ -1707,7 +1676,7 @@ Prefix args ::
   ;; Get the next completion
   (let* ((print-status-p
          (and (>= baud-rate completion-prompt-speed-threshold)
-              (not (minibuffer-window-selected-p))))
+              (not (window-minibuffer-p (selected-window)))))
         (insert-point (point))
         (entry (completion-search-next cmpl-current-index))
         string)
@@ -2266,7 +2235,7 @@ If file is not specified, then use `save-completions-file-name'."
 
 (defun initialize-completions ()
   "Load the default completions file.
-Also sets up so that exiting emacs will automatically save the file."
+Also sets up so that exiting Emacs will automatically save the file."
   (interactive)
   (cond ((not cmpl-initialized-p)
         (load-completions-from-file)))
@@ -2283,7 +2252,7 @@ The command \\[yank] can retrieve it from there.
 /(If you want to kill and then yank immediately, use \\[copy-region-as-kill].)
 
 This is the primitive for programs to kill text (as opposed to deleting it).
-Supply two arguments, character numbers indicating the stretch of text
+Supply two arguments, character positions indicating the stretch of text
  to be killed.
 Any command that calls this function is a \"kill command\".
 If the previous command was also a kill command,
@@ -2379,6 +2348,9 @@ TYPE is the type of the wrapper to be added.  Can be :before or :under."
               'use-completion-under-or-before-point)))
 \f
 ;; C mode diffs.
+
+(defvar c-mode-map)
+
 (defun completion-c-mode-hook ()
   (def-completion-wrapper electric-c-semi :separator)
   (define-key c-mode-map "+" 'completion-separator-self-insert-command)
@@ -2390,6 +2362,9 @@ TYPE is the type of the wrapper to be added.  Can be :before or :under."
   (add-hook 'c-mode-hook 'completion-c-mode-hook))
 
 ;; FORTRAN mode diffs. (these are defined when fortran is called)
+
+(defvar fortran-mode-map)
+
 (defun completion-setup-fortran-mode ()
   (define-key fortran-mode-map "+" 'completion-separator-self-insert-command)
   (define-key fortran-mode-map "-" 'completion-separator-self-insert-command)
@@ -2531,11 +2506,11 @@ TYPE is the type of the wrapper to be added.  Can be :before or :under."
 
   (initialize-completions))
 
-(mapc (lambda (x)
-       (add-to-list 'debug-ignored-errors x))
+(mapc (lambda (x) (add-to-list 'debug-ignored-errors x))
       '("^To complete, the point must be after a symbol at least [0-9]* character long\\.$"
        "^The string \".*\" is too short to be saved as a completion\\.$"))
 
 (provide 'completion)
 
+;;; arch-tag: 6990dafe-4abd-4a1f-8c42-ffb25e120f5e
 ;;; completion.el ends here