Remember that Emacs web server I wrote
back in May? Well, I got an e-mail last night from Chunye Wang
containing a patch with a variant of my dynamic lisp idea, called
"servlets" (not to be confused with Java servlets). Chunye had similar
concept for an Emacs web server for a long time, but never implemented
because Emacs lacked network functionality until recently
make-network-process in Emacs 22.1, June 2007). This
led Chunye to find my implementation.
Again, you can clone/view the code here. I turned the patch into a
series of commits,
git clone git://github.com/skeeto/emacs-http-server.git
This is some cool stuff here.
The servlets are simply functions installed under an
httpd/" namespace, where the trailing slash represents
the server root. So, the function
will be executed when "/example-servlet" is requested from the
server. The servlet runs on a temporary buffer, whose contents are
served when the servlet function returns.
To assist in HTML generation, Chunye also wrote a function to turn an
into HTML, similar to the one I described in the web server previous
post. Symbols are converted into strings, alists are attributes, and
elisp symbol indicates code to be executed, and the
results used to generate HTML. For a simple hello word,
And for some dynamic content, a die roller,
That one would be accessed from the browser with with
/roll-die" or "
Chunye provided some sample servlets that list the buffers, with links
that serve them up. There is also another servlet that will switch the
current buffer, which I find compelling. All of Emacs' functionality
is available to the servlet.
Now, to write a servlet that runs the Emacs psychiatrist ...