Commit bb310d1e authored by Richard M. Stallman's avatar Richard M. Stallman

(dynamic-completion-mode): New function to enable

the mode.  (Just loading the file now does not change anything.)
parent ebd32d7b
...@@ -28,8 +28,7 @@ ...@@ -28,8 +28,7 @@
;; What to put in .emacs ;; What to put in .emacs
;;----------------------- ;;-----------------------
;; (load "completion") ;; (dynamic-completion-mode)
;; (initialize-completions)
;;--------------------------------------------------------------------------- ;;---------------------------------------------------------------------------
;; Documentation [Slightly out of date] ;; Documentation [Slightly out of date]
...@@ -616,23 +615,6 @@ Used to decide whether to save completions.") ...@@ -616,23 +615,6 @@ Used to decide whether to save completions.")
"This variable holds the current completion syntax table.") "This variable holds the current completion syntax table.")
(make-variable-buffer-local 'cmpl-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 ;; Symbol functions
;;----------------------------------------------- ;;-----------------------------------------------
...@@ -875,11 +857,11 @@ Returns nil if there isn't one longer than `completion-min-length'." ...@@ -875,11 +857,11 @@ Returns nil if there isn't one longer than `completion-min-length'."
;; "The current point position the cdabbrev search is at.") ;; "The current point position the cdabbrev search is at.")
(defvar cdabbrev-current-window nil) (defvar cdabbrev-current-window nil)
;; "The current window we are looking for cdabbrevs in. T if looking in ;; "The current window we are looking for cdabbrevs in.
;; (other-buffer), NIL if no more cdabbrevs.") ;; Return t if looking in (other-buffer), nil if no more cdabbrevs.")
(defvar cdabbrev-wrapped-p nil) (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-abbrev-string "")
(defvar cdabbrev-start-point 0) (defvar cdabbrev-start-point 0)
...@@ -1891,23 +1873,6 @@ Prefix args :: ...@@ -1891,23 +1873,6 @@ Prefix args ::
;; Pretend that we were never here ;; Pretend that we were never here
(setq this-command 'failed-complete) (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
;;--------------------------------------------------------------------------- ;;---------------------------------------------------------------------------
;; Parsing definitions from files into the database ;; Parsing definitions from files into the database
...@@ -1976,8 +1941,6 @@ Prefix args :: ...@@ -1976,8 +1941,6 @@ Prefix args ::
(add-completions-from-buffer) (add-completions-from-buffer)
))) )))
)) ))
(add-hook 'find-file-hooks 'cmpl-find-file-hook)
;;----------------------------------------------- ;;-----------------------------------------------
;; Tags Table Completions ;; Tags Table Completions
...@@ -2470,17 +2433,6 @@ Also sets up so that exiting emacs will automatically save the file." ...@@ -2470,17 +2433,6 @@ Also sets up so that exiting emacs will automatically save the file."
)) ))
(setq cmpl-initialized-p t) (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))))
;;----------------------------------------------- ;;-----------------------------------------------
;; Kill region patch ;; Kill region patch
...@@ -2510,7 +2462,6 @@ Patched to remove the most recent completion." ...@@ -2510,7 +2462,6 @@ Patched to remove the most recent completion."
(t (t
(kill-region beg end)))) (kill-region beg end))))
(global-set-key "\C-w" 'completion-kill-region)
;;----------------------------------------------- ;;-----------------------------------------------
;; Patches to self-insert-command. ;; Patches to self-insert-command.
...@@ -2590,61 +2541,7 @@ TYPE is the type of the wrapper to be added. Can be :before or :under." ...@@ -2590,61 +2541,7 @@ TYPE is the type of the wrapper to be added. Can be :before or :under."
(funcall (or (and (symbolp this-command) (funcall (or (and (symbolp this-command)
(get this-command 'completion-function)) (get this-command 'completion-function))
'use-completion-under-or-before-point))) '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)
;; C mode diffs. ;; C mode diffs.
(defun completion-c-mode-hook () (defun completion-c-mode-hook ()
(def-completion-wrapper electric-c-semi :separator) (def-completion-wrapper electric-c-semi :separator)
...@@ -2663,46 +2560,141 @@ TYPE is the type of the wrapper to be added. Can be :before or :under." ...@@ -2663,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)
(define-key fortran-mode-map "/" 'completion-separator-self-insert-command) (define-key fortran-mode-map "/" 'completion-separator-self-insert-command)
) )
;;; 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
;;----------------------------------------------- (cmpl-statistics-block
;; End of line chars. (record-completion-file-loaded))
;;-----------------------------------------------
(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 (initialize-completions))
(record-completion-file-loaded))
(provide 'completion) (provide 'completion)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment