Mercurial > emacs
comparison lisp/completion.el @ 190:8428fd468956
*** empty log message ***
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Thu, 07 Feb 1991 21:38:20 +0000 |
parents | 3146eff78ab1 |
children | 8a533acedb77 |
comparison
equal
deleted
inserted
replaced
189:70bc47d3c6c9 | 190:8428fd468956 |
---|---|
331 ;;; User changeable parameters | 331 ;;; User changeable parameters |
332 ;;;--------------------------------------------------------------------------- | 332 ;;;--------------------------------------------------------------------------- |
333 | 333 |
334 (defvar *completep* t | 334 (defvar *completep* t |
335 "*Set to nil to turn off the completion hooks. | 335 "*Set to nil to turn off the completion hooks. |
336 (No new words added to the database or saved to the init file)." | 336 (No new words added to the database or saved to the init file).") |
337 ) | |
338 | 337 |
339 (defvar *save-completions-p* t | 338 (defvar *save-completions-p* t |
340 "*If non-nil, the most useful completions are saved to disk when | 339 "*If non-nil, the most useful completions are saved to disk when |
341 exiting EMACS. See *saved-completions-decay-factor*.") | 340 exiting EMACS. See *saved-completions-decay-factor*.") |
342 | 341 |
343 (defvar *saved-completions-filename* "~/.completions" | 342 (defvar *saved-completions-filename* "~/.completions" |
344 "*The filename to save completions to.") | 343 "*The filename to save completions to.") |
345 | 344 |
346 (defvar *saved-completion-retention-time* 336 | 345 (defvar *saved-completion-retention-time* 336 |
347 "*The maximum amout of time to save a completion for if it has not been used. | 346 "*The maximum amount of time to save a completion for if it has not been used. |
348 In hours. (1 day = 24, 1 week = 168). If this is 0, non-permanent completions | 347 In hours. (1 day = 24, 1 week = 168). If this is 0, non-permanent completions |
349 will not be saved unless these are used. Default is two weeks." | 348 will not be saved unless these are used. Default is two weeks.") |
350 ) | |
351 | 349 |
352 (defvar *separator-character-uses-completion-p* nil | 350 (defvar *separator-character-uses-completion-p* nil |
353 "*If non-nil, typing a separator character after a completion symbol that | 351 "*If non-nil, typing a separator character after a completion symbol that |
354 is not part of the database marks it as used (so it will be saved).") | 352 is not part of the database marks it as used (so it will be saved).") |
355 | 353 |
361 "*The baud rate at or above which to print the next potential completion | 359 "*The baud rate at or above which to print the next potential completion |
362 after inserting the current one." | 360 after inserting the current one." |
363 ) | 361 ) |
364 | 362 |
365 (defvar *print-next-completion-does-cdabbrev-search-p* nil | 363 (defvar *print-next-completion-does-cdabbrev-search-p* nil |
366 "*If non-NIL, the next completion prompt will also do a cdabbrev search. | 364 "*If non-nil, the next completion prompt will also do a cdabbrev search. |
367 This can be time consuming.") | 365 This can be time consuming.") |
368 | 366 |
369 (defvar *cdabbrev-radius* 15000 | 367 (defvar *cdabbrev-radius* 15000 |
370 "*How far to search for cdabbrevs. In number of characters. If nil, the | 368 "*How far to search for cdabbrevs. In number of characters. If nil, the |
371 whole buffer is searched.") | 369 whole buffer is searched.") |
372 | 370 |
373 (defvar *modes-for-completion-find-file-hook* '(lisp c) | 371 (defvar *modes-for-completion-find-file-hook* '(lisp c) |
374 "*A list of modes {either c or lisp}. Definitions from visited files | 372 "*A list of modes {either C or Lisp}. Definitions from visited files |
375 of those types are automatically added to the completion database.") | 373 of those types are automatically added to the completion database.") |
376 | 374 |
377 (defvar *record-cmpl-statistics-p* nil | 375 (defvar *record-cmpl-statistics-p* nil |
378 "*If non-nil, statistics are automatically recorded.") | 376 "*If non-nil, statistics are automatically recorded.") |
379 | 377 |
394 DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.") | 392 DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.") |
395 | 393 |
396 (defmacro eval-when-compile-load-eval (&rest body) | 394 (defmacro eval-when-compile-load-eval (&rest body) |
397 ;; eval everything before expanding | 395 ;; eval everything before expanding |
398 (mapcar 'eval body) | 396 (mapcar 'eval body) |
399 (cons 'progn body) | 397 (cons 'progn body)) |
400 ) | |
401 | 398 |
402 (defun completion-eval-when () | 399 (defun completion-eval-when () |
403 (eval-when-compile-load-eval | 400 (eval-when-compile-load-eval |
404 ;; These vars. are defined at both compile and load time. | 401 ;; These vars. are defined at both compile and load time. |
405 (setq *completion-min-length* 6) | 402 (setq *completion-min-length* 6) |
406 (setq *completion-max-length* 200) | 403 (setq *completion-max-length* 200) |
407 (setq *completion-prefix-min-length* 3) | 404 (setq *completion-prefix-min-length* 3) |
408 ;; Need this file around too | 405 ;; Need this file around too |
409 (require 'cl) | 406 (require 'cl))) |
410 )) ;; eval-when | |
411 | 407 |
412 (completion-eval-when) | 408 (completion-eval-when) |
413 | 409 |
414 ;;;--------------------------------------------------------------------------- | 410 ;;;--------------------------------------------------------------------------- |
415 ;;; Internal Variables | 411 ;;; Internal Variables |
416 ;;;--------------------------------------------------------------------------- | 412 ;;;--------------------------------------------------------------------------- |
417 | 413 |
418 (defvar cmpl-initialized-p nil | 414 (defvar cmpl-initialized-p nil |
419 "Set to t when the completion system is initialized. Indicates that the old | 415 "Set to t when the completion system is initialized. Indicates that the |
420 completion file has been read in.") | 416 old completion file has been read in.") |
421 | 417 |
422 (defvar cmpl-completions-accepted-p nil | 418 (defvar cmpl-completions-accepted-p nil |
423 "Set to T as soon as the first completion has been accepted. Used to | 419 "Set to T as soon as the first completion has been accepted. Used to |
424 decide whether to save completions.") | 420 decide whether to save completions.") |
425 | 421 |
432 ;;; Misc. | 428 ;;; Misc. |
433 ;;;----------------------------------------------- | 429 ;;;----------------------------------------------- |
434 | 430 |
435 (defun remove (item list) | 431 (defun remove (item list) |
436 (setq list (copy-sequence list)) | 432 (setq list (copy-sequence list)) |
437 (delq item list) | 433 (delq item list)) |
438 ) | |
439 | 434 |
440 (defun minibuffer-window-selected-p () | 435 (defun minibuffer-window-selected-p () |
441 "True iff the current window is the minibuffer." | 436 "True iff the current window is the minibuffer." |
442 (eq (minibuffer-window) (selected-window))) | 437 (eq (minibuffer-window) (selected-window))) |
443 | 438 |
445 (defun function-needs-autoloading-p (symbol) | 440 (defun function-needs-autoloading-p (symbol) |
446 ;; True iff symbol is represents an autoloaded function and has not yet been | 441 ;; True iff symbol is represents an autoloaded function and has not yet been |
447 ;; autoloaded. | 442 ;; autoloaded. |
448 (and (listp (symbol-function symbol)) | 443 (and (listp (symbol-function symbol)) |
449 (eq 'autoload (car (symbol-function symbol))) | 444 (eq 'autoload (car (symbol-function symbol))) |
450 )) | 445 ))) |
451 ) ;; eval-when | |
452 | 446 |
453 (defun function-defined-and-loaded (symbol) | 447 (defun function-defined-and-loaded (symbol) |
454 ;; True iff symbol is bound to a loaded function. | 448 ;; True iff symbol is bound to a loaded function. |
455 (and (fboundp symbol) (not (function-needs-autoloading-p symbol))) | 449 (and (fboundp symbol) (not (function-needs-autoloading-p symbol)))) |
456 ) | |
457 | 450 |
458 (defmacro read-time-eval (form) | 451 (defmacro read-time-eval (form) |
459 ;; Like the #. reader macro | 452 ;; Like the #. reader macro |
460 (eval form) | 453 (eval form)) |
461 ) | |
462 | 454 |
463 ;;;----------------------------------------------- | 455 ;;;----------------------------------------------- |
464 ;;; Emacs Version 19 compatibility | 456 ;;; Emacs Version 19 compatibility |
465 ;;;----------------------------------------------- | 457 ;;;----------------------------------------------- |
466 | 458 |
624 ;;;----------------------------------------------- | 616 ;;;----------------------------------------------- |
625 | 617 |
626 (defvar cmpl-emacs-idle-process nil) | 618 (defvar cmpl-emacs-idle-process nil) |
627 | 619 |
628 (defvar cmpl-emacs-idle-interval 150 | 620 (defvar cmpl-emacs-idle-interval 150 |
629 "Seconds between running the emacs idle process.") | 621 "Seconds between running the Emacs idle process.") |
630 | 622 |
631 (defun init-cmpl-emacs-idle-process () | 623 (defun init-cmpl-emacs-idle-process () |
632 "Initialize the emacs idle process." | 624 "Initialize the emacs idle process." |
633 (let ((live (and cmpl-emacs-idle-process | 625 (let ((live (and cmpl-emacs-idle-process |
634 (eq (process-status cmpl-emacs-idle-process) 'run))) | 626 (eq (process-status cmpl-emacs-idle-process) 'run))) |
665 (setq last-command-char last-command-char) | 657 (setq last-command-char last-command-char) |
666 nil | 658 nil |
667 )) | 659 )) |
668 | 660 |
669 (defvar cmpl-emacs-idle-time 0 | 661 (defvar cmpl-emacs-idle-time 0 |
670 "The idle time of emacs in seconds.") | 662 "The idle time of Emacs in seconds.") |
671 | 663 |
672 (defvar inside-cmpl-emacs-idle-filter nil) | 664 (defvar inside-cmpl-emacs-idle-filter nil) |
673 (defvar cmpl-emacs-idle-time-hooks nil) | 665 (defvar cmpl-emacs-idle-time-hooks nil) |
674 | 666 |
675 (defun cmpl-emacs-idle-filter (proc string) | 667 (defun cmpl-emacs-idle-filter (proc string) |
694 | 686 |
695 | 687 |
696 ;;;----------------------------------------------- | 688 ;;;----------------------------------------------- |
697 ;;; Time | 689 ;;; Time |
698 ;;;----------------------------------------------- | 690 ;;;----------------------------------------------- |
699 ;;; What a backwards way to get the time ! Unfortunately, GNU Emacs | 691 ;;; What a backwards way to get the time! Unfortunately, GNU Emacs |
700 ;;; doesn't have an accessible time function. | 692 ;;; doesn't have an accessible time function. |
701 | 693 |
702 (defconst cmpl-hours-per-day 24) | 694 (defconst cmpl-hours-per-day 24) |
703 (defconst cmpl-hours-per-year (* 365 cmpl-hours-per-day)) | 695 (defconst cmpl-hours-per-year (* 365 cmpl-hours-per-day)) |
704 (defconst cmpl-hours-per-4-years (+ (* 4 cmpl-hours-per-year) | 696 (defconst cmpl-hours-per-4-years (+ (* 4 cmpl-hours-per-year) |
706 (defconst cmpl-days-since-start-of-year | 698 (defconst cmpl-days-since-start-of-year |
707 '(0 31 59 90 120 151 181 212 243 273 304 334)) | 699 '(0 31 59 90 120 151 181 212 243 273 304 334)) |
708 (defconst cmpl-days-since-start-of-leap-year | 700 (defconst cmpl-days-since-start-of-leap-year |
709 '(0 31 60 91 121 152 182 213 244 274 305 335)) | 701 '(0 31 60 91 121 152 182 213 244 274 305 335)) |
710 (defconst cmpl-months | 702 (defconst cmpl-months |
711 '("Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec") | 703 '("Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec")) |
712 ) | |
713 | 704 |
714 (defun cmpl-hours-since-1900-internal (month day year hours) | 705 (defun cmpl-hours-since-1900-internal (month day year hours) |
715 "Month is an integer from 1 to 12. Year is a two digit integer (19XX)" | 706 "Month is an integer from 1 to 12. Year is a two digit integer (19XX)" |
716 (+ ;; Year | 707 (+ ;; Year |
717 (* (/ (1- year) 4) cmpl-hours-per-4-years) | 708 (* (/ (1- year) 4) cmpl-hours-per-4-years) |
721 (* cmpl-hours-per-day | 712 (* cmpl-hours-per-day |
722 (nth (1- month) (if (zerop (mod year 4)) | 713 (nth (1- month) (if (zerop (mod year 4)) |
723 cmpl-days-since-start-of-leap-year | 714 cmpl-days-since-start-of-leap-year |
724 cmpl-days-since-start-of-year))) | 715 cmpl-days-since-start-of-year))) |
725 (* (1- day) cmpl-hours-per-day) | 716 (* (1- day) cmpl-hours-per-day) |
726 hours | 717 hours)) |
727 )) | |
728 | 718 |
729 (defun cmpl-month-from-string (month-string) | 719 (defun cmpl-month-from-string (month-string) |
730 "Month string is a three char. month string" | 720 "Month string is a three char. month string" |
731 (let ((count 1)) | 721 (let ((count 1)) |
732 (do ((list cmpl-months (cdr list)) | 722 (do ((list cmpl-months (cdr list)) |
743 (month (cmpl-month-from-string (substring string 4 7))) | 733 (month (cmpl-month-from-string (substring string 4 7))) |
744 (day (string-to-int (substring string 8 10))) | 734 (day (string-to-int (substring string 8 10))) |
745 (year (string-to-int (substring string 22 24))) | 735 (year (string-to-int (substring string 22 24))) |
746 (hour (string-to-int (substring string 11 13))) | 736 (hour (string-to-int (substring string 11 13))) |
747 ) | 737 ) |
748 (cmpl-hours-since-1900-internal month day year hour) | 738 (cmpl-hours-since-1900-internal month day year hour))) |
749 )) | |
750 | 739 |
751 ;;; Tests - | 740 ;;; Tests - |
752 ;;;(cmpl-hours-since-1900 "Wed Jan 1 00:00:28 1900") --> 35040 | 741 ;;;(cmpl-hours-since-1900 "Wed Jan 1 00:00:28 1900") --> 35040 |
753 ;;;(cmpl-hours-since-1900 "Wed Nov 2 23:00:28 1988") --> 778751 | 742 ;;;(cmpl-hours-since-1900 "Wed Nov 2 23:00:28 1988") --> 778751 |
754 ;;;(cmpl-hours-since-1900 "Wed Jan 23 14:34:28 1988") --> 771926 | 743 ;;;(cmpl-hours-since-1900 "Wed Jan 23 14:34:28 1988") --> 771926 |