diff options
| author | Stefan Monnier | 2003-02-05 19:09:34 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2003-02-05 19:09:34 +0000 |
| commit | 7975cb9fe01ca330b04c3c524db4d41266999d9d (patch) | |
| tree | 418c3eb40dea2876eb23d705a974ebdae17a53d5 | |
| parent | 821b278f805e35518b7a5ce9769cb567b94ef714 (diff) | |
| download | emacs-7975cb9fe01ca330b04c3c524db4d41266999d9d.tar.gz emacs-7975cb9fe01ca330b04c3c524db4d41266999d9d.zip | |
(eval-when-compile-load-eval, completion-eval-when)
(cmpl-read-time-eval, minibuffer-window-selected-p): Remove.
(completion-min-length, completion-max-length)
(completion-prefix-min-length): Don't hard-code the default value
when byte-compiling.
(complete): Inline minibuffer-window-selected-p.
| -rw-r--r-- | lisp/completion.el | 83 |
1 files changed, 25 insertions, 58 deletions
diff --git a/lisp/completion.el b/lisp/completion.el index 2f89a68147d..6f7eb569f71 100644 --- a/lisp/completion.el +++ b/lisp/completion.el | |||
| @@ -75,7 +75,7 @@ | |||
| 75 | ;; When you load this file, completion will be on. I suggest you use the | 75 | ;; When you load this file, completion will be on. I suggest you use the |
| 76 | ;; compiled version (because it is noticeably faster). | 76 | ;; compiled version (because it is noticeably faster). |
| 77 | ;; | 77 | ;; |
| 78 | ;; M-X completion-mode toggles whether or not new words are added to the | 78 | ;; M-x completion-mode toggles whether or not new words are added to the |
| 79 | ;; database by changing the value of enable-completion. | 79 | ;; database by changing the value of enable-completion. |
| 80 | ;; | 80 | ;; |
| 81 | ;; SAVING/LOADING COMPLETIONS | 81 | ;; SAVING/LOADING COMPLETIONS |
| @@ -350,32 +350,18 @@ are automatically added to the completion database." | |||
| 350 | ;; "*The period in seconds to wait for emacs to be idle before autosaving | 350 | ;; "*The period in seconds to wait for emacs to be idle before autosaving |
| 351 | ;;the completions. Default is a 1/2 hour.") | 351 | ;;the completions. Default is a 1/2 hour.") |
| 352 | 352 | ||
| 353 | (defconst completion-min-length nil ;; defined below in eval-when | 353 | (defvar completion-min-length 6 |
| 354 | "*The minimum length of a stored completion. | 354 | "*The minimum length of a stored completion. |
| 355 | DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.") | 355 | DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.") |
| 356 | 356 | ||
| 357 | (defconst completion-max-length nil ;; defined below in eval-when | 357 | (defvar completion-max-length 200 |
| 358 | "*The maximum length of a stored completion. | 358 | "*The maximum length of a stored completion. |
| 359 | DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.") | 359 | DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.") |
| 360 | 360 | ||
| 361 | (defconst completion-prefix-min-length nil ;; defined below in eval-when | 361 | (defvar completion-prefix-min-length 3 |
| 362 | "The minimum length of a completion search string. | 362 | "The minimum length of a completion search string. |
| 363 | DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.") | 363 | DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.") |
| 364 | 364 | ||
| 365 | (defmacro eval-when-compile-load-eval (&rest body) | ||
| 366 | ;; eval everything before expanding | ||
| 367 | (mapcar 'eval body) | ||
| 368 | (cons 'progn body)) | ||
| 369 | |||
| 370 | (defun completion-eval-when () | ||
| 371 | (eval-when-compile-load-eval | ||
| 372 | ;; These vars. are defined at both compile and load time. | ||
| 373 | (setq completion-min-length 6) | ||
| 374 | (setq completion-max-length 200) | ||
| 375 | (setq completion-prefix-min-length 3))) | ||
| 376 | |||
| 377 | (completion-eval-when) | ||
| 378 | |||
| 379 | ;;--------------------------------------------------------------------------- | 365 | ;;--------------------------------------------------------------------------- |
| 380 | ;; Internal Variables | 366 | ;; Internal Variables |
| 381 | ;;--------------------------------------------------------------------------- | 367 | ;;--------------------------------------------------------------------------- |
| @@ -397,18 +383,6 @@ Used to decide whether to save completions.") | |||
| 397 | ;;--------------------------------------------------------------------------- | 383 | ;;--------------------------------------------------------------------------- |
| 398 | 384 | ||
| 399 | ;;----------------------------------------------- | 385 | ;;----------------------------------------------- |
| 400 | ;; Misc. | ||
| 401 | ;;----------------------------------------------- | ||
| 402 | |||
| 403 | (defun minibuffer-window-selected-p () | ||
| 404 | "True iff the current window is the minibuffer." | ||
| 405 | (window-minibuffer-p (selected-window))) | ||
| 406 | |||
| 407 | ;; This used to be `(eval form)'. Eval FORM at run time now. | ||
| 408 | (defmacro cmpl-read-time-eval (form) | ||
| 409 | form) | ||
| 410 | |||
| 411 | ;;----------------------------------------------- | ||
| 412 | ;; String case coercion | 386 | ;; String case coercion |
| 413 | ;;----------------------------------------------- | 387 | ;;----------------------------------------------- |
| 414 | 388 | ||
| @@ -592,7 +566,7 @@ Used to decide whether to save completions.") | |||
| 592 | (defvar cmpl-saved-point nil) | 566 | (defvar cmpl-saved-point nil) |
| 593 | 567 | ||
| 594 | (defun symbol-under-point () | 568 | (defun symbol-under-point () |
| 595 | "Returns the symbol that the point is currently on. | 569 | "Return the symbol that the point is currently on. |
| 596 | But only if it is longer than `completion-min-length'." | 570 | But only if it is longer than `completion-min-length'." |
| 597 | (setq cmpl-saved-syntax (syntax-table)) | 571 | (setq cmpl-saved-syntax (syntax-table)) |
| 598 | (unwind-protect | 572 | (unwind-protect |
| @@ -617,10 +591,10 @@ But only if it is longer than `completion-min-length'." | |||
| 617 | (setq cmpl-symbol-end (point)) | 591 | (setq cmpl-symbol-end (point)) |
| 618 | (goto-char cmpl-saved-point))) | 592 | (goto-char cmpl-saved-point))) |
| 619 | ;; Return completion if the length is reasonable. | 593 | ;; Return completion if the length is reasonable. |
| 620 | (if (and (<= (cmpl-read-time-eval completion-min-length) | 594 | (if (and (<= completion-min-length |
| 621 | (- cmpl-symbol-end cmpl-symbol-start)) | 595 | (- cmpl-symbol-end cmpl-symbol-start)) |
| 622 | (<= (- cmpl-symbol-end cmpl-symbol-start) | 596 | (<= (- cmpl-symbol-end cmpl-symbol-start) |
| 623 | (cmpl-read-time-eval completion-max-length))) | 597 | completion-max-length)) |
| 624 | (buffer-substring cmpl-symbol-start cmpl-symbol-end))))) | 598 | (buffer-substring cmpl-symbol-start cmpl-symbol-end))))) |
| 625 | (set-syntax-table cmpl-saved-syntax))) | 599 | (set-syntax-table cmpl-saved-syntax))) |
| 626 | 600 | ||
| @@ -637,7 +611,7 @@ But only if it is longer than `completion-min-length'." | |||
| 637 | ;; | 611 | ;; |
| 638 | 612 | ||
| 639 | (defun symbol-before-point () | 613 | (defun symbol-before-point () |
| 640 | "Returns a string of the symbol immediately before point. | 614 | "Return a string of the symbol immediately before point. |
| 641 | Returns nil if there isn't one longer than `completion-min-length'." | 615 | Returns nil if there isn't one longer than `completion-min-length'." |
| 642 | ;; This is called when a word separator is typed so it must be FAST ! | 616 | ;; This is called when a word separator is typed so it must be FAST ! |
| 643 | (setq cmpl-saved-syntax (syntax-table)) | 617 | (setq cmpl-saved-syntax (syntax-table)) |
| @@ -657,8 +631,7 @@ Returns nil if there isn't one longer than `completion-min-length'." | |||
| 657 | (goto-char cmpl-symbol-end))) | 631 | (goto-char cmpl-symbol-end))) |
| 658 | ;; Return value if long enough. | 632 | ;; Return value if long enough. |
| 659 | (if (>= cmpl-symbol-end | 633 | (if (>= cmpl-symbol-end |
| 660 | (+ cmpl-symbol-start | 634 | (+ cmpl-symbol-start completion-min-length)) |
| 661 | (cmpl-read-time-eval completion-min-length))) | ||
| 662 | (buffer-substring cmpl-symbol-start cmpl-symbol-end))) | 635 | (buffer-substring cmpl-symbol-start cmpl-symbol-end))) |
| 663 | ((= cmpl-preceding-syntax ?w) | 636 | ((= cmpl-preceding-syntax ?w) |
| 664 | ;; chars to ignore at end | 637 | ;; chars to ignore at end |
| @@ -675,10 +648,10 @@ Returns nil if there isn't one longer than `completion-min-length'." | |||
| 675 | ;; Restore state. | 648 | ;; Restore state. |
| 676 | (goto-char cmpl-saved-point) | 649 | (goto-char cmpl-saved-point) |
| 677 | ;; Return completion if the length is reasonable | 650 | ;; Return completion if the length is reasonable |
| 678 | (if (and (<= (cmpl-read-time-eval completion-min-length) | 651 | (if (and (<= completion-min-length |
| 679 | (- cmpl-symbol-end cmpl-symbol-start)) | 652 | (- cmpl-symbol-end cmpl-symbol-start)) |
| 680 | (<= (- cmpl-symbol-end cmpl-symbol-start) | 653 | (<= (- cmpl-symbol-end cmpl-symbol-start) |
| 681 | (cmpl-read-time-eval completion-max-length))) | 654 | completion-max-length)) |
| 682 | (buffer-substring cmpl-symbol-start cmpl-symbol-end))))) | 655 | (buffer-substring cmpl-symbol-start cmpl-symbol-end))))) |
| 683 | (set-syntax-table cmpl-saved-syntax))) | 656 | (set-syntax-table cmpl-saved-syntax))) |
| 684 | 657 | ||
| @@ -734,11 +707,10 @@ Returns nil if there isn't one longer than `completion-min-length'." | |||
| 734 | (setq cmpl-symbol-start (point)) | 707 | (setq cmpl-symbol-start (point)) |
| 735 | (goto-char cmpl-symbol-end))) | 708 | (goto-char cmpl-symbol-end))) |
| 736 | ;; Return completion if the length is reasonable. | 709 | ;; Return completion if the length is reasonable. |
| 737 | (if (and (<= (cmpl-read-time-eval | 710 | (if (and (<= completion-prefix-min-length |
| 738 | completion-prefix-min-length) | ||
| 739 | (- cmpl-symbol-end cmpl-symbol-start)) | 711 | (- cmpl-symbol-end cmpl-symbol-start)) |
| 740 | (<= (- cmpl-symbol-end cmpl-symbol-start) | 712 | (<= (- cmpl-symbol-end cmpl-symbol-start) |
| 741 | (cmpl-read-time-eval completion-max-length))) | 713 | completion-max-length)) |
| 742 | (buffer-substring cmpl-symbol-start cmpl-symbol-end))))) | 714 | (buffer-substring cmpl-symbol-start cmpl-symbol-end))))) |
| 743 | ;; Restore syntax table. | 715 | ;; Restore syntax table. |
| 744 | (set-syntax-table cmpl-saved-syntax))) | 716 | (set-syntax-table cmpl-saved-syntax))) |
| @@ -833,7 +805,7 @@ Returns nil if there isn't one longer than `completion-min-length'." | |||
| 833 | 805 | ||
| 834 | 806 | ||
| 835 | (defun reset-cdabbrev (abbrev-string &optional initial-completions-tried) | 807 | (defun reset-cdabbrev (abbrev-string &optional initial-completions-tried) |
| 836 | "Resets the cdabbrev search to search for abbrev-string. | 808 | "Reset the cdabbrev search to search for ABBREV-STRING. |
| 837 | INITIAL-COMPLETIONS-TRIED is a list of downcased strings to ignore | 809 | INITIAL-COMPLETIONS-TRIED is a list of downcased strings to ignore |
| 838 | during the search." | 810 | during the search." |
| 839 | (setq cdabbrev-abbrev-string abbrev-string | 811 | (setq cdabbrev-abbrev-string abbrev-string |
| @@ -849,7 +821,7 @@ during the search." | |||
| 849 | 821 | ||
| 850 | 822 | ||
| 851 | (defun reset-cdabbrev-window (&optional initializep) | 823 | (defun reset-cdabbrev-window (&optional initializep) |
| 852 | "Resets the cdabbrev search to search for abbrev-string." | 824 | "Reset the cdabbrev search to search for abbrev-string." |
| 853 | ;; Set the window | 825 | ;; Set the window |
| 854 | (cond (initializep | 826 | (cond (initializep |
| 855 | (setq cdabbrev-current-window (selected-window))) | 827 | (setq cdabbrev-current-window (selected-window))) |
| @@ -1037,7 +1009,7 @@ Each symbol is bound to a single completion entry.") | |||
| 1037 | 1009 | ||
| 1038 | ;; CONSTRUCTOR | 1010 | ;; CONSTRUCTOR |
| 1039 | (defun make-completion (string) | 1011 | (defun make-completion (string) |
| 1040 | "Returns a list of a completion entry." | 1012 | "Return a list of a completion entry." |
| 1041 | (list (list string 0 nil current-completion-source))) | 1013 | (list (list string 0 nil current-completion-source))) |
| 1042 | 1014 | ||
| 1043 | ;; Obsolete | 1015 | ;; Obsolete |
| @@ -1070,7 +1042,7 @@ Each symbol is bound to a single completion entry.") | |||
| 1070 | ;; Constructor | 1042 | ;; Constructor |
| 1071 | 1043 | ||
| 1072 | (defun make-cmpl-prefix-entry (completion-entry-list) | 1044 | (defun make-cmpl-prefix-entry (completion-entry-list) |
| 1073 | "Makes a new prefix entry containing only completion-entry." | 1045 | "Make a new prefix entry containing only completion-entry." |
| 1074 | (cons completion-entry-list completion-entry-list)) | 1046 | (cons completion-entry-list completion-entry-list)) |
| 1075 | 1047 | ||
| 1076 | ;;----------------------------------------------- | 1048 | ;;----------------------------------------------- |
| @@ -1221,8 +1193,7 @@ Returns the completion entry." | |||
| 1221 | ;; setup the prefix | 1193 | ;; setup the prefix |
| 1222 | (prefix-entry (find-cmpl-prefix-entry | 1194 | (prefix-entry (find-cmpl-prefix-entry |
| 1223 | (substring cmpl-db-downcase-string 0 | 1195 | (substring cmpl-db-downcase-string 0 |
| 1224 | (cmpl-read-time-eval | 1196 | completion-prefix-min-length)))) |
| 1225 | completion-prefix-min-length))))) | ||
| 1226 | ;; The next two forms should happen as a unit (atomically) but | 1197 | ;; The next two forms should happen as a unit (atomically) but |
| 1227 | ;; no fatal errors should result if that is not the case. | 1198 | ;; no fatal errors should result if that is not the case. |
| 1228 | (cond (prefix-entry | 1199 | (cond (prefix-entry |
| @@ -1253,8 +1224,7 @@ Returns the completion entry." | |||
| 1253 | ;; found | 1224 | ;; found |
| 1254 | (let* ((prefix-entry (find-cmpl-prefix-entry | 1225 | (let* ((prefix-entry (find-cmpl-prefix-entry |
| 1255 | (substring cmpl-db-downcase-string 0 | 1226 | (substring cmpl-db-downcase-string 0 |
| 1256 | (cmpl-read-time-eval | 1227 | completion-prefix-min-length))) |
| 1257 | completion-prefix-min-length)))) | ||
| 1258 | (splice-ptr (locate-completion-entry cmpl-db-entry prefix-entry)) | 1228 | (splice-ptr (locate-completion-entry cmpl-db-entry prefix-entry)) |
| 1259 | (cmpl-ptr (cdr splice-ptr))) | 1229 | (cmpl-ptr (cdr splice-ptr))) |
| 1260 | ;; update entry | 1230 | ;; update entry |
| @@ -1277,8 +1247,7 @@ Returns the completion entry." | |||
| 1277 | ;; setup the prefix | 1247 | ;; setup the prefix |
| 1278 | (prefix-entry (find-cmpl-prefix-entry | 1248 | (prefix-entry (find-cmpl-prefix-entry |
| 1279 | (substring cmpl-db-downcase-string 0 | 1249 | (substring cmpl-db-downcase-string 0 |
| 1280 | (cmpl-read-time-eval | 1250 | completion-prefix-min-length)))) |
| 1281 | completion-prefix-min-length))))) | ||
| 1282 | (cond (prefix-entry | 1251 | (cond (prefix-entry |
| 1283 | ;; Splice in at head | 1252 | ;; Splice in at head |
| 1284 | (setcdr entry (cmpl-prefix-entry-head prefix-entry)) | 1253 | (setcdr entry (cmpl-prefix-entry-head prefix-entry)) |
| @@ -1301,8 +1270,7 @@ String must be longer than `completion-prefix-min-length'." | |||
| 1301 | ;; found | 1270 | ;; found |
| 1302 | (let* ((prefix-entry (find-cmpl-prefix-entry | 1271 | (let* ((prefix-entry (find-cmpl-prefix-entry |
| 1303 | (substring cmpl-db-downcase-string 0 | 1272 | (substring cmpl-db-downcase-string 0 |
| 1304 | (cmpl-read-time-eval | 1273 | completion-prefix-min-length))) |
| 1305 | completion-prefix-min-length)))) | ||
| 1306 | (splice-ptr (locate-completion-entry cmpl-db-entry prefix-entry))) | 1274 | (splice-ptr (locate-completion-entry cmpl-db-entry prefix-entry))) |
| 1307 | ;; delete symbol reference | 1275 | ;; delete symbol reference |
| 1308 | (set cmpl-db-symbol nil) | 1276 | (set cmpl-db-symbol nil) |
| @@ -1577,7 +1545,7 @@ If there are no more entries, try cdabbrev and returns only a string." | |||
| 1577 | 1545 | ||
| 1578 | 1546 | ||
| 1579 | (defun completion-search-peek (use-cdabbrev) | 1547 | (defun completion-search-peek (use-cdabbrev) |
| 1580 | "Returns the next completion entry without actually moving the pointers. | 1548 | "Return the next completion entry without actually moving the pointers. |
| 1581 | Calling this again or calling `completion-search-next' results in the same | 1549 | Calling this again or calling `completion-search-next' results in the same |
| 1582 | string being returned. Depends on `case-fold-search'. | 1550 | string being returned. Depends on `case-fold-search'. |
| 1583 | If there are no more entries, try cdabbrev and then return only a string." | 1551 | If there are no more entries, try cdabbrev and then return only a string." |
| @@ -1707,7 +1675,7 @@ Prefix args :: | |||
| 1707 | ;; Get the next completion | 1675 | ;; Get the next completion |
| 1708 | (let* ((print-status-p | 1676 | (let* ((print-status-p |
| 1709 | (and (>= baud-rate completion-prompt-speed-threshold) | 1677 | (and (>= baud-rate completion-prompt-speed-threshold) |
| 1710 | (not (minibuffer-window-selected-p)))) | 1678 | (not (window-minibuffer-p (selected-window))))) |
| 1711 | (insert-point (point)) | 1679 | (insert-point (point)) |
| 1712 | (entry (completion-search-next cmpl-current-index)) | 1680 | (entry (completion-search-next cmpl-current-index)) |
| 1713 | string) | 1681 | string) |
| @@ -2266,7 +2234,7 @@ If file is not specified, then use `save-completions-file-name'." | |||
| 2266 | 2234 | ||
| 2267 | (defun initialize-completions () | 2235 | (defun initialize-completions () |
| 2268 | "Load the default completions file. | 2236 | "Load the default completions file. |
| 2269 | Also sets up so that exiting emacs will automatically save the file." | 2237 | Also sets up so that exiting Emacs will automatically save the file." |
| 2270 | (interactive) | 2238 | (interactive) |
| 2271 | (cond ((not cmpl-initialized-p) | 2239 | (cond ((not cmpl-initialized-p) |
| 2272 | (load-completions-from-file))) | 2240 | (load-completions-from-file))) |
| @@ -2531,8 +2499,7 @@ TYPE is the type of the wrapper to be added. Can be :before or :under." | |||
| 2531 | 2499 | ||
| 2532 | (initialize-completions)) | 2500 | (initialize-completions)) |
| 2533 | 2501 | ||
| 2534 | (mapc (lambda (x) | 2502 | (mapc (lambda (x) (add-to-list 'debug-ignored-errors x)) |
| 2535 | (add-to-list 'debug-ignored-errors x)) | ||
| 2536 | '("^To complete, the point must be after a symbol at least [0-9]* character long\\.$" | 2503 | '("^To complete, the point must be after a symbol at least [0-9]* character long\\.$" |
| 2537 | "^The string \".*\" is too short to be saved as a completion\\.$")) | 2504 | "^The string \".*\" is too short to be saved as a completion\\.$")) |
| 2538 | 2505 | ||