/[cmucl]/src/hemlock/echo.lisp
ViewVC logotype

Contents of /src/hemlock/echo.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations)
Wed Dec 18 11:44:07 1991 UTC (22 years, 4 months ago) by wlott
Branch: MAIN
Changes since 1.5: +4 -20 lines
In FILE-VERIFICATION-FUNCTION, just use MERGE-PATHNAMES to do the merging,
because it works correctly now.
1 ;;; -*- Log: hemlock.log; Package: Hemlock-Internals -*-
2 ;;;
3 ;;; **********************************************************************
4 ;;; This code was written as part of the CMU Common Lisp project at
5 ;;; Carnegie Mellon University, and has been placed in the public domain.
6 ;;; If you want to use this code or any part of CMU Common Lisp, please contact
7 ;;; Scott Fahlman or slisp-group@cs.cmu.edu.
8 ;;;
9 (ext:file-comment
10 "$Header: /tiger/var/lib/cvsroots/cmucl/src/hemlock/echo.lisp,v 1.6 1991/12/18 11:44:07 wlott Exp $")
11 ;;;
12 ;;; **********************************************************************
13 ;;;
14 ;;; Hemlock Echo Area stuff.
15 ;;; Written by Skef Wholey and Rob MacLachlan.
16 ;;; Modified by Bill Chiles.
17 ;;;
18 (in-package "HEMLOCK-INTERNALS")
19 (export '(*echo-area-buffer* *echo-area-stream* *echo-area-window*
20 *parse-starting-mark* *parse-input-region*
21 *parse-verification-function* *parse-string-tables*
22 *parse-value-must-exist* *parse-default* *parse-default-string*
23 *parse-prompt* *parse-help* clear-echo-area message loud-message
24 prompt-for-buffer prompt-for-file prompt-for-integer
25 prompt-for-keyword prompt-for-expression prompt-for-string
26 prompt-for-variable prompt-for-yes-or-no prompt-for-y-or-n
27 prompt-for-key-event prompt-for-key *logical-key-event-names*
28 logical-key-event-p logical-key-event-documentation
29 logical-key-event-name logical-key-event-key-events
30 define-logical-key-event *parse-type* current-variable-tables))
31
32
33 (defmode "Echo Area" :major-p t)
34 (defvar *echo-area-buffer* (make-buffer "Echo Area" :modes '("Echo Area"))
35 "Buffer used to hack text for the echo area.")
36 (defvar *echo-area-region* (buffer-region *echo-area-buffer*)
37 "Internal thing that's the *echo-area-buffer*'s region.")
38 (defvar *echo-area-stream*
39 (make-hemlock-output-stream (region-end *echo-area-region*) :full)
40 "Buffered stream that prints into the echo area.")
41 (defvar *echo-area-window* ()
42 "Window used to display stuff in the echo area.")
43 (defvar *parse-starting-mark*
44 (copy-mark (buffer-point *echo-area-buffer*) :right-inserting)
45 "Mark that points to the beginning of the text that'll be parsed.")
46 (defvar *parse-input-region*
47 (region *parse-starting-mark* (region-end *echo-area-region*))
48 "Region that contains the text typed in.")
49
50
51
52 ;;;; Variables that control parsing:
53
54 (defvar *parse-verification-function* '%not-inside-a-parse
55 "Function that verifies what's being parsed.")
56
57 ;;; %Not-Inside-A-Parse -- Internal
58 ;;;
59 ;;; This function is called if someone does stuff in the echo area when
60 ;;; we aren't inside a parse. It tries to put them back in a reasonable place.
61 ;;;
62 (defun %not-inside-a-parse (quaz)
63 "Thing that's called when somehow we get called to confirm a parse that's
64 not in progress."
65 (declare (ignore quaz))
66 (let* ((bufs (remove *echo-area-buffer* *buffer-list*))
67 (buf (or (find-if #'buffer-windows bufs)
68 (car bufs)
69 (make-buffer "Main"))))
70 (setf (current-buffer) buf)
71 (dolist (w *window-list*)
72 (when (and (eq (window-buffer w) *echo-area-buffer*)
73 (not (eq w *echo-area-window*)))
74 (setf (window-buffer w) buf)))
75 (setf (current-window)
76 (or (car (buffer-windows buf))
77 (make-window (buffer-start-mark buf)))))
78 (editor-error "Wham! We tried to confirm a parse that wasn't in progress?"))
79
80 (defvar *parse-string-tables* ()
81 "String tables being used in the current parse.")
82
83 (defvar *parse-value-must-exist* ()
84 "You know.")
85
86 (defvar *parse-default* ()
87 "When the user attempts to default a parse, we call the verification function
88 on this string. This is not the :Default argument to the prompting function,
89 but rather a string representation of it.")
90
91 (defvar *parse-default-string* ()
92 "String that we show the user to inform him of the default. If this
93 is NIL then we just use *Parse-Default*.")
94
95 (defvar *parse-prompt* ()
96 "Prompt for the current parse.")
97
98 (defvar *parse-help* ()
99 "Help string for the current parse.")
100
101 (defvar *parse-type* :string "A hack. :String, :File or :Keyword.")
102
103
104
105 ;;;; MESSAGE and CLEAR-ECHO-AREA:
106
107 (defhvar "Message Pause" "The number of seconds to pause after a Message."
108 :value 0.5s0)
109
110 (defvar *last-message-time* 0
111 "Internal-Real-Time the last time we displayed a message.")
112
113 (defun maybe-wait ()
114 (let* ((now (get-internal-real-time))
115 (delta (/ (float (- now *last-message-time*))
116 (float internal-time-units-per-second)))
117 (pause (value ed::message-pause)))
118 (when (< delta pause)
119 (sleep (- pause delta)))))
120
121 (defun clear-echo-area ()
122 "You guessed it."
123 (maybe-wait)
124 (delete-region *echo-area-region*)
125 (setf (buffer-modified *echo-area-buffer*) nil))
126
127 ;;; Message -- Public
128 ;;;
129 ;;; Display the stuff on *echo-area-stream* and then wait. Editor-Sleep
130 ;;; will do a redisplay if appropriate.
131 ;;;
132 (defun message (string &rest args)
133 "Nicely display a message in the echo-area.
134 Put the message on a fresh line and wait for \"Message Pause\" seconds
135 to give the luser a chance to see it. String and Args are a format
136 control string and format arguments, respectively."
137 (maybe-wait)
138 (cond ((eq *current-window* *echo-area-window*)
139 (let ((point (buffer-point *echo-area-buffer*)))
140 (with-mark ((m point :left-inserting))
141 (line-start m)
142 (with-output-to-mark (s m :full)
143 (apply #'format s string args)
144 (fresh-line s)))))
145 (t
146 (let ((mark (region-end *echo-area-region*)))
147 (cond ((buffer-modified *echo-area-buffer*)
148 (clear-echo-area))
149 ((not (zerop (mark-charpos mark)))
150 (insert-character mark #\newline)
151 (unless (displayed-p mark *echo-area-window*)
152 (clear-echo-area))))
153 (apply #'format *echo-area-stream* string args)
154 (setf (buffer-modified *echo-area-buffer*) nil))))
155 (force-output *echo-area-stream*)
156 (setq *last-message-time* (get-internal-real-time))
157 nil)
158
159
160 ;;; LOUD-MESSAGE -- Public.
161 ;;;
162 ;;; Like message, only more provocative.
163 ;;;
164 (defun loud-message (&rest args)
165 "This is the same as MESSAGE, but it beeps and clears the echo area before
166 doing anything else."
167 (beep)
168 (clear-echo-area)
169 (apply #'message args))
170
171
172 (defhvar "Raise Echo Area When Modified"
173 "When set, Hemlock raises the echo area window when output appears there."
174 :value nil)
175
176 ;;; RAISE-ECHO-AREA-WHEN-MODIFIED -- Internal.
177 ;;;
178 ;;; INIT-BITMAP-SCREEN-MANAGER in bit-screen.lisp adds this hook when
179 ;;; initializing the bitmap screen manager.
180 ;;;
181 (defun raise-echo-area-when-modified (buffer modified)
182 (when (and (value ed::raise-echo-area-when-modified)
183 (eq buffer *echo-area-buffer*)
184 modified)
185 (let* ((hunk (window-hunk *echo-area-window*))
186 (win (window-group-xparent (bitmap-hunk-window-group hunk))))
187 (xlib:map-window win)
188 (setf (xlib:window-priority win) :above)
189 (xlib:display-force-output
190 (bitmap-device-display (device-hunk-device hunk))))))
191
192
193
194 ;;;; DISPLAY-PROMPT-NICELY and PARSE-FOR-SOMETHING.
195
196 (defun display-prompt-nicely (&optional (prompt *parse-prompt*)
197 (default (or *parse-default-string*
198 *parse-default*)))
199 (clear-echo-area)
200 (let ((point (buffer-point *echo-area-buffer*)))
201 (if (listp prompt)
202 (apply #'format *echo-area-stream* prompt)
203 (insert-string point prompt))
204 (when default
205 (insert-character point #\[)
206 (insert-string point default)
207 (insert-string point "] "))))
208
209 (defun parse-for-something ()
210 (display-prompt-nicely)
211 (let ((start-window (current-window)))
212 (move-mark *parse-starting-mark* (buffer-point *echo-area-buffer*))
213 (setf (current-window) *echo-area-window*)
214 (unwind-protect
215 (use-buffer *echo-area-buffer*
216 (recursive-edit nil))
217 (setf (current-window) start-window))))
218
219
220
221 ;;;; Buffer prompting.
222
223 (defun prompt-for-buffer (&key ((:must-exist *parse-value-must-exist*) t)
224 default
225 ((:default-string *parse-default-string*))
226 ((:prompt *parse-prompt*) "Buffer: ")
227 ((:help *parse-help*) "Type a buffer name."))
228 "Prompts for a buffer name and returns the corresponding buffer. If
229 :must-exist is nil, then return the input string. This refuses to accept
230 the empty string as input when no default is supplied. :default-string
231 may be used to supply a default buffer name even when :default is nil, but
232 when :must-exist is non-nil, :default-string must be the name of an existing
233 buffer."
234 (let ((*parse-string-tables* (list *buffer-names*))
235 (*parse-type* :keyword)
236 (*parse-default* (cond
237 (default (buffer-name default))
238 (*parse-default-string*
239 (when (and *parse-value-must-exist*
240 (not (getstring *parse-default-string*
241 *buffer-names*)))
242 (error "Default-string must name an existing ~
243 buffer when must-exist is non-nil -- ~S."
244 *parse-default-string*))
245 *parse-default-string*)
246 (t nil)))
247 (*parse-verification-function* #'buffer-verification-function))
248 (parse-for-something)))
249
250 (defun buffer-verification-function (string)
251 (declare (simple-string string))
252 (cond ((string= string "") nil)
253 (*parse-value-must-exist*
254 (multiple-value-bind
255 (prefix key value field ambig)
256 (complete-string string *parse-string-tables*)
257 (declare (ignore field))
258 (ecase key
259 (:none nil)
260 ((:unique :complete)
261 (list value))
262 (:ambiguous
263 (delete-region *parse-input-region*)
264 (insert-string (region-start *parse-input-region*) prefix)
265 (let ((point (current-point)))
266 (move-mark point (region-start *parse-input-region*))
267 (unless (character-offset point ambig)
268 (buffer-end point)))
269 nil))))
270 (t
271 (list (or (getstring string *buffer-names*) string)))))
272
273
274
275 ;;;; File Prompting.
276
277 (defun prompt-for-file (&key ((:must-exist *parse-value-must-exist*) t)
278 default
279 ((:default-string *parse-default-string*))
280 ((:prompt *parse-prompt*) "Filename: ")
281 ((:help *parse-help*) "Type a file name."))
282 "Prompts for a filename."
283 (let ((*parse-verification-function* #'file-verification-function)
284 (*parse-default* (if default (namestring default)))
285 (*parse-type* :file))
286 (parse-for-something)))
287
288 (defun file-verification-function (string)
289 (let ((pn (pathname-or-lose string)))
290 (if pn
291 (let ((merge
292 (cond ((not *parse-default*) nil)
293 ((directoryp pn)
294 (merge-pathnames pn *parse-default*))
295 (t
296 (merge-pathnames pn
297 (directory-namestring
298 *parse-default*))))))
299 (cond ((probe-file pn) (list pn))
300 ((and merge (probe-file merge)) (list merge))
301 ((not *parse-value-must-exist*) (list (or merge pn)))
302 (t nil))))))
303
304 ;;; PATHNAME-OR-LOSE tries to convert string to a pathname using
305 ;;; PARSE-NAMESTRING. If it succeeds, this returns the pathname. Otherwise,
306 ;;; this deletes the offending characters from *parse-input-region* and signals
307 ;;; an editor-error.
308 ;;;
309 (defun pathname-or-lose (string)
310 (declare (simple-string string))
311 (multiple-value-bind (pn idx)
312 (parse-namestring string nil *default-pathname-defaults*
313 :junk-allowed t)
314 (cond (pn)
315 (t (delete-characters (region-end *echo-area-region*)
316 (- idx (length string)))
317 nil))))
318
319
320
321 ;;;; Keyword and variable prompting.
322
323 (defun prompt-for-keyword (*parse-string-tables*
324 &key
325 ((:must-exist *parse-value-must-exist*) t)
326 ((:default *parse-default*))
327 ((:default-string *parse-default-string*))
328 ((:prompt *parse-prompt*) "Keyword: ")
329 ((:help *parse-help*) "Type a keyword."))
330 "Prompts for a keyword using the String Tables."
331 (let ((*parse-verification-function* #'keyword-verification-function)
332 (*parse-type* :keyword))
333 (parse-for-something)))
334
335 (defun prompt-for-variable (&key ((:must-exist *parse-value-must-exist*) t)
336 ((:default *parse-default*))
337 ((:default-string *parse-default-string*))
338 ((:prompt *parse-prompt*) "Variable: ")
339 ((:help *parse-help*)
340 "Type the name of a variable."))
341 "Prompts for a variable defined in the current scheme of things."
342 (let ((*parse-string-tables* (current-variable-tables))
343 (*parse-verification-function* #'keyword-verification-function)
344 (*parse-type* :keyword))
345 (parse-for-something)))
346
347 (defun current-variable-tables ()
348 "Returns a list of all the variable tables currently established globally,
349 by the current buffer, and by any modes for the current buffer."
350 (do ((tables (list (buffer-variables *current-buffer*)
351 *global-variable-names*)
352 (cons (mode-object-variables (car mode)) tables))
353 (mode (buffer-mode-objects *current-buffer*) (cdr mode)))
354 ((null mode) tables)))
355
356 (defun keyword-verification-function (string)
357 (declare (simple-string string))
358 (multiple-value-bind
359 (prefix key value field ambig)
360 (complete-string string *parse-string-tables*)
361 (declare (ignore field))
362 (cond (*parse-value-must-exist*
363 (ecase key
364 (:none nil)
365 ((:unique :complete)
366 (list prefix value))
367 (:ambiguous
368 (delete-region *parse-input-region*)
369 (insert-string (region-start *parse-input-region*) prefix)
370 (let ((point (current-point)))
371 (move-mark point (region-start *parse-input-region*))
372 (unless (character-offset point ambig)
373 (buffer-end point)))
374 nil)))
375 (t
376 ;; HACK: If it doesn't have to exist, and the completion does not
377 ;; add anything, then return the completion's capitalization,
378 ;; instead of the user's input.
379 (list (if (= (length string) (length prefix)) prefix string))))))
380
381
382
383 ;;;; Integer, expression, and string prompting.
384
385 (defun prompt-for-integer (&key ((:must-exist *parse-value-must-exist*) t)
386 default
387 ((:default-string *parse-default-string*))
388 ((:prompt *parse-prompt*) "Integer: ")
389 ((:help *parse-help*) "Type an integer."))
390 "Prompt for an integer. If :must-exist is Nil, then we return as a string
391 whatever was input if it is not a valid integer."
392 (let ((*parse-verification-function*
393 #'(lambda (string)
394 (let ((number (parse-integer string :junk-allowed t)))
395 (if *parse-value-must-exist*
396 (if number (list number))
397 (list (or number string))))))
398 (*parse-default* (if default (write-to-string default :base 10))))
399 (parse-for-something)))
400
401
402 (defvar hemlock-eof '(())
403 "An object that won't be EQ to anything read.")
404
405 (defun prompt-for-expression (&key ((:must-exist *parse-value-must-exist*) t)
406 (default nil defaultp)
407 ((:default-string *parse-default-string*))
408 ((:prompt *parse-prompt*) "Expression: ")
409 ((:help *parse-help*)
410 "Type a Lisp expression."))
411 "Prompts for a Lisp expression."
412 (let ((*parse-verification-function*
413 #'(lambda (string)
414 (let ((expr (with-input-from-region (stream *parse-input-region*)
415 (handler-case (read stream nil hemlock-eof)
416 (error () hemlock-eof)))))
417 (if *parse-value-must-exist*
418 (if (not (eq expr hemlock-eof)) (values (list expr) t))
419 (if (eq expr hemlock-eof)
420 (list string) (values (list expr) t))))))
421 (*parse-default* (if defaultp (prin1-to-string default))))
422 (parse-for-something)))
423
424
425 (defun prompt-for-string (&key ((:default *parse-default*))
426 ((:default-string *parse-default-string*))
427 (trim ())
428 ((:prompt *parse-prompt*) "String: ")
429 ((:help *parse-help*) "Type a string."))
430 "Prompts for a string. If :trim is t, then leading and trailing whitespace
431 is removed from input, otherwise it is interpreted as a Char-Bag argument
432 to String-Trim."
433 (let ((*parse-verification-function*
434 #'(lambda (string)
435 (list (string-trim (if (eq trim t) '(#\space #\tab) trim)
436 string)))))
437 (parse-for-something)))
438
439
440
441 ;;;; Yes-or-no and y-or-n prompting.
442
443 (defvar *yes-or-no-string-table*
444 (make-string-table :initial-contents '(("Yes" . t) ("No" . nil))))
445
446 (defun prompt-for-yes-or-no (&key ((:must-exist *parse-value-must-exist*) t)
447 (default nil defaultp)
448 ((:default-string *parse-default-string*))
449 ((:prompt *parse-prompt*) "Yes or No? ")
450 ((:help *parse-help*) "Type Yes or No."))
451 "Prompts for Yes or No."
452 (let* ((*parse-string-tables* (list *yes-or-no-string-table*))
453 (*parse-default* (if defaultp (if default "Yes" "No")))
454 (*parse-verification-function*
455 #'(lambda (string)
456 (multiple-value-bind
457 (prefix key value field ambig)
458 (complete-string string *parse-string-tables*)
459 (declare (ignore prefix field ambig))
460 (let ((won (or (eq key :complete) (eq key :unique))))
461 (if *parse-value-must-exist*
462 (if won (values (list value) t))
463 (list (if won (values value t) string)))))))
464 (*parse-type* :keyword))
465 (parse-for-something)))
466
467 (defun prompt-for-y-or-n (&key ((:must-exist must-exist) t)
468 (default nil defaultp)
469 default-string
470 ((:prompt prompt) "Y or N? ")
471 ((:help *parse-help*) "Type Y or N."))
472 "Prompts for Y or N."
473 (let ((old-window (current-window)))
474 (unwind-protect
475 (progn
476 (setf (current-window) *echo-area-window*)
477 (display-prompt-nicely prompt (or default-string
478 (if defaultp (if default "Y" "N"))))
479 (loop
480 (let ((key-event (get-key-event *editor-input*)))
481 (cond ((or (eq key-event #k"y")
482 (eq key-event #k"Y"))
483 (return t))
484 ((or (eq key-event #k"n")
485 (eq key-event #k"N"))
486 (return nil))
487 ((logical-key-event-p key-event :confirm)
488 (if defaultp
489 (return default)
490 (beep)))
491 ((logical-key-event-p key-event :help)
492 (ed::help-on-parse-command ()))
493 (t
494 (unless must-exist (return key-event))
495 (beep))))))
496 (setf (current-window) old-window))))
497
498
499
500 ;;;; Key-event and key prompting.
501
502 (defun prompt-for-key-event (&key (prompt "Key-event: ") (change-window t))
503 "Prompts for a key-event."
504 (prompt-for-key-event* prompt change-window))
505
506 (defun prompt-for-key-event* (prompt change-window)
507 (let ((old-window (current-window)))
508 (unwind-protect
509 (progn
510 (when change-window
511 (setf (current-window) *echo-area-window*))
512 (display-prompt-nicely prompt)
513 (get-key-event *editor-input* t))
514 (when change-window (setf (current-window) old-window)))))
515
516 (defvar *prompt-key* (make-array 10 :adjustable t :fill-pointer 0))
517 (defun prompt-for-key (&key ((:must-exist must-exist) t)
518 default default-string
519 (prompt "Key: ")
520 ((:help *parse-help*) "Type a key."))
521 (let ((old-window (current-window))
522 (string (if default
523 (or default-string
524 (let ((l (coerce default 'list)))
525 (format nil "~:C~{ ~:C~}" (car l) (cdr l)))))))
526
527 (unwind-protect
528 (progn
529 (setf (current-window) *echo-area-window*)
530 (display-prompt-nicely prompt string)
531 (setf (fill-pointer *prompt-key*) 0)
532 (prog ((key *prompt-key*) key-event)
533 (declare (vector key))
534 TOP
535 (setf key-event (get-key-event *editor-input*))
536 (cond ((logical-key-event-p key-event :quote)
537 (setf key-event (get-key-event *editor-input* t)))
538 ((logical-key-event-p key-event :confirm)
539 (cond ((and default (zerop (length key)))
540 (let ((res (get-command default :current)))
541 (unless (commandp res) (go FLAME))
542 (return (values default res))))
543 ((and (not must-exist) (plusp (length key)))
544 (return (copy-seq key)))
545 (t
546 (go FLAME))))
547 ((logical-key-event-p key-event :help)
548 (ed::help-on-parse-command ())
549 (go TOP)))
550 (vector-push-extend key-event key)
551 (when must-exist
552 (let ((res (get-command key :current)))
553 (cond ((commandp res)
554 (ext:print-pretty-key-event key-event
555 *echo-area-stream*
556 t)
557 (write-char #\space *echo-area-stream*)
558 (return (values (copy-seq key) res)))
559 ((not (eq res :prefix))
560 (vector-pop key)
561 (go FLAME)))))
562 (print-pretty-key key-event *echo-area-stream* t)
563 (write-char #\space *echo-area-stream*)
564 (go TOP)
565 FLAME
566 (beep)
567 (go TOP)))
568 (force-output *echo-area-stream*)
569 (setf (current-window) old-window))))
570
571
572
573 ;;;; Logical key-event stuff.
574
575 (defvar *logical-key-event-names* (make-string-table)
576 "This variable holds a string-table from logical-key-event names to the
577 corresponding keywords.")
578
579 (defvar *real-to-logical-key-events* (make-hash-table :test #'eql)
580 "A hashtable from real key-events to their corresponding logical
581 key-event keywords.")
582
583 (defvar *logical-key-event-descriptors* (make-hash-table :test #'eq)
584 "A hashtable from logical-key-events to logical-key-event-descriptors.")
585
586 (defstruct (logical-key-event-descriptor
587 (:constructor make-logical-key-event-descriptor ()))
588 name
589 key-events
590 documentation)
591
592 ;;; LOGICAL-KEY-EVENT-P -- Public
593 ;;;
594 (defun logical-key-event-p (key-event keyword)
595 "Return true if key-event has been defined to have Keyword as its
596 logical key-event. The relation between logical and real key-events
597 is defined by using SETF on LOGICAL-KEY-EVENT-P. If it is set to
598 true then calling LOGICAL-KEY-EVENT-P with the same key-event and
599 Keyword, will result in truth. Setting to false produces the opposite
600 result. See DEFINE-LOGICAL-KEY-EVENT and COMMAND-CASE."
601 (not (null (memq keyword (gethash key-event *real-to-logical-key-events*)))))
602
603 ;;; GET-LOGICAL-KEY-EVENT-DESC -- Internal
604 ;;;
605 ;;; Return the descriptor for the logical key-event keyword, or signal
606 ;;; an error if it isn't defined.
607 ;;;
608 (defun get-logical-key-event-desc (keyword)
609 (let ((res (gethash keyword *logical-key-event-descriptors*)))
610 (unless res
611 (error "~S is not a defined logical-key-event keyword." keyword))
612 res))
613
614 ;;; %SET-LOGICAL-KEY-EVENT-P -- Internal
615 ;;;
616 ;;; Add or remove a logical key-event link by adding to or deleting from
617 ;;; the list in the from-char hashtable and the descriptor.
618 ;;;
619 (defun %set-logical-key-event-p (key-event keyword new-value)
620 (let ((entry (get-logical-key-event-desc keyword)))
621 (cond
622 (new-value
623 (pushnew keyword (gethash key-event *real-to-logical-key-events*))
624 (pushnew key-event (logical-key-event-descriptor-key-events entry)))
625 (t
626 (setf (gethash key-event *real-to-logical-key-events*)
627 (delete keyword (gethash key-event *real-to-logical-key-events*)))
628 (setf (logical-key-event-descriptor-key-events entry)
629 (delete keyword (logical-key-event-descriptor-key-events entry))))))
630 new-value)
631
632 ;;; LOGICAL-KEY-EVENT-DOCUMENTATION, NAME, KEY-EVENTS -- Public
633 ;;;
634 ;;; Grab the right field out of the descriptor and return it.
635 ;;;
636 (defun logical-key-event-documentation (keyword)
637 "Return the documentation for the logical key-event Keyword."
638 (logical-key-event-descriptor-documentation
639 (get-logical-key-event-desc keyword)))
640 ;;;
641 (defun logical-key-event-name (keyword)
642 "Return the string name for the logical key-event Keyword."
643 (logical-key-event-descriptor-name (get-logical-key-event-desc keyword)))
644 ;;;
645 (defun logical-key-event-key-events (keyword)
646 "Return the list of key-events for which Keyword is the logical key-event."
647 (logical-key-event-descriptor-key-events
648 (get-logical-key-event-desc keyword)))
649
650 ;;; DEFINE-LOGICAL-KEY-EVENT -- Public
651 ;;;
652 ;;; Make the entries in the two hashtables and the string-table.
653 ;;;
654 (defun define-logical-key-event (name documentation)
655 "Define a logical key-event having the specified Name and Documentation.
656 See LOGICAL-KEY-EVENT-P and COMMAND-CASE."
657 (check-type name string)
658 (check-type documentation (or string function))
659 (let* ((keyword (string-to-keyword name))
660 (entry (or (gethash keyword *logical-key-event-descriptors*)
661 (setf (gethash keyword *logical-key-event-descriptors*)
662 (make-logical-key-event-descriptor)))))
663 (setf (logical-key-event-descriptor-name entry) name)
664 (setf (logical-key-event-descriptor-documentation entry) documentation)
665 (setf (getstring name *logical-key-event-names*) keyword)))
666
667
668
669 ;;;; Some standard logical-key-events:
670
671 (define-logical-key-event "Forward Search"
672 "This key-event is used to indicate that a forward search should be made.")
673 (define-logical-key-event "Backward Search"
674 "This key-event is used to indicate that a backward search should be made.")
675 (define-logical-key-event "Recursive Edit"
676 "This key-event indicates that a recursive edit should be entered.")
677 (define-logical-key-event "Cancel"
678 "This key-event is used to cancel a previous key-event of input.")
679 (define-logical-key-event "Abort"
680 "This key-event is used to abort the command in progress.")
681 (define-logical-key-event "Exit"
682 "This key-event is used to exit normally the command in progress.")
683 (define-logical-key-event "Yes"
684 "This key-event is used to indicate a positive response.")
685 (define-logical-key-event "No"
686 "This key-event is used to indicate a negative response.")
687 (define-logical-key-event "Do All"
688 "This key-event means do it as many times as you can.")
689 (define-logical-key-event "Do Once"
690 "This key-event means, do it this time, then exit.")
691 (define-logical-key-event "Help"
692 "This key-event is used to ask for help.")
693 (define-logical-key-event "Confirm"
694 "This key-event is used to confirm some choice.")
695 (define-logical-key-event "Quote"
696 "This key-event is used to quote the next key-event of input.")
697 (define-logical-key-event "Keep"
698 "This key-event means exit but keep something around.")
699
700
701
702 ;;;; COMMAND-CASE help message printing.
703
704 (defvar *my-string-output-stream* (make-string-output-stream))
705
706 (defun chars-to-string (chars)
707 (do ((s *my-string-output-stream*)
708 (chars chars (cdr chars)))
709 ((null chars)
710 (get-output-stream-string s))
711 (let ((char (car chars)))
712 (if (characterp char)
713 (write-char char s)
714 (do ((key-events
715 (logical-key-event-key-events char)
716 (cdr key-events)))
717 ((null key-events))
718 (ext:print-pretty-key (car key-events) s)
719 (unless (null (cdr key-events))
720 (write-string ", " s))))
721 (unless (null (cdr chars))
722 (write-string ", " s)))))
723
724 ;;; COMMAND-CASE-HELP -- Internal
725 ;;;
726 ;;; Print out a help message derived from the options in a
727 ;;; random-typeout window.
728 ;;;
729 (defun command-case-help (help options)
730 (let ((help (if (listp help)
731 (apply #'format nil help) help)))
732 (with-pop-up-display (s)
733 (write-string help s)
734 (fresh-line s)
735 (do ((o options (cdr o)))
736 ((null o))
737 (let ((string (chars-to-string (caar o))))
738 (declare (simple-string string))
739 (if (= (length string) 1)
740 (write-char (char string 0) s)
741 (write-line string s))
742 (write-string " - " s)
743 (write-line (cdar o) s))))))

  ViewVC Help
Powered by ViewVC 1.1.5