# HG changeset patch # User Steve Losh # Date 1460236406 0 # Node ID 3e9db801d234da2b706d4b7872f4d402200ed22a # Parent 9cf977a17d89ca2ba870f2df1f5007afcf8f0caf Clean up some of the middleware code diff -r 9cf977a17d89 -r 3e9db801d234 src/middleware/core.lisp --- a/src/middleware/core.lisp Sat Apr 09 21:04:26 2016 +0000 +++ b/src/middleware/core.lisp Sat Apr 09 21:13:26 2016 +0000 @@ -5,12 +5,17 @@ (defmacro handle-op (message op fallback &rest body) `(if (equal ,op (fset:lookup ,message "op")) - (progn ,@body) - (funcall ,fallback ,message))) + (progn ,@body) + (funcall ,fallback ,message))) -(defmacro define-middleware (name op message-binding &rest body) +(defmacro define-middleware (name op message-binding &body body) + "Define a middleware at the symbol `name` to handle `op`. + + As the body is executing `message-binding` will be bound to the message map. + + " (let ((fallback (gensym))) - `(defun ,name (,fallback) - (lambda (,message-binding) - (handle-op ,message-binding ,op ,fallback - ,@body))))) + `(defun ,name (,fallback) + (lambda (,message-binding) + (handle-op ,message-binding ,op ,fallback + ,@body))))) diff -r 9cf977a17d89 -r 3e9db801d234 src/middleware/describe.lisp --- a/src/middleware/describe.lisp Sat Apr 09 21:04:26 2016 +0000 +++ b/src/middleware/describe.lisp Sat Apr 09 21:13:26 2016 +0000 @@ -9,9 +9,11 @@ (define-middleware wrap-describe "describe" message (respond message (make-map "status" '("done") + ;; TODO: find actual versions "versions" (make-map "lisp" (make-version-map 0 0 0) "cl-nrepl" (make-version-map 0 0 0)) + ;; TODO: fill in supported ops "ops" (make-map)))) diff -r 9cf977a17d89 -r 3e9db801d234 src/middleware/documentation.lisp --- a/src/middleware/documentation.lisp Sat Apr 09 21:04:26 2016 +0000 +++ b/src/middleware/documentation.lisp Sat Apr 09 21:13:26 2016 +0000 @@ -20,21 +20,18 @@ t) (values nil nil))) - (defun find-symbol-harder (name) "Return the symbol object with the given `name`. - This should work with: + This should work with names like: FOO (assumes the current package) P:FOO (looks in package P) - TODO: add support for: - - P::FOO - :KEYWORD - " + ;; TODO: add support for: + ;; P::FOO + ;; :KEYWORD (flet ((split-string (s delim) (let ((idx (position delim s))) (if idx @@ -46,6 +43,7 @@ (find-package pack) *package*))))) + (define-middleware wrap-documentation "documentation" message (let ((s (find-symbol-harder (fset:lookup message "symbol")))) (respond message