6eb527beb6b9

Add `in-package`
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sun, 21 Aug 2016 11:40:09 +0000
parents 60462d4304de
children b7a399c67d24
branches/tags (none)
files src/middleware/documentation.lisp src/middleware/macroexpand.lisp src/utils.lisp

Changes

--- a/src/middleware/documentation.lisp	Sat Jul 02 23:19:07 2016 +0000
+++ b/src/middleware/documentation.lisp	Sun Aug 21 11:40:09 2016 +0000
@@ -40,16 +40,18 @@
                (cons nil s)))))
     (destructuring-bind (package-name . symbol-name)
         (split-string (string-upcase name) #\:)
-      (find-symbol
-        symbol-name
-        (cond
-          ((null package-name) (parse-in-package in-package)) ; no : at all
-          ((string= "" package-name) (find-package "KEYWORD")) ; :keyw
-          (t (find-package package-name))))))) ; pack:sym
+      (let ((package
+              (cond
+                ((null package-name) (parse-in-package in-package)) ; no : at all
+                ((string= "" package-name) (find-package "KEYWORD")) ; :keyw
+                (t (find-package package-name))))) ; pack:sym
+        (when package
+          (find-symbol symbol-name package))))))
 
 
 (define-middleware wrap-documentation "documentation" message
-  (let ((s (find-symbol-harder (fset:lookup message "symbol"))))
+  (let ((s (find-symbol-harder (fset:lookup message "symbol")
+                               (fset:lookup message "in-package"))))
     (respond message
              (with-when
                  (make-map "status" '("done"))
@@ -65,9 +67,8 @@
                    (princ-to-string (cons s arglist))))))))
 
 (define-middleware wrap-arglist "arglist" message
-  (let ((s (find-symbol-harder
-             (fset:lookup message "symbol")
-             (fset:lookup message "in-package"))))
+  (let ((s (find-symbol-harder (fset:lookup message "symbol")
+                               (fset:lookup message "in-package"))))
     (respond message
              (with-when
                (make-map "status" '("done"))
--- a/src/middleware/macroexpand.lisp	Sat Jul 02 23:19:07 2016 +0000
+++ b/src/middleware/macroexpand.lisp	Sun Aug 21 11:40:09 2016 +0000
@@ -2,14 +2,15 @@
 
 (defun pretty-string (form)
   "Return a prettified string version of `form`, indented nicely."
-  #-ccl (format nil "~A" form)
-  ;; CCL's format doesn't indent forms nicely
-  #+ccl (with-output-to-string (*standard-output*)
-          (pprint form)))
+  (with-output-to-string (*standard-output*)
+    (let ((*print-pretty* t)
+          (*print-escape* t))
+      (write form))))
 
 (define-middleware wrap-macroexpand "macroexpand" message
   ;; TODO: handle mangled input
-  (let ((form (read-from-string (fset:lookup message "form"))))
+  (let* ((*package* (parse-in-package (fset:lookup message "in-package")))
+         (form (read-from-string (fset:lookup message "form"))))
     (respond message
              (make-map
                "status" '("done")
--- a/src/utils.lisp	Sat Jul 02 23:19:07 2016 +0000
+++ b/src/utils.lisp	Sun Aug 21 11:40:09 2016 +0000
@@ -76,4 +76,4 @@
 (defun parse-in-package (in-package)
   (if (null in-package)
     *package*
-    (find-package (read-from-string in-package))))
+    (or (find-package (read-from-string in-package)) *package*)))