-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better environment, presentations, guile, and MIT support. #16
base: master
Are you sure you want to change the base?
Changes from all commits
27606f6
7977140
e86ce42
e5aec4d
a67e773
9548db4
233d4e2
33c5d7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,7 +136,7 @@ | |
(hash-table-ref/default *handlers* name #f)) | ||
|
||
(define (interactive-eval sexp) | ||
(let-values ((vals (eval sexp (param:environment)))) ;; TODO environment | ||
(let-values ((vals (eval sexp ($current-environment)))) | ||
vals)) | ||
|
||
(define *presentations* (make-hash-table)) | ||
|
@@ -167,14 +167,28 @@ The secondary value indicates the absence of an entry." | |
object)))) | ||
|
||
(define (replace-readtime-lookup-presented-object-or-lose string) | ||
"For presentations, emacs passes something that common lisp evals at read time. The resulting object is very different than what gerbil or gambits #. tries to do, so we do everything at run time" | ||
"For presentations, emacs passes something that common lisp evals at read time. The resulting object is very different than what gerbil or gambits #. tries to do, so strip the #. and pattern-match to evaluate this form at runtime." | ||
(let* ((pattern "#.(swank:lookup-presented-object-or-lose ") | ||
(start (string-contains string pattern))) | ||
(if start | ||
(replace-readtime-lookup-presented-object-or-lose | ||
(string-replace string "" start (+ 2 start))) | ||
string))) | ||
|
||
(define (replace-lookup-presented-object-or-lose form) | ||
(define (recons form x y) | ||
(if (and (eq? x (car form)) | ||
(eq? y (cdr form))) | ||
form | ||
(cons x y))) | ||
(if (pair? form) | ||
(if (eq? (car form) 'swank:lookup-presented-object-or-lose) | ||
(swank:lookup-presented-object-or-lose (cadr form)) | ||
(recons form | ||
(replace-lookup-presented-object-or-lose (car form)) | ||
(replace-lookup-presented-object-or-lose (cdr form)))) | ||
form)) | ||
|
||
(define last-presentation-id 0) | ||
(define (next-presentation-id) | ||
(set! last-presentation-id (+ last-presentation-id 1)) | ||
|
@@ -264,7 +278,7 @@ The secondary value indicates the absence of an entry." | |
(if (and (list? x) | ||
(eq? (car x) 'quote)) | ||
(cond ((string? (cadr x)) | ||
(cadr x)) | ||
(read-from-string (cadr x))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not really familiar with the code, but why should unquote-string return something different than a string? |
||
((eq? (cadr x) 'nil) | ||
"(user)") | ||
(else ;; TODO | ||
|
@@ -285,7 +299,8 @@ The secondary value indicates the absence of an entry." | |
(define (find-expression-containing-swank-cursor-marker expr) | ||
(define (f expr exit) | ||
(if (list? expr) | ||
(if (member '|swank::%cursor-marker%| expr) | ||
(if (or (member '|swank::%cursor-marker%| expr) | ||
(member 'swank::%cursor-marker% expr)) | ||
expr | ||
(let ((res (find (lambda (ex) | ||
(f ex exit)) | ||
|
@@ -296,17 +311,20 @@ The secondary value indicates the absence of an entry." | |
|
||
(define (highlight-at-cursor signature expr) | ||
(let* ((form (find-expression-containing-swank-cursor-marker (cdr expr))) | ||
(index (list-index (lambda (el) (eq? el '|swank::%cursor-marker%|)) form))) | ||
(index (list-index (lambda (el) | ||
(or (eq? el '|swank::%cursor-marker%|) | ||
(eq? el 'swank::%cursor-marker%))) | ||
form))) | ||
(if index | ||
(wrap-item/index (improper->proper-list signature) (- index 1) '===> '<===) | ||
'()))) | ||
|
||
(define (find-string-before-swank-cursor-marker expr) | ||
(let ((ex (find-expression-containing-swank-cursor-marker expr))) | ||
(if ex | ||
(if (string? (car ex)) | ||
(car ex) | ||
#f)))) | ||
(and ex | ||
(if (string? (car ex)) | ||
(car ex) | ||
#f)))) | ||
|
||
(define (wrap-item/index lst index before-marker after-marker) | ||
(let loop ((i 0) | ||
|
@@ -527,7 +545,7 @@ The secondary value indicates the absence of an entry." | |
(stream)))))) | ||
|
||
(define (binding-value symbol) | ||
(call/cc (lambda (k) (with-exception-handler (lambda (c) (k #f)) (lambda () (eval symbol (param:environment))))))) | ||
(call/cc (lambda (k) (with-exception-handler (lambda (c) (k #f)) (lambda () (eval symbol ($current-environment))))))) | ||
|
||
(define (object-documentation name object) | ||
(let ((doc ($binding-documentation object))) | ||
|
@@ -787,6 +805,13 @@ The secondary value indicates the absence of an entry." | |
(write-message `(:inspect ,(inspect-object object) nil nil)) | ||
#t) | ||
|
||
(define (environment-name-as-string environment) | ||
(write-to-string ($environment-name environment))) | ||
(define (package-string->environment string) | ||
(if (string=? string "COMMON-LISP-USER") | ||
(interaction-environment) | ||
($environment (read-from-string string)))) | ||
|
||
;;;; swank image support | ||
(define-record-type swank-image | ||
(make-swank-image type filename data string) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,19 +52,25 @@ | |
(write error o) | ||
(get-output-string o))) | ||
|
||
(define repl-output-port | ||
(make-soft-port | ||
(vector (lambda (c) | ||
(write-message `(:write-string ,(string c)))) | ||
(lambda (s) | ||
(write-message `(:write-string ,s))) | ||
(lambda () #f) | ||
#f | ||
(lambda () #f) | ||
#f) | ||
"w")) | ||
|
||
(define ($output-to-repl thunk) | ||
;; basic implementation, print all output at the end, this should | ||
;; be replaced with a custom output port | ||
(let ((o (open-output-string))) | ||
(with-output-to-port o (lambda () | ||
(with-error-to-port o (lambda () | ||
(let-values ((x (thunk))) | ||
(swank/write-string (get-output-string o) #f) | ||
(apply values x)))))))) | ||
(with-output-to-port repl-output-port | ||
(lambda () | ||
(with-error-to-port repl-output-port thunk)))) | ||
|
||
(define (env-name->environment env-name) | ||
;; TODO | ||
(interaction-environment)) | ||
(resolve-module env-name)) | ||
(define (environment-bindings env) | ||
(define (env-binds env) | ||
(let ((results '())) | ||
|
@@ -143,7 +149,9 @@ | |
(set! stored-frames frames) | ||
(vector->list | ||
(vector-map (lambda (fr) | ||
(format #f "~a" (frame-procedure-name fr))) | ||
(format #f "~a ~a" | ||
(frame-procedure-name fr) | ||
(frame-arguments fr))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alternatively, one can use frame-call-representation (see PR #17 ). But we can leave this change said PR. |
||
frames)))) | ||
|
||
|
||
|
@@ -183,8 +191,31 @@ | |
(define ($handle-condition exception) | ||
(invoke-sldb exception)) | ||
|
||
(define (procedure-parameters procedure) | ||
(let ((arguments (procedure-arguments procedure))) | ||
(and arguments | ||
(let ((required (cdar arguments)) | ||
(optional (cdadr arguments)) | ||
(keyword (cdaddr arguments)) | ||
(allow-other-keys? (cdar (cdddr arguments))) | ||
(rest (cdar (cddddr arguments)))) | ||
(append required | ||
(cons '#:optional optional) | ||
(cons '#:key keyword) | ||
(if allow-other-keys? | ||
(list '#:allow-other-keys?) | ||
'()) | ||
(cons '#:rest rest)))))) | ||
|
||
(define ($function-parameters-and-documentation name) | ||
(cons #f #f)) | ||
(let ((thing (module-variable (current-module) | ||
(string->symbol name)))) | ||
(if (and thing | ||
(procedure? (variable-ref thing))) | ||
(let ((procedure (variable-ref thing))) | ||
(cons (cons (string->symbol name) (procedure-parameters procedure)) | ||
(procedure-documentation procedure))) | ||
(cons #f #f)))) | ||
|
||
(define (get-valid-module-name name) | ||
(with-input-from-string name read)) | ||
|
@@ -195,8 +226,13 @@ | |
(set-current-module mod))) | ||
(list name name)) | ||
|
||
(define ($environment name) | ||
(interaction-environment)) | ||
(define ($environment-name environment) | ||
(module-name environment)) | ||
|
||
(define $environment env-name->environment) | ||
|
||
(define ($current-environment) | ||
(current-module)) | ||
|
||
(define $pretty-print pretty-print) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I see, it's an workaround until proper lookup is implemented, right? In which cases slime sends these commands? Perhaps some TODO-comments with context information would be helpful.