home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / interfaces / Emacs-cl-shell / always-complete.el < prev    next >
Encoding:
Text File  |  1990-10-15  |  3.8 KB  |  111 lines

  1. ;;; always-complete.el: Extensions to completion.el to make
  2. ;;; completions display themselves in the minibuffer as you type.
  3.  
  4. ;;; Code by Alan Ruttenberg, Music Group, MIT Media Laboratory.
  5.  
  6. ;;; To use this file, just put a line (load-file "<this-file>") in
  7. ;;; your .emacs file.  If you don't like to be reminded of
  8. ;;; completions, just load the file completions.el without this file.
  9. ;;; The default completion key (bound in completion.el) is M-return.
  10. ;;; You can also bind another key to the function 'complete, like
  11. ;;; this: (define-key esc-map "c" 'complete)
  12.  
  13. ;; Requires advise.el and completion.el
  14. (require 'advise)
  15. (require 'cl)
  16. (load "completion")
  17.  
  18. ;;; Additional extensions to add the contents of a TAGS file to your
  19. ;;; list of completions.  Very useful when hacking on a source tree!
  20. ;;; Optional arg allows you to specify which tags file to use.
  21. ;;; Otherwise, you are prompted for one.
  22. (defun add-completions-from-tags-table (&optional tags-file-name)
  23.   ;; Written by Jim Salem, inspired by Eero Simoncelli
  24.   "Add completions from the current tags-table-buffer."
  25.   (interactive)
  26.   (visit-tags-table-buffer)        ;this will prompt if no tags-table
  27.   (save-excursion
  28.     (goto-char (point-min))
  29.     (let (string)
  30.       (condition-case e
  31.        (while t
  32.          (search-forward "\177")
  33.          (backward-char 3)
  34.          (and (setq string (symbol-under-point))
  35.           (add-completion-to-tail-if-new string))
  36.          (forward-char 3)
  37.          )
  38.      (search-failed)
  39.      ))))
  40.  
  41. (defvar *old-self-insert-command* (symbol-function 'self-insert-command))
  42.  
  43. (defun maybe-display-next-completion ()
  44.   (when *completep*
  45.     (let ((string (and *completep* (symbol-before-point-for-complete))))
  46.       (if string 
  47.       (progn
  48.         (completion-search-reset string)
  49.         (let ((it (completion-search-next 0)))
  50.           (if (and (consp it) (zerop (or (minibuffer-depth) 0)))
  51.           (message "%s" (car it))
  52.           )))))))
  53.  
  54. ;; patch the old one. This doesn't always work
  55. (defun self-insert-command (howmany)
  56.   (interactive "p")
  57.   (funcall *old-self-insert-command* howmany)
  58.   (maybe-display-next-completion))
  59.  
  60. ;; it doesn't work for most of the characters, so make a new function, and 
  61. ;; globally-bind it to all the alphabetic keys.
  62.  
  63. (defun self-insert-command-1 (number)    
  64.   (interactive "p")
  65.   (funcall *old-self-insert-command* number)
  66.   (maybe-display-next-completion))
  67.  
  68. (defvar all-completing-keys "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ*!@#$%^&*()_-1234567890<>?")
  69. (dotimes (i (length all-completing-keys))
  70.   (global-set-key (format "%c" (aref all-completing-keys i)) 'self-insert-command-1))
  71.  
  72. (advise previous-line :after (maybe-display-next-completion))
  73. (advise next-line :after (maybe-display-next-completion))
  74. (advise cmpl-forward-sexp :after (maybe-display-next-completion))
  75. (advise cmpl-backward-sexp :after (maybe-display-next-completion))
  76. (advise cmpl-forward-char :after (maybe-display-next-completion))
  77. (advise cmpl-backward-char :after (maybe-display-next-completion))
  78.  
  79. (defun forward-word-1 (&optional number)
  80.   (interactive "p")
  81.   (prog1
  82.       (forward-word number)
  83.     (maybe-display-next-completion)))
  84.  
  85. (defun backward-word-1 (&optional number)
  86.   (interactive "p")
  87.   (prog1 
  88.       (backward-word number)
  89.     (maybe-display-next-completion)))
  90.  
  91. (defun backward-char-1 (&optional number)
  92.   (interactive "p")
  93.   (prog1
  94.       (backward-word number)
  95.     (maybe-display-next-completion)))
  96.  
  97. (defun forward-char-1 (&optional number)
  98.   (interactive "p")
  99.   (prog1
  100.       (forward-char number)
  101.     (maybe-display-next-completion)))
  102.  
  103. (defun rebind-function-key-callers (old-function new-function)
  104.   (mapcar '(lambda (key) (global-set-key key new-function))
  105.       (where-is-internal old-function)))
  106.  
  107. (rebind-function-key-callers 'forward-word 'forward-word-1)
  108. (rebind-function-key-callers 'backward-word 'backward-word-1)
  109. (rebind-function-key-callers 'forward-char 'forward-char-1)
  110. (rebind-function-key-callers 'backward-char 'backward-char-1)
  111.