diff options
| author | Roland McGrath | 1993-09-17 18:51:05 +0000 |
|---|---|---|
| committer | Roland McGrath | 1993-09-17 18:51:05 +0000 |
| commit | b81d991d750ab6144067be09347295a2dd122716 (patch) | |
| tree | 124492bda70bfff27f7a94024b517565c1b76803 | |
| parent | 65151a1bd491f852a66d652ceebd677b307dd216 (diff) | |
| download | emacs-b81d991d750ab6144067be09347295a2dd122716.tar.gz emacs-b81d991d750ab6144067be09347295a2dd122716.zip | |
(read-cookie): New function.
| -rw-r--r-- | lisp/play/cookie1.el | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/lisp/play/cookie1.el b/lisp/play/cookie1.el index a7792fb32b6..0cde6b9b703 100644 --- a/lisp/play/cookie1.el +++ b/lisp/play/cookie1.el | |||
| @@ -91,9 +91,9 @@ is read in, display STARTMSG at beginning of load, ENDMSG at end." | |||
| 91 | 91 | ||
| 92 | ;;;###autoload | 92 | ;;;###autoload |
| 93 | (defun cookie-snarf (phrase-file startmsg endmsg) | 93 | (defun cookie-snarf (phrase-file startmsg endmsg) |
| 94 | "Reads in the PHRASE-FILE, returns it as a vector of strings. Emit | 94 | "Reads in the PHRASE-FILE, returns it as a vector of strings. |
| 95 | STARTMSG and ENDMSG before and after. Caches the result; second and | 95 | Emit STARTMSG and ENDMSG before and after. Caches the result; second |
| 96 | subsequent calls on the same file won't go to disk." | 96 | and subsequent calls on the same file won't go to disk." |
| 97 | (let ((sym (intern-soft phrase-file cookie-cache))) | 97 | (let ((sym (intern-soft phrase-file cookie-cache))) |
| 98 | (and sym (not (equal (symbol-function sym) | 98 | (and sym (not (equal (symbol-function sym) |
| 99 | (nth 5 (file-attributes phrase-file)))) | 99 | (nth 5 (file-attributes phrase-file)))) |
| @@ -120,6 +120,26 @@ subsequent calls on the same file won't go to disk." | |||
| 120 | (message endmsg) | 120 | (message endmsg) |
| 121 | (set sym (apply 'vector result))))))) | 121 | (set sym (apply 'vector result))))))) |
| 122 | 122 | ||
| 123 | (defun read-cookie (prompt phrase-file startmsg endmsg &optional require-match) | ||
| 124 | "Prompt with PROMPT and read with completion among cookies in PHRASE-FILE. | ||
| 125 | STARTMSG and ENDMSG are passed along to `cookie-snarf'. | ||
| 126 | Optional fifth arg REQUIRE-MATCH non-nil forces a matching cookie." | ||
| 127 | ;; Make sure the cookies are in the cache. | ||
| 128 | (or (intern-soft phrase-file cookie-cache) | ||
| 129 | (cookie-snarf phrase-file startmsg endmsg)) | ||
| 130 | (completing-read prompt | ||
| 131 | (let ((sym (intern phrase-file cookie-cache))) | ||
| 132 | ;; We cache the alist form of the cookie in a property. | ||
| 133 | (or (get sym 'completion-alist) | ||
| 134 | (let* ((alist nil) | ||
| 135 | (vec (cookie-snarf phrase-file | ||
| 136 | startmsg endmsg)) | ||
| 137 | (i (length vec))) | ||
| 138 | (while (> (setq i (1- i)) 0) | ||
| 139 | (setq alist (cons (list (aref vec i)) alist))) | ||
| 140 | (put sym 'completion-alist alist)))) | ||
| 141 | nil require-match nil nil)) | ||
| 142 | |||
| 123 | ; Thanks to Ian G Batten <BattenIG@CS.BHAM.AC.UK> | 143 | ; Thanks to Ian G Batten <BattenIG@CS.BHAM.AC.UK> |
| 124 | ; [of the University of Birmingham Computer Science Department] | 144 | ; [of the University of Birmingham Computer Science Department] |
| 125 | ; for the iterative version of this shuffle. | 145 | ; for the iterative version of this shuffle. |