+(defconst completion-lisp-syntax-table
+ (let ((table (copy-syntax-table completion-standard-syntax-table))
+ (symbol-chars '(?! ?& ?? ?= ?^)))
+ (dolist (char symbol-chars)
+ (modify-syntax-entry char "_" table))
+ table))
+
+(defun completion-lisp-mode-hook ()
+ (setq completion-syntax-table completion-lisp-syntax-table)
+ ;; Lisp Mode diffs
+ (local-set-key "!" 'self-insert-command)
+ (local-set-key "&" 'self-insert-command)
+ (local-set-key "%" 'self-insert-command)
+ (local-set-key "?" 'self-insert-command)
+ (local-set-key "=" 'self-insert-command)
+ (local-set-key "^" 'self-insert-command))
+
+;; C mode diffs.
+
+(defconst completion-c-syntax-table
+ (let ((table (copy-syntax-table completion-standard-syntax-table))
+ (separator-chars '(?+ ?* ?/ ?: ?%)))
+ (dolist (char separator-chars)
+ (modify-syntax-entry char " " table))
+ table))
+
+(completion-def-wrapper 'electric-c-semi :separator)
+(defun completion-c-mode-hook ()
+ (setq completion-syntax-table completion-c-syntax-table)
+ (local-set-key "+" 'completion-separator-self-insert-command)
+ (local-set-key "*" 'completion-separator-self-insert-command)
+ (local-set-key "/" 'completion-separator-self-insert-command))
+
+;; FORTRAN mode diffs. (these are defined when fortran is called)
+
+(defconst completion-fortran-syntax-table
+ (let ((table (copy-syntax-table completion-standard-syntax-table))
+ (separator-chars '(?+ ?- ?* ?/ ?:)))
+ (dolist (char separator-chars)
+ (modify-syntax-entry char " " table))
+ table))
+
+(defun completion-setup-fortran-mode ()
+ (setq completion-syntax-table completion-fortran-syntax-table)
+ (local-set-key "+" 'completion-separator-self-insert-command)
+ (local-set-key "-" 'completion-separator-self-insert-command)
+ (local-set-key "*" 'completion-separator-self-insert-command)
+ (local-set-key "/" 'completion-separator-self-insert-command))
+\f
+;; Enable completion mode.
+
+(defvar fortran-mode-hook)
+
+(defvar completion-saved-bindings nil)
+
+;;;###autoload
+(define-minor-mode dynamic-completion-mode
+ "Enable dynamic word-completion."
+ :global t
+ ;; This is always good, not specific to dynamic-completion-mode.
+ (define-key function-key-map [C-return] [?\C-\r])
+
+ (dolist (x '((find-file-hook . completion-find-file-hook)
+ (pre-command-hook . completion-before-command)
+ ;; Save completions when killing Emacs.
+ (kill-emacs-hook . kill-emacs-save-completions)
+
+ ;; Install the appropriate mode tables.
+ (lisp-mode-hook . completion-lisp-mode-hook)
+ (c-mode-hook . completion-c-mode-hook)
+ (fortran-mode-hook . completion-setup-fortran-mode)))
+ (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
+ ;; that a map has lower precedence if the symbol is not buffer-local.
+ (while completion-saved-bindings
+ (let ((binding (pop completion-saved-bindings)))
+ (global-set-key (car binding) (cdr binding))))
+ (when dynamic-completion-mode
+ (dolist (binding
+ '(("\M-\r" . complete)
+ ([?\C-\r] . complete)
+
+ ;; Tests -
+ ;; (add-completion "cumberland")
+ ;; (add-completion "cumberbund")
+ ;; cum
+ ;; Cumber
+ ;; cumbering
+ ;; cumb
+
+ ;; Patches to standard keymaps insert completions
+ ([remap kill-region] . completion-kill-region)
+
+ ;; 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.
+ (" " . completion-separator-self-insert-autofilling)
+ ("!" . completion-separator-self-insert-command)
+ ("%" . completion-separator-self-insert-command)
+ ("^" . completion-separator-self-insert-command)
+ ("&" . completion-separator-self-insert-command)
+ ("(" . completion-separator-self-insert-command)
+ (")" . completion-separator-self-insert-command)
+ ("=" . completion-separator-self-insert-command)
+ ("`" . completion-separator-self-insert-command)
+ ("|" . completion-separator-self-insert-command)
+ ("{" . completion-separator-self-insert-command)
+ ("}" . completion-separator-self-insert-command)
+ ("[" . completion-separator-self-insert-command)
+ ("]" . completion-separator-self-insert-command)
+ (";" . completion-separator-self-insert-command)
+ ("\"". completion-separator-self-insert-command)
+ ("'" . completion-separator-self-insert-command)
+ ("#" . completion-separator-self-insert-command)
+ ("," . completion-separator-self-insert-command)
+ ("?" . 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)
+ ("." . completion-separator-self-insert-command)
+ (":" . completion-separator-self-insert-command)))
+ (push (cons (car binding) (lookup-key global-map (car binding)))
+ completion-saved-bindings)
+ (global-set-key (car binding) (cdr binding)))
+
+ ;; Tests --
+ ;; foobarbiz
+ ;; foobar
+ ;; fooquux
+ ;; fooper
+
+ (cmpl-statistics-block
+ (record-completion-file-loaded))
+
+ (completion-initialize)))
+
+;;-----------------------------------------------
+;; End of line chars.
+;;-----------------------------------------------
+(completion-def-wrapper 'newline :separator)
+(completion-def-wrapper 'newline-and-indent :separator)
+(completion-def-wrapper 'comint-send-input :separator)
+(completion-def-wrapper 'exit-minibuffer :minibuffer-separator)
+(completion-def-wrapper 'eval-print-last-sexp :separator)
+(completion-def-wrapper 'eval-last-sexp :separator)
+;;(completion-def-wrapper 'minibuffer-complete-and-exit :minibuffer)
+
+;;-----------------------------------------------
+;; Cursor movement
+;;-----------------------------------------------
+
+(completion-def-wrapper 'next-line :under-or-before)
+(completion-def-wrapper 'previous-line :under-or-before)
+(completion-def-wrapper 'beginning-of-buffer :under-or-before)
+(completion-def-wrapper 'end-of-buffer :under-or-before)
+(completion-def-wrapper 'beginning-of-line :under-or-before)
+(completion-def-wrapper 'end-of-line :under-or-before)
+(completion-def-wrapper 'forward-char :under-or-before)
+(completion-def-wrapper 'forward-word :under-or-before)
+(completion-def-wrapper 'forward-sexp :under-or-before)
+(completion-def-wrapper 'backward-char :backward-under)
+(completion-def-wrapper 'backward-word :backward-under)
+(completion-def-wrapper 'backward-sexp :backward-under)
+
+(completion-def-wrapper 'delete-backward-char :backward)
+(completion-def-wrapper 'delete-backward-char-untabify :backward)
+
+;; Old names, non-namespace-clean.
+(defvaralias 'cmpl-syntax-table 'completion-syntax-table)
+(defalias 'initialize-completions 'completion-initialize)
+
+(dolist (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\\.$"))
+ (add-to-list 'debug-ignored-errors x))
+
+(provide 'completion)
+
+;; arch-tag: 6990dafe-4abd-4a1f-8c42-ffb25e120f5e