*** empty log message ***
[bpt/emacs.git] / lisp / completion.el
index 64bf802..8779eed 100644 (file)
@@ -1,7 +1,7 @@
 ;;; completion.el --- dynamic word-completion code
 
-;; Copyright (C) 1990, 1993, 1995, 1997, 2002, 2003, 2004,
-;;   2005, 2006 Free Software Foundation, Inc.
+;; Copyright (C) 1990, 1993, 1995, 1997, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: abbrev convenience
@@ -12,7 +12,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -301,9 +301,9 @@ See also `save-completions-retention-time'."
   (let ((olddef (convert-standard-filename "~/.completions")))
     (cond
      ((file-readable-p olddef) olddef)
-     ((file-directory-p (convert-standard-filename "~/.emacs.d/"))
+     ((file-directory-p user-emacs-directory)
       (convert-standard-filename
-       (expand-file-name "completions" "~/.emacs.d/")))
+       (expand-file-name "completions" user-emacs-directory)))
      (t olddef)))
   "The filename to save completions to."
   :type 'file
@@ -568,7 +568,8 @@ But only if it is longer than `completion-min-length'."
                      (- cmpl-symbol-end cmpl-symbol-start))
                  (<= (- cmpl-symbol-end cmpl-symbol-start)
                      completion-max-length))
-            (buffer-substring cmpl-symbol-start cmpl-symbol-end))))))
+            (buffer-substring-no-properties
+             cmpl-symbol-start cmpl-symbol-end))))))
 
 ;; tests for symbol-under-point
 ;;  `^' indicates cursor pos. where value is returned
@@ -601,7 +602,8 @@ Returns nil if there isn't one longer than `completion-min-length'."
            ;; Return value if long enough.
            (if (>= cmpl-symbol-end
                    (+ cmpl-symbol-start completion-min-length))
-               (buffer-substring cmpl-symbol-start cmpl-symbol-end)))
+               (buffer-substring-no-properties
+                cmpl-symbol-start cmpl-symbol-end)))
           ((= cmpl-preceding-syntax ?w)
            ;; chars to ignore at end
            (let ((saved-point (point)))
@@ -621,7 +623,8 @@ Returns nil if there isn't one longer than `completion-min-length'."
                           (- cmpl-symbol-end cmpl-symbol-start))
                       (<= (- cmpl-symbol-end cmpl-symbol-start)
                           completion-max-length))
-                 (buffer-substring cmpl-symbol-start cmpl-symbol-end)))))))
+                 (buffer-substring-no-properties
+                  cmpl-symbol-start cmpl-symbol-end)))))))
 
 ;; tests for symbol-before-point
 ;;  `^' indicates cursor pos. where value is returned
@@ -670,7 +673,8 @@ Returns nil if there isn't one longer than `completion-min-length'."
                         (- cmpl-symbol-end cmpl-symbol-start))
                     (<= (- cmpl-symbol-end cmpl-symbol-start)
                         completion-max-length))
-               (buffer-substring cmpl-symbol-start cmpl-symbol-end))))))
+               (buffer-substring-no-properties
+                cmpl-symbol-start cmpl-symbol-end))))))
 
 ;; tests for symbol-before-point-for-complete
 ;;  `^' indicates cursor pos. where value is returned
@@ -1885,7 +1889,7 @@ Prefix args ::
     (save-excursion
       (goto-char (point-min))
       (catch 'finish-add-completions
-       (with-syntax-table completion-c-def-syntax-table
+        (with-syntax-table completion-c-def-syntax-table
           (while t
             ;; we loop here only when scan-sexps fails
             ;; (i.e. unbalance exps.)
@@ -1895,8 +1899,7 @@ Prefix args ::
                   (cond
                    ((= (preceding-char) ?#)
                     ;; preprocessor macro, see if it's one we handle
-                    (setq string (buffer-substring (point) (+ (point) 6)))
-                    (cond ((member string '("define" "ifdef "))
+                    (cond ((looking-at "\\(define\\|ifdef\\)\\>")
                            ;; skip forward over definition symbol
                            ;; and add it to database
                            (and (forward-word 2)
@@ -1944,9 +1947,9 @@ Prefix args ::
                (throw 'finish-add-completions t))
               (error
                ;; Check for failure in scan-sexps
-               (if (or (string-equal (nth 1 e)
-                                     "Containing expression ends prematurely")
-                       (string-equal (nth 1 e) "Unbalanced parentheses"))
+               (if (member (nth 1 e)
+                           '("Containing expression ends prematurely"
+                             "Unbalanced parentheses"))
                    ;; unbalanced paren., keep going
                    ;;(ding)
                    (forward-line 1)
@@ -2228,15 +2231,19 @@ Patched to remove the most recent completion."
 
 (defun completion-separator-self-insert-command (arg)
   (interactive "p")
-  (use-completion-before-separator)
-  (self-insert-command arg))
+  (if (command-remapping 'self-insert-command)
+      (funcall (command-remapping 'self-insert-command) arg)
+    (use-completion-before-separator)
+    (self-insert-command arg)))
 
 (defun completion-separator-self-insert-autofilling (arg)
   (interactive "p")
-  (use-completion-before-separator)
-  (self-insert-command arg)
-  (and auto-fill-function
-       (funcall auto-fill-function)))
+  (if (command-remapping 'self-insert-command)
+      (funcall (command-remapping 'self-insert-command) arg)
+    (use-completion-before-separator)
+    (self-insert-command arg)
+    (and auto-fill-function
+        (funcall auto-fill-function))))
 
 ;;-----------------------------------------------
 ;; Wrapping Macro