;;; completion.el --- dynamic word-completion code
-;; Copyright (C) 1990, 1993, 1995, 1997, 2002, 2003, 2004,
-;; 2005 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
;; 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,
;; SAVING/LOADING COMPLETIONS
;; Completions are automatically saved from one session to another
;; (unless save-completions-flag or enable-completion is nil).
-;; Activating this minor-mode calling completion-initialize) causes Emacs
-;; to load a completions database for a saved completions file
+;; Activating this minor-mode (calling completion-initialize) loads
+;; a completions database for a saved completions file
;; (default: ~/.completions). When you exit, Emacs saves a copy of the
-;; completions that you
-;; often use. When you next start, Emacs loads in the saved completion file.
+;; completions that you often use. When you next start, Emacs loads in
+;; the saved completion file.
;;
;; The number of completions saved depends loosely on
;; *saved-completions-decay-factor*. Completions that have never been
(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
(- 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
;; 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)))
(- 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
(- 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
(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.)
(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)
(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)
(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
TYPE is the type of the wrapper to be added. Can be :before or :under."
(put function-name 'completion-function
(cdr (assq type
- '((:separator 'use-completion-before-separator)
- (:before 'use-completion-before-point)
- (:backward-under 'use-completion-backward-under)
- (:backward 'use-completion-backward)
- (:under 'use-completion-under-point)
- (:under-or-before 'use-completion-under-or-before-point)
- (:minibuffer-separator 'use-completion-minibuffer-separator))))))
+ '((:separator . use-completion-before-separator)
+ (:before . use-completion-before-point)
+ (:backward-under . use-completion-backward-under)
+ (:backward . use-completion-backward)
+ (:under . use-completion-under-point)
+ (:under-or-before . use-completion-under-or-before-point)
+ (:minibuffer-separator
+ . use-completion-minibuffer-separator))))))
(defun use-completion-minibuffer-separator ()
(let ((completion-syntax-table completion-standard-syntax-table))
(if dynamic-completion-mode
(add-hook (car x) (cdr x))
(remove-hook (car x) (cdr x))))
-
+
;; "Complete" Key Keybindings. We don't want to use a minor-mode
;; map because these have too high a priority. We could/should
;; probably change the interpretation of minor-mode-map-alist such