diff options
| author | Roland McGrath | 1993-07-14 23:36:04 +0000 |
|---|---|---|
| committer | Roland McGrath | 1993-07-14 23:36:04 +0000 |
| commit | 4054367c9e9ea0507f50db4874ee6f78f817a67e (patch) | |
| tree | 6609f3aa9c485baa42c8a5885845062a9ec4fb08 | |
| parent | 1265394fdd21cb462e087c3cf6d671b072ab6f70 (diff) | |
| download | emacs-4054367c9e9ea0507f50db4874ee6f78f817a67e.tar.gz emacs-4054367c9e9ea0507f50db4874ee6f78f817a67e.zip | |
(cookie-cache): New defvar.
(cookie-snarf): Cache cookies in `cookie-cache', not in obarray (idiot).
Also store the modtime and punt the cache when it changes.
| -rw-r--r-- | lisp/play/cookie1.el | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/lisp/play/cookie1.el b/lisp/play/cookie1.el index e07b08c32f3..aa767ed8f4e 100644 --- a/lisp/play/cookie1.el +++ b/lisp/play/cookie1.el | |||
| @@ -60,6 +60,9 @@ | |||
| 60 | (defconst cookie-delimiter "\n%%\n\\|\0" | 60 | (defconst cookie-delimiter "\n%%\n\\|\0" |
| 61 | "Delimiter used to separate cookie file entries.") | 61 | "Delimiter used to separate cookie file entries.") |
| 62 | 62 | ||
| 63 | (defvar cookie-cache (make-vector 511 0) | ||
| 64 | "Cache of cookie files that have already been snarfed.") | ||
| 65 | |||
| 63 | (defun cookie (phrase-file startmsg endmsg) | 66 | (defun cookie (phrase-file startmsg endmsg) |
| 64 | "Return a random phrase from PHRASE-FILE. When the phrase file | 67 | "Return a random phrase from PHRASE-FILE. When the phrase file |
| 65 | is read in, display STARTMSG at beginning of load, ENDMSG at end." | 68 | is read in, display STARTMSG at beginning of load, ENDMSG at end." |
| @@ -89,23 +92,31 @@ is read in, display STARTMSG at beginning of load, ENDMSG at end." | |||
| 89 | "Reads in the PHRASE-FILE, returns it as a vector of strings. Emit | 92 | "Reads in the PHRASE-FILE, returns it as a vector of strings. Emit |
| 90 | STARTMSG and ENDMSG before and after. Caches the result; second and | 93 | STARTMSG and ENDMSG before and after. Caches the result; second and |
| 91 | subsequent calls on the same file won't go to disk." | 94 | subsequent calls on the same file won't go to disk." |
| 92 | (if (boundp (intern phrase-file)) | 95 | (let ((sym (intern-soft phrase-file cookie-cache))) |
| 93 | (eval (intern phrase-file)) | 96 | (and sym (not (equal (symbol-function sym) |
| 94 | (message startmsg) | 97 | (nth 5 (file-attributes phrase-file)))) |
| 95 | (save-excursion | 98 | (yes-or-no-p (concat phrase-file |
| 96 | (let ((buf (generate-new-buffer "*cookie*")) | 99 | " has changed. Read new contents? ")) |
| 97 | (result nil)) | 100 | (setq sym nil)) |
| 98 | (set-buffer buf) | 101 | (if sym |
| 99 | (insert-file-contents (expand-file-name phrase-file)) | 102 | (symbol-value sym) |
| 100 | (re-search-forward cookie-delimiter) | 103 | (setq sym (intern phrase-file cookie-cache)) |
| 101 | (while (progn (skip-chars-forward " \t\n\r\f") (not (eobp))) | 104 | (message startmsg) |
| 102 | (let ((beg (point))) | 105 | (save-excursion |
| 103 | (re-search-forward cookie-delimiter) | 106 | (let ((buf (generate-new-buffer "*cookie*")) |
| 104 | (setq result (cons (buffer-substring beg (1- (point))) | 107 | (result nil)) |
| 105 | result)))) | 108 | (set-buffer buf) |
| 106 | (kill-buffer buf) | 109 | (fset sym (nth 5 (file-attributes phrase-file))) |
| 107 | (message endmsg) | 110 | (insert-file-contents (expand-file-name phrase-file)) |
| 108 | (set (intern phrase-file) (apply 'vector result)))))) | 111 | (re-search-forward cookie-delimiter) |
| 112 | (while (progn (skip-chars-forward " \t\n\r\f") (not (eobp))) | ||
| 113 | (let ((beg (point))) | ||
| 114 | (re-search-forward cookie-delimiter) | ||
| 115 | (setq result (cons (buffer-substring beg (1- (point))) | ||
| 116 | result)))) | ||
| 117 | (kill-buffer buf) | ||
| 118 | (message endmsg) | ||
| 119 | (set sym (apply 'vector result))))))) | ||
| 109 | 120 | ||
| 110 | (defun pick-random (n) | 121 | (defun pick-random (n) |
| 111 | "Returns a random number from 0 to N-1 inclusive." | 122 | "Returns a random number from 0 to N-1 inclusive." |