算是 emacs-web-server 的一个小例子:
(defun docstring-server ()
(ws-start
(lambda (request)
(with-slots (process headers) request
(let* ((path (alist-get :GET headers))
(str (substring path 1))
(doc (elisp--company-doc-string str)))
(cond
(doc
(ws-response-header process 200 '("Content-type" . "text/plain; charset=utf-8"))
(process-send-string process doc))
(t
(ws-send-404
process
(if (string= str "")
"Visit http://localhost:9001/mapcar for its docstring."
(concat "No documentation for " str))))))))
9001))
然后 http://localhost:9001/mapcar 会返回 mapcar
的 docstring,我还丢进了自己的服务器上,预计随时都会挂掉,just for fun
~ $ curl -L 1.xuchunyang.me
Visit http://localhost:9001/mapcar for its docstring.
~ $ curl -L 1.xuchunyang.me/mapcar
Apply FUNCTION to each element of SEQUENCE, and make a list of the results.
~ $ curl -L 1.xuchunyang.me/cl-loop
The Common Lisp `loop' macro.
~ $