75 |
;; When you load this file, completion will be on. I suggest you use the |
;; When you load this file, completion will be on. I suggest you use the |
76 |
;; compiled version (because it is noticeably faster). |
;; compiled version (because it is noticeably faster). |
77 |
;; |
;; |
78 |
;; M-X completion-mode toggles whether or not new words are added to the |
;; M-x completion-mode toggles whether or not new words are added to the |
79 |
;; database by changing the value of enable-completion. |
;; database by changing the value of enable-completion. |
80 |
;; |
;; |
81 |
;; SAVING/LOADING COMPLETIONS |
;; SAVING/LOADING COMPLETIONS |
350 |
;; "*The period in seconds to wait for emacs to be idle before autosaving |
;; "*The period in seconds to wait for emacs to be idle before autosaving |
351 |
;;the completions. Default is a 1/2 hour.") |
;;the completions. Default is a 1/2 hour.") |
352 |
|
|
353 |
(defconst completion-min-length nil ;; defined below in eval-when |
(defvar completion-min-length 6 |
354 |
"*The minimum length of a stored completion. |
"*The minimum length of a stored completion. |
355 |
DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.") |
DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.") |
356 |
|
|
357 |
(defconst completion-max-length nil ;; defined below in eval-when |
(defvar completion-max-length 200 |
358 |
"*The maximum length of a stored completion. |
"*The maximum length of a stored completion. |
359 |
DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.") |
DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.") |
360 |
|
|
361 |
(defconst completion-prefix-min-length nil ;; defined below in eval-when |
(defvar completion-prefix-min-length 3 |
362 |
"The minimum length of a completion search string. |
"The minimum length of a completion search string. |
363 |
DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.") |
DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.") |
364 |
|
|
|
(defmacro eval-when-compile-load-eval (&rest body) |
|
|
;; eval everything before expanding |
|
|
(mapcar 'eval body) |
|
|
(cons 'progn body)) |
|
|
|
|
|
(defun completion-eval-when () |
|
|
(eval-when-compile-load-eval |
|
|
;; These vars. are defined at both compile and load time. |
|
|
(setq completion-min-length 6) |
|
|
(setq completion-max-length 200) |
|
|
(setq completion-prefix-min-length 3))) |
|
|
|
|
|
(completion-eval-when) |
|
|
|
|
365 |
;;--------------------------------------------------------------------------- |
;;--------------------------------------------------------------------------- |
366 |
;; Internal Variables |
;; Internal Variables |
367 |
;;--------------------------------------------------------------------------- |
;;--------------------------------------------------------------------------- |
383 |
;;--------------------------------------------------------------------------- |
;;--------------------------------------------------------------------------- |
384 |
|
|
385 |
;;----------------------------------------------- |
;;----------------------------------------------- |
|
;; Misc. |
|
|
;;----------------------------------------------- |
|
|
|
|
|
(defun minibuffer-window-selected-p () |
|
|
"True iff the current window is the minibuffer." |
|
|
(window-minibuffer-p (selected-window))) |
|
|
|
|
|
;; This used to be `(eval form)'. Eval FORM at run time now. |
|
|
(defmacro cmpl-read-time-eval (form) |
|
|
form) |
|
|
|
|
|
;;----------------------------------------------- |
|
386 |
;; String case coercion |
;; String case coercion |
387 |
;;----------------------------------------------- |
;;----------------------------------------------- |
388 |
|
|
566 |
(defvar cmpl-saved-point nil) |
(defvar cmpl-saved-point nil) |
567 |
|
|
568 |
(defun symbol-under-point () |
(defun symbol-under-point () |
569 |
"Returns the symbol that the point is currently on. |
"Return the symbol that the point is currently on. |
570 |
But only if it is longer than `completion-min-length'." |
But only if it is longer than `completion-min-length'." |
571 |
(setq cmpl-saved-syntax (syntax-table)) |
(setq cmpl-saved-syntax (syntax-table)) |
572 |
(unwind-protect |
(unwind-protect |
591 |
(setq cmpl-symbol-end (point)) |
(setq cmpl-symbol-end (point)) |
592 |
(goto-char cmpl-saved-point))) |
(goto-char cmpl-saved-point))) |
593 |
;; Return completion if the length is reasonable. |
;; Return completion if the length is reasonable. |
594 |
(if (and (<= (cmpl-read-time-eval completion-min-length) |
(if (and (<= completion-min-length |
595 |
(- cmpl-symbol-end cmpl-symbol-start)) |
(- cmpl-symbol-end cmpl-symbol-start)) |
596 |
(<= (- cmpl-symbol-end cmpl-symbol-start) |
(<= (- cmpl-symbol-end cmpl-symbol-start) |
597 |
(cmpl-read-time-eval completion-max-length))) |
completion-max-length)) |
598 |
(buffer-substring cmpl-symbol-start cmpl-symbol-end))))) |
(buffer-substring cmpl-symbol-start cmpl-symbol-end))))) |
599 |
(set-syntax-table cmpl-saved-syntax))) |
(set-syntax-table cmpl-saved-syntax))) |
600 |
|
|
611 |
;; |
;; |
612 |
|
|
613 |
(defun symbol-before-point () |
(defun symbol-before-point () |
614 |
"Returns a string of the symbol immediately before point. |
"Return a string of the symbol immediately before point. |
615 |
Returns nil if there isn't one longer than `completion-min-length'." |
Returns nil if there isn't one longer than `completion-min-length'." |
616 |
;; This is called when a word separator is typed so it must be FAST ! |
;; This is called when a word separator is typed so it must be FAST ! |
617 |
(setq cmpl-saved-syntax (syntax-table)) |
(setq cmpl-saved-syntax (syntax-table)) |
631 |
(goto-char cmpl-symbol-end))) |
(goto-char cmpl-symbol-end))) |
632 |
;; Return value if long enough. |
;; Return value if long enough. |
633 |
(if (>= cmpl-symbol-end |
(if (>= cmpl-symbol-end |
634 |
(+ cmpl-symbol-start |
(+ cmpl-symbol-start completion-min-length)) |
|
(cmpl-read-time-eval completion-min-length))) |
|
635 |
(buffer-substring cmpl-symbol-start cmpl-symbol-end))) |
(buffer-substring cmpl-symbol-start cmpl-symbol-end))) |
636 |
((= cmpl-preceding-syntax ?w) |
((= cmpl-preceding-syntax ?w) |
637 |
;; chars to ignore at end |
;; chars to ignore at end |
648 |
;; Restore state. |
;; Restore state. |
649 |
(goto-char cmpl-saved-point) |
(goto-char cmpl-saved-point) |
650 |
;; Return completion if the length is reasonable |
;; Return completion if the length is reasonable |
651 |
(if (and (<= (cmpl-read-time-eval completion-min-length) |
(if (and (<= completion-min-length |
652 |
(- cmpl-symbol-end cmpl-symbol-start)) |
(- cmpl-symbol-end cmpl-symbol-start)) |
653 |
(<= (- cmpl-symbol-end cmpl-symbol-start) |
(<= (- cmpl-symbol-end cmpl-symbol-start) |
654 |
(cmpl-read-time-eval completion-max-length))) |
completion-max-length)) |
655 |
(buffer-substring cmpl-symbol-start cmpl-symbol-end))))) |
(buffer-substring cmpl-symbol-start cmpl-symbol-end))))) |
656 |
(set-syntax-table cmpl-saved-syntax))) |
(set-syntax-table cmpl-saved-syntax))) |
657 |
|
|
707 |
(setq cmpl-symbol-start (point)) |
(setq cmpl-symbol-start (point)) |
708 |
(goto-char cmpl-symbol-end))) |
(goto-char cmpl-symbol-end))) |
709 |
;; Return completion if the length is reasonable. |
;; Return completion if the length is reasonable. |
710 |
(if (and (<= (cmpl-read-time-eval |
(if (and (<= completion-prefix-min-length |
|
completion-prefix-min-length) |
|
711 |
(- cmpl-symbol-end cmpl-symbol-start)) |
(- cmpl-symbol-end cmpl-symbol-start)) |
712 |
(<= (- cmpl-symbol-end cmpl-symbol-start) |
(<= (- cmpl-symbol-end cmpl-symbol-start) |
713 |
(cmpl-read-time-eval completion-max-length))) |
completion-max-length)) |
714 |
(buffer-substring cmpl-symbol-start cmpl-symbol-end))))) |
(buffer-substring cmpl-symbol-start cmpl-symbol-end))))) |
715 |
;; Restore syntax table. |
;; Restore syntax table. |
716 |
(set-syntax-table cmpl-saved-syntax))) |
(set-syntax-table cmpl-saved-syntax))) |
805 |
|
|
806 |
|
|
807 |
(defun reset-cdabbrev (abbrev-string &optional initial-completions-tried) |
(defun reset-cdabbrev (abbrev-string &optional initial-completions-tried) |
808 |
"Resets the cdabbrev search to search for abbrev-string. |
"Reset the cdabbrev search to search for ABBREV-STRING. |
809 |
INITIAL-COMPLETIONS-TRIED is a list of downcased strings to ignore |
INITIAL-COMPLETIONS-TRIED is a list of downcased strings to ignore |
810 |
during the search." |
during the search." |
811 |
(setq cdabbrev-abbrev-string abbrev-string |
(setq cdabbrev-abbrev-string abbrev-string |
821 |
|
|
822 |
|
|
823 |
(defun reset-cdabbrev-window (&optional initializep) |
(defun reset-cdabbrev-window (&optional initializep) |
824 |
"Resets the cdabbrev search to search for abbrev-string." |
"Reset the cdabbrev search to search for abbrev-string." |
825 |
;; Set the window |
;; Set the window |
826 |
(cond (initializep |
(cond (initializep |
827 |
(setq cdabbrev-current-window (selected-window))) |
(setq cdabbrev-current-window (selected-window))) |
1009 |
|
|
1010 |
;; CONSTRUCTOR |
;; CONSTRUCTOR |
1011 |
(defun make-completion (string) |
(defun make-completion (string) |
1012 |
"Returns a list of a completion entry." |
"Return a list of a completion entry." |
1013 |
(list (list string 0 nil current-completion-source))) |
(list (list string 0 nil current-completion-source))) |
1014 |
|
|
1015 |
;; Obsolete |
;; Obsolete |
1042 |
;; Constructor |
;; Constructor |
1043 |
|
|
1044 |
(defun make-cmpl-prefix-entry (completion-entry-list) |
(defun make-cmpl-prefix-entry (completion-entry-list) |
1045 |
"Makes a new prefix entry containing only completion-entry." |
"Make a new prefix entry containing only completion-entry." |
1046 |
(cons completion-entry-list completion-entry-list)) |
(cons completion-entry-list completion-entry-list)) |
1047 |
|
|
1048 |
;;----------------------------------------------- |
;;----------------------------------------------- |
1193 |
;; setup the prefix |
;; setup the prefix |
1194 |
(prefix-entry (find-cmpl-prefix-entry |
(prefix-entry (find-cmpl-prefix-entry |
1195 |
(substring cmpl-db-downcase-string 0 |
(substring cmpl-db-downcase-string 0 |
1196 |
(cmpl-read-time-eval |
completion-prefix-min-length)))) |
|
completion-prefix-min-length))))) |
|
1197 |
;; The next two forms should happen as a unit (atomically) but |
;; The next two forms should happen as a unit (atomically) but |
1198 |
;; no fatal errors should result if that is not the case. |
;; no fatal errors should result if that is not the case. |
1199 |
(cond (prefix-entry |
(cond (prefix-entry |
1224 |
;; found |
;; found |
1225 |
(let* ((prefix-entry (find-cmpl-prefix-entry |
(let* ((prefix-entry (find-cmpl-prefix-entry |
1226 |
(substring cmpl-db-downcase-string 0 |
(substring cmpl-db-downcase-string 0 |
1227 |
(cmpl-read-time-eval |
completion-prefix-min-length))) |
|
completion-prefix-min-length)))) |
|
1228 |
(splice-ptr (locate-completion-entry cmpl-db-entry prefix-entry)) |
(splice-ptr (locate-completion-entry cmpl-db-entry prefix-entry)) |
1229 |
(cmpl-ptr (cdr splice-ptr))) |
(cmpl-ptr (cdr splice-ptr))) |
1230 |
;; update entry |
;; update entry |
1247 |
;; setup the prefix |
;; setup the prefix |
1248 |
(prefix-entry (find-cmpl-prefix-entry |
(prefix-entry (find-cmpl-prefix-entry |
1249 |
(substring cmpl-db-downcase-string 0 |
(substring cmpl-db-downcase-string 0 |
1250 |
(cmpl-read-time-eval |
completion-prefix-min-length)))) |
|
completion-prefix-min-length))))) |
|
1251 |
(cond (prefix-entry |
(cond (prefix-entry |
1252 |
;; Splice in at head |
;; Splice in at head |
1253 |
(setcdr entry (cmpl-prefix-entry-head prefix-entry)) |
(setcdr entry (cmpl-prefix-entry-head prefix-entry)) |
1270 |
;; found |
;; found |
1271 |
(let* ((prefix-entry (find-cmpl-prefix-entry |
(let* ((prefix-entry (find-cmpl-prefix-entry |
1272 |
(substring cmpl-db-downcase-string 0 |
(substring cmpl-db-downcase-string 0 |
1273 |
(cmpl-read-time-eval |
completion-prefix-min-length))) |
|
completion-prefix-min-length)))) |
|
1274 |
(splice-ptr (locate-completion-entry cmpl-db-entry prefix-entry))) |
(splice-ptr (locate-completion-entry cmpl-db-entry prefix-entry))) |
1275 |
;; delete symbol reference |
;; delete symbol reference |
1276 |
(set cmpl-db-symbol nil) |
(set cmpl-db-symbol nil) |
1545 |
|
|
1546 |
|
|
1547 |
(defun completion-search-peek (use-cdabbrev) |
(defun completion-search-peek (use-cdabbrev) |
1548 |
"Returns the next completion entry without actually moving the pointers. |
"Return the next completion entry without actually moving the pointers. |
1549 |
Calling this again or calling `completion-search-next' results in the same |
Calling this again or calling `completion-search-next' results in the same |
1550 |
string being returned. Depends on `case-fold-search'. |
string being returned. Depends on `case-fold-search'. |
1551 |
If there are no more entries, try cdabbrev and then return only a string." |
If there are no more entries, try cdabbrev and then return only a string." |
1675 |
;; Get the next completion |
;; Get the next completion |
1676 |
(let* ((print-status-p |
(let* ((print-status-p |
1677 |
(and (>= baud-rate completion-prompt-speed-threshold) |
(and (>= baud-rate completion-prompt-speed-threshold) |
1678 |
(not (minibuffer-window-selected-p)))) |
(not (window-minibuffer-p (selected-window))))) |
1679 |
(insert-point (point)) |
(insert-point (point)) |
1680 |
(entry (completion-search-next cmpl-current-index)) |
(entry (completion-search-next cmpl-current-index)) |
1681 |
string) |
string) |
2234 |
|
|
2235 |
(defun initialize-completions () |
(defun initialize-completions () |
2236 |
"Load the default completions file. |
"Load the default completions file. |
2237 |
Also sets up so that exiting emacs will automatically save the file." |
Also sets up so that exiting Emacs will automatically save the file." |
2238 |
(interactive) |
(interactive) |
2239 |
(cond ((not cmpl-initialized-p) |
(cond ((not cmpl-initialized-p) |
2240 |
(load-completions-from-file))) |
(load-completions-from-file))) |
2499 |
|
|
2500 |
(initialize-completions)) |
(initialize-completions)) |
2501 |
|
|
2502 |
(mapc (lambda (x) |
(mapc (lambda (x) (add-to-list 'debug-ignored-errors x)) |
|
(add-to-list 'debug-ignored-errors x)) |
|
2503 |
'("^To complete, the point must be after a symbol at least [0-9]* character long\\.$" |
'("^To complete, the point must be after a symbol at least [0-9]* character long\\.$" |
2504 |
"^The string \".*\" is too short to be saved as a completion\\.$")) |
"^The string \".*\" is too short to be saved as a completion\\.$")) |
2505 |
|
|