user.scm 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. ; Copyright (c) 1993-2008 by Richard Kelsey and Jonathan Rees. See file COPYING.
  2. ; The user's state is in two parts:
  3. ; User context - preserved across dump commands (but not by us).
  4. ; This includes the designated user and configuration environments
  5. ; and the values of a bunch of user-preference settings.
  6. ;
  7. ; Static
  8. ; command-environment
  9. ; command-syntax-table
  10. ; user-command-environment
  11. ; user-command-help
  12. ; user-environment
  13. ; config-package
  14. ; traced (?)
  15. ; file-environments
  16. ;
  17. ; Modified
  18. ; break-on-warnings?
  19. ; load-noisily?
  20. ; ask-before-loading?
  21. ;
  22. ; User session state - one per "login"; not preserved across dump commands.
  23. ; Kept in a fluid variable in the command-levels scheduler thread.
  24. ; More pedestrian threads access it via an upcall.
  25. ;
  26. ; Static
  27. ; user-context
  28. ; command input, output, and error ports
  29. ; command thread (for spawning threads)
  30. ; Modified
  31. ; focus value (##)
  32. ; batch?
  33. ; exit-status
  34. ;----------------
  35. ; User context.
  36. ;
  37. ; This is a symbol table stored in a slot in the session state (see below).
  38. ; *USER-CONTEXT-INITIALIZERS* is a list of (<name> . <initial-value-thunk>)
  39. ; pairs. The <thunk>s are called to get the initial value of the <name>d
  40. ; slots.
  41. (define (make-user-context)
  42. (let ((context (make-symbol-table)))
  43. (for-each (lambda (name+thunk)
  44. (table-set! context (car name+thunk) ((cdr name+thunk))))
  45. *user-context-initializers*)
  46. context))
  47. (define *user-context-initializers* '())
  48. ; Add a new slot to the user context.
  49. (define (user-context-accessor name initializer)
  50. (set! *user-context-initializers*
  51. (append *user-context-initializers*
  52. (list (cons name initializer))))
  53. (lambda ()
  54. (table-ref (user-context) name)))
  55. (define (user-context-modifier name)
  56. (lambda (new)
  57. (table-set! (user-context) name new)))
  58. ; Various bits of context.
  59. (define break-on-warnings? (user-context-accessor 'break-on-warnings?
  60. (lambda () #f)))
  61. (define set-break-on-warnings?! (user-context-modifier 'break-on-warnings?))
  62. (define load-noisily? (user-context-accessor 'load-noisily?
  63. (lambda () #f)))
  64. (define set-load-noisily?! (user-context-modifier 'load-noisily?))
  65. ; maximum writing depth for traces
  66. (define trace-writing-depth (user-context-accessor 'trace-writing-depth
  67. (lambda () 8)))
  68. (define set-trace-writing-depth! (user-context-modifier 'trace-writing-depth))
  69. ; maximum menu entries in inspector
  70. (define inspector-menu-limit (user-context-accessor 'inspector-menu-limit
  71. (lambda () 15)))
  72. (define set-inspector-menu-limit! (user-context-modifier 'inspector-menu-limit))
  73. ; ditto, maximum writing depth
  74. (define inspector-writing-depth (user-context-accessor 'inspector-writing-depth
  75. (lambda () 3)))
  76. (define set-inspector-writing-depth! (user-context-modifier 'inspector-writing-depth))
  77. ; ditto, maximum writing length
  78. (define inspector-writing-length (user-context-accessor 'inspector-writing-length
  79. (lambda () 5)))
  80. (define set-inspector-writing-length! (user-context-modifier 'inspector-writing-length))
  81. (define translations (user-context-accessor 'translations make-translations))
  82. (define set-translations! (user-context-modifier 'translations))
  83. ;----------------
  84. ; User session state.
  85. ;
  86. ; User information relevant to a particular session (`login').
  87. ;
  88. ; There isn't so much of this, so we just use a record.
  89. (define-record-type user-session :user-session
  90. (make-user-session command-thread
  91. user-context
  92. script-thunk repl-thunk
  93. command-input command-output command-error-output
  94. focus-object
  95. exit-status
  96. batch-mode?
  97. script-mode?)
  98. user-session?
  99. (command-thread user-session-command-thread)
  100. (repl-thunk user-session-repl-thunk)
  101. (script-thunk user-session-script-thunk)
  102. (user-context user-session-user-context)
  103. (command-input user-session-command-input)
  104. (command-output user-session-command-output)
  105. (command-error-output user-session-command-error-output)
  106. (exit-status user-session-exit-status set-user-session-exit-status!)
  107. (batch-mode? user-session-batch-mode? set-user-session-batch-mode?!)
  108. (script-mode? user-session-script-mode? set-user-session-script-mode?!)
  109. (focus-object user-session-focus-object set-user-session-focus-object!))
  110. ; Two local macros that do a bit of name mangling.
  111. ;
  112. ; (define-session-slot <name>)
  113. ; ->
  114. ; (define (<name>)
  115. ; (user-session-<name> (user-session)))
  116. ;
  117. ; (define-settable-session-slot <name>)
  118. ; ->
  119. ; (begin
  120. ; (define (<name>)
  121. ; (user-session-<name> (user-session)))
  122. ; (define (set-<name>! value)
  123. ; (set-user-session-<name>! (user-session) value)))
  124. (define-syntax define-session-slot
  125. (lambda (e r c)
  126. (let* ((name (cadr e))
  127. (sconc (lambda args
  128. (string->symbol (apply string-append args))))
  129. (read (sconc "user-session-" (symbol->string name))))
  130. `(define (,name)
  131. ;(debug-message "[u-s " ',(cadr e) "]" )
  132. (,read (user-session))))))
  133. (define-syntax define-settable-session-slot
  134. (lambda (e r c)
  135. (let* ((name (cadr e))
  136. (string-name (symbol->string name))
  137. (sconc (lambda args
  138. (string->symbol (apply string-append args))))
  139. (read (sconc "user-session-" string-name))
  140. (write (sconc "set-user-session-" string-name "!"))
  141. (write-name (caddr e)))
  142. `(begin
  143. (define (,name)
  144. ;(debug-message "[u-s " ',name "]" )
  145. (,read (user-session)))
  146. (define (,write-name value)
  147. ;(debug-message "[u-s! " ',name "]" )
  148. (,write (user-session) value))))))
  149. (define-session-slot command-thread)
  150. (define-session-slot user-context)
  151. (define-session-slot command-input)
  152. (define-session-slot command-output)
  153. (define-session-slot command-error-output)
  154. (define-settable-session-slot focus-object really-set-focus-object!)
  155. (define-settable-session-slot batch-mode? set-batch-mode?!)
  156. (define-settable-session-slot exit-status set-exit-status!)
  157. ; If we get new focus values we clear the menu, add the old focus values to
  158. ; the stack, if there is one, and actually set the focus values.
  159. (define (set-focus-object! value)
  160. (set-menu! #f)
  161. (let ((old (focus-object)))
  162. (really-set-focus-object! value)
  163. (if (and (value-stack)
  164. (not (eq? old (focus-object))))
  165. (set-value-stack! (cons old (value-stack))))))
  166. (define (pop-value-stack!)
  167. (set-menu! #f)
  168. (let ((stack (value-stack)))
  169. (set-focus-object! (car stack))
  170. (set-value-stack! (cdr stack))))