user.scm 6.7 KB

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