user.scm 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 condition-writing-depth (user-context-accessor 'condition-writing-depth
  82. (lambda () 5)))
  83. (define set-condition-writing-depth! (user-context-modifier 'condition-writing-depth))
  84. (define condition-writing-length (user-context-accessor 'condition-writing-length
  85. (lambda () 6)))
  86. (define set-condition-writing-length! (user-context-modifier 'condition-writing-length))
  87. (define translations (user-context-accessor 'translations make-translations))
  88. (define set-translations! (user-context-modifier 'translations))
  89. ;----------------
  90. ; User session state.
  91. ;
  92. ; User information relevant to a particular session (`login').
  93. ;
  94. ; There isn't so much of this, so we just use a record.
  95. (define-record-type user-session :user-session
  96. (make-user-session command-thread
  97. user-context
  98. script-thunk repl-thunk
  99. command-input command-output command-error-output
  100. focus-object
  101. exit-status
  102. batch-mode?
  103. script-mode?)
  104. user-session?
  105. (command-thread user-session-command-thread)
  106. (repl-thunk user-session-repl-thunk)
  107. (script-thunk user-session-script-thunk)
  108. (user-context user-session-user-context)
  109. (command-input user-session-command-input)
  110. (command-output user-session-command-output)
  111. (command-error-output user-session-command-error-output)
  112. (exit-status user-session-exit-status set-user-session-exit-status!)
  113. (batch-mode? user-session-batch-mode? set-user-session-batch-mode?!)
  114. (script-mode? user-session-script-mode? set-user-session-script-mode?!)
  115. (focus-object user-session-focus-object set-user-session-focus-object!))
  116. ; Two local macros that do a bit of name mangling.
  117. ;
  118. ; (define-session-slot <name>)
  119. ; ->
  120. ; (define (<name>)
  121. ; (user-session-<name> (user-session)))
  122. ;
  123. ; (define-settable-session-slot <name>)
  124. ; ->
  125. ; (begin
  126. ; (define (<name>)
  127. ; (user-session-<name> (user-session)))
  128. ; (define (set-<name>! value)
  129. ; (set-user-session-<name>! (user-session) value)))
  130. (define-syntax define-session-slot
  131. (lambda (e r c)
  132. (let* ((name (cadr e))
  133. (sconc (lambda args
  134. (string->symbol (apply string-append args))))
  135. (read (sconc "user-session-" (symbol->string name))))
  136. `(define (,name)
  137. ;(debug-message "[u-s " ',(cadr e) "]" )
  138. (,read (user-session))))))
  139. (define-syntax define-settable-session-slot
  140. (lambda (e r c)
  141. (let* ((name (cadr e))
  142. (string-name (symbol->string name))
  143. (sconc (lambda args
  144. (string->symbol (apply string-append args))))
  145. (read (sconc "user-session-" string-name))
  146. (write (sconc "set-user-session-" string-name "!"))
  147. (write-name (caddr e)))
  148. `(begin
  149. (define (,name)
  150. ;(debug-message "[u-s " ',name "]" )
  151. (,read (user-session)))
  152. (define (,write-name value)
  153. ;(debug-message "[u-s! " ',name "]" )
  154. (,write (user-session) value))))))
  155. (define-session-slot command-thread)
  156. (define-session-slot user-context)
  157. (define-session-slot command-input)
  158. (define-session-slot command-output)
  159. (define-session-slot command-error-output)
  160. (define-settable-session-slot focus-object really-set-focus-object!)
  161. (define-settable-session-slot batch-mode? set-batch-mode?!)
  162. (define-settable-session-slot exit-status set-exit-status!)
  163. ; If we get new focus values we clear the menu, add the old focus values to
  164. ; the stack, if there is one, and actually set the focus values.
  165. (define (set-focus-object! value)
  166. (set-menu! #f)
  167. (let ((old (focus-object)))
  168. (really-set-focus-object! value)
  169. (if (and (value-stack)
  170. (not (eq? old (focus-object))))
  171. (set-value-stack! (cons old (value-stack))))))
  172. (define (pop-value-stack!)
  173. (set-menu! #f)
  174. (let ((stack (value-stack)))
  175. (set-focus-object! (car stack))
  176. (set-value-stack! (cdr stack))))