2005-05-25 11:18:26 -04:00
|
|
|
(define footer-length 0)
|
2005-05-24 09:57:56 -04:00
|
|
|
|
2005-05-25 11:18:26 -04:00
|
|
|
(define (make-inspector-selection-list num-cols num-lines focus-obj)
|
|
|
|
(let ((menu (prepare-menu focus-obj)))
|
|
|
|
(make-select-list
|
2005-05-27 04:01:24 -04:00
|
|
|
(map (lambda (e)
|
2005-09-27 12:29:34 -04:00
|
|
|
(make-unmarked-text-element
|
2005-05-27 04:01:24 -04:00
|
|
|
(cdr e) #t (layout-menu-entry num-cols e)))
|
|
|
|
menu)
|
2005-05-25 11:18:26 -04:00
|
|
|
num-lines)))
|
|
|
|
|
|
|
|
(define (make-header focus-obj num-cols)
|
2005-06-02 15:02:04 -04:00
|
|
|
(cons (val-to-string focus-obj num-cols)
|
|
|
|
(maybe-source focus-obj #f)))
|
|
|
|
; (if (exception-continuation? focus-obj)
|
|
|
|
; "Press cont-down key to see more"
|
|
|
|
; "")))
|
|
|
|
|
|
|
|
(define (header-length header)
|
|
|
|
(length header))
|
|
|
|
|
|
|
|
(define (set-header-message! header msg)
|
|
|
|
(if (null? (cdr header))
|
|
|
|
(set-cdr! header (list msg))
|
|
|
|
(begin
|
|
|
|
(set-car! (cdr header) msg)
|
|
|
|
(set-cdr! (cdr header) '()))))
|
2005-05-25 11:18:26 -04:00
|
|
|
|
|
|
|
(define (layout-menu-entry num-cols entry)
|
|
|
|
(let ((head (format #f "[~a]" (or (car entry) ""))))
|
|
|
|
(string-append head (val-to-string (cdr entry)
|
|
|
|
(- num-cols (string-length head))))))
|
|
|
|
|
2005-06-02 15:02:04 -04:00
|
|
|
(define *write-depth* 3)
|
|
|
|
(define *write-length* 5)
|
|
|
|
|
2005-05-25 11:18:26 -04:00
|
|
|
(define (val-to-string val max-length)
|
|
|
|
(let ((out (open-output-string)))
|
|
|
|
(limited-write val
|
|
|
|
out
|
2005-06-02 15:02:04 -04:00
|
|
|
*write-depth*
|
|
|
|
*write-length*)
|
2005-05-25 11:18:26 -04:00
|
|
|
(let ((str (get-output-string out)))
|
|
|
|
(substring str 0 (min (string-length str) max-length)))))
|
|
|
|
|
2005-06-01 08:55:29 -04:00
|
|
|
(define (prepare-selection-for-scheme-mode file-names)
|
2005-09-27 04:46:34 -04:00
|
|
|
(string-append "'" (write-to-string file-names)))
|
2005-06-01 08:55:29 -04:00
|
|
|
|
2005-06-02 15:02:04 -04:00
|
|
|
(define (continuation-debug-data thing)
|
|
|
|
(template-debug-data (continuation-template thing)))
|
|
|
|
|
|
|
|
|
|
|
|
; Exception continuations don't have source, so we get the source from
|
|
|
|
; the next continuation if it is from the same procedure invocation.
|
|
|
|
|
|
|
|
(define (maybe-source thing exception?)
|
|
|
|
(cond ((not (continuation? thing))
|
|
|
|
'())
|
|
|
|
((exception-continuation? thing)
|
|
|
|
(let ((next (continuation-cont thing)))
|
|
|
|
(if (not (eq? next (continuation-parent thing)))
|
|
|
|
(maybe-source next #t)
|
|
|
|
'())))
|
|
|
|
(else
|
|
|
|
(let ((dd (continuation-debug-data thing)))
|
|
|
|
(if dd
|
|
|
|
(let ((source (assoc (continuation-pc thing)
|
|
|
|
(debug-data-source dd))))
|
|
|
|
(if source
|
|
|
|
(maybe-source-info (cdr source) exception?)
|
|
|
|
'()))
|
|
|
|
'())))))
|
|
|
|
|
|
|
|
; Show the source code for a continuation, if we have it.
|
|
|
|
|
|
|
|
(define (maybe-source-info info exception?)
|
|
|
|
(if (pair? info)
|
|
|
|
(let ((i (car info))
|
|
|
|
(exp (cdr info)))
|
|
|
|
(if (and (integer? i) (list? exp))
|
|
|
|
(let ((out1 (open-output-string))
|
|
|
|
(out2 (open-output-string)))
|
|
|
|
(display (if exception?
|
|
|
|
"Next call is "
|
|
|
|
"Waiting for ")
|
|
|
|
out1)
|
|
|
|
(limited-write (list-ref exp i) out1
|
|
|
|
*write-depth* *write-length*)
|
|
|
|
(display " in " out2)
|
|
|
|
(limited-write (append (sublist exp 0 i)
|
|
|
|
(list '^^^)
|
|
|
|
(list-tail exp (+ i 1)))
|
|
|
|
out2
|
|
|
|
*write-depth* *write-length*)
|
|
|
|
(list (get-output-string out1)
|
|
|
|
(get-output-string out2)))
|
|
|
|
'()))
|
|
|
|
'()))
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-05-24 09:57:56 -04:00
|
|
|
(define (inspect-value val)
|
2005-05-25 11:18:26 -04:00
|
|
|
(error "not yet"))
|
2005-05-24 09:57:56 -04:00
|
|
|
|
|
|
|
(define key-d 100)
|
|
|
|
(define key-u 117)
|
2005-06-01 08:55:29 -04:00
|
|
|
(define key-return 10)
|
2005-05-24 09:57:56 -04:00
|
|
|
|
|
|
|
(define down-key key-d)
|
|
|
|
(define up-key key-u)
|
2005-06-01 08:55:29 -04:00
|
|
|
(define inspect-key key-return)
|
2005-05-24 09:57:56 -04:00
|
|
|
|
2005-05-31 09:15:31 -04:00
|
|
|
(define (make-inspector focus-obj buffer)
|
|
|
|
(let* ((num-cols (result-buffer-num-cols buffer))
|
|
|
|
(num-lines (result-buffer-num-lines buffer))
|
|
|
|
(val focus-obj)
|
|
|
|
(stack '())
|
|
|
|
(header (make-header focus-obj num-cols))
|
|
|
|
(num-cols num-cols)
|
|
|
|
(num-lines num-lines)
|
|
|
|
(selection-list
|
|
|
|
(make-inspector-selection-list num-cols
|
2005-06-02 15:02:04 -04:00
|
|
|
(- num-lines (header-length header))
|
2005-05-31 09:15:31 -04:00
|
|
|
focus-obj)))
|
|
|
|
|
2005-06-01 08:55:29 -04:00
|
|
|
(define (push-val! new)
|
2005-06-02 15:02:04 -04:00
|
|
|
(set! header (make-header new num-cols))
|
|
|
|
(set! stack (cons val stack))
|
2005-06-01 08:55:29 -04:00
|
|
|
(set! val new)
|
|
|
|
(set! selection-list
|
|
|
|
(make-inspector-selection-list
|
|
|
|
num-cols
|
2005-06-02 15:02:04 -04:00
|
|
|
(- num-lines (header-length header))
|
2005-06-01 08:55:29 -04:00
|
|
|
new)))
|
|
|
|
|
2005-05-31 09:15:31 -04:00
|
|
|
(define (inspect-next-continuation)
|
|
|
|
(if (continuation? val)
|
2005-06-01 08:55:29 -04:00
|
|
|
(push-val! (continuation-parent val))
|
2005-06-02 15:02:04 -04:00
|
|
|
(set-header-message! header
|
2005-05-31 09:15:31 -04:00
|
|
|
"Can't go down from a non-continuation.")))
|
|
|
|
|
2005-06-01 08:55:29 -04:00
|
|
|
(define (pop-val!)
|
2005-05-31 09:15:31 -04:00
|
|
|
(if (null? stack)
|
2005-06-02 15:02:04 -04:00
|
|
|
(set-header-message! header "Can't go up from here.")
|
2005-06-01 08:55:29 -04:00
|
|
|
(begin
|
2005-05-31 09:15:31 -04:00
|
|
|
(set! val (car stack))
|
2005-06-01 08:55:29 -04:00
|
|
|
(set! header (make-header val num-cols))
|
2005-05-31 09:15:31 -04:00
|
|
|
(set! stack (cdr stack))
|
|
|
|
(set! selection-list
|
|
|
|
(make-inspector-selection-list
|
|
|
|
num-cols
|
2005-06-02 15:02:04 -04:00
|
|
|
(- num-lines (header-length header))
|
2005-05-31 09:15:31 -04:00
|
|
|
val)))))
|
|
|
|
|
2005-07-06 04:57:44 -04:00
|
|
|
(define (get-selection-as-ref self focus-object-table)
|
2005-09-27 04:08:15 -04:00
|
|
|
(let ((marked (select-list-get-marked selection-list))
|
2005-06-01 08:55:29 -04:00
|
|
|
(make-reference (lambda (obj)
|
|
|
|
(make-focus-object-reference
|
|
|
|
focus-object-table obj))))
|
|
|
|
(if (null? marked)
|
2005-09-27 04:46:34 -04:00
|
|
|
(write-to-string
|
2005-06-01 08:55:29 -04:00
|
|
|
(make-reference (select-list-selected-entry selection-list)))
|
|
|
|
(string-append
|
|
|
|
"(list "
|
2005-09-27 04:46:34 -04:00
|
|
|
(string-join (map write-to-string (map make-reference marked)))
|
2005-06-01 08:55:29 -04:00
|
|
|
")"))))
|
|
|
|
|
2005-07-06 04:57:44 -04:00
|
|
|
(define (get-selection-as-text self for-scheme-mode? focus-object-table)
|
2005-06-01 08:55:29 -04:00
|
|
|
(if for-scheme-mode?
|
2005-09-27 04:08:15 -04:00
|
|
|
(let ((marked (select-list-get-marked selection-list)))
|
2005-06-01 08:55:29 -04:00
|
|
|
(prepare-selection-for-scheme-mode marked))
|
|
|
|
""))
|
|
|
|
|
2005-05-31 09:15:31 -04:00
|
|
|
(lambda (message)
|
|
|
|
(case message
|
|
|
|
((paint)
|
|
|
|
(lambda (self win result-buffer have-focus?)
|
2005-06-02 15:02:04 -04:00
|
|
|
(let ((hdr-len (header-length header)))
|
2005-05-31 09:15:31 -04:00
|
|
|
(for-each (lambda (text y)
|
|
|
|
(mvwaddstr win y 0 text))
|
|
|
|
header
|
|
|
|
(iota hdr-len))
|
|
|
|
(paint-selection-list-at
|
|
|
|
selection-list
|
|
|
|
0 hdr-len
|
|
|
|
win result-buffer have-focus?))))
|
|
|
|
((key-press)
|
|
|
|
(lambda (self key control-x-pressed?)
|
|
|
|
(cond
|
|
|
|
((= key down-key)
|
|
|
|
(inspect-next-continuation))
|
|
|
|
((= key up-key)
|
2005-06-01 08:55:29 -04:00
|
|
|
(pop-val!))
|
|
|
|
((= key inspect-key)
|
|
|
|
(push-val! (select-list-selected-entry selection-list)))
|
2005-05-31 09:15:31 -04:00
|
|
|
(else
|
|
|
|
(set! selection-list
|
|
|
|
(select-list-handle-key-press
|
|
|
|
selection-list key))))
|
|
|
|
self))
|
2005-07-06 04:57:44 -04:00
|
|
|
((get-selection-as-ref)
|
|
|
|
get-selection-as-ref)
|
|
|
|
((get-selection-as-text)
|
|
|
|
get-selection-as-text)
|
2005-06-01 08:55:29 -04:00
|
|
|
(else
|
|
|
|
(debug-message "inspector did not handle message " message))))))
|
2005-05-24 09:57:56 -04:00
|
|
|
|
|
|
|
(register-plugin!
|
2005-05-31 09:15:31 -04:00
|
|
|
(make-view-plugin make-inspector exception-continuation?))
|