emac’s simple-httpd and impatient mode

I found another JavaScript CLI scheme. Skewer which I’ll get around trying sooner or later.  But I got distracted by some adjacent work. Skewer’s scheme for connecting Emac to the java interpreter so it can do remote evaluation etc is to infect the java interpreter with a bit of code that then connects into Emacs using HTTP long polling. Which is good because it works with all the browsers, and is bad because … well actually it’s pretty good. Obviously, that requires that we have a working http server inside of Emacs.

Unsurprisingly people have written http servers in emacs-lisp, one of these is simple-httpd.  It is easily installed from the Melba package repository.

So, what might you do with such a thing? I already mentioned skewer, and I see that somebody wrote a web UI for his emac’s RSS reader.   Somebody else wrote air play server. Those examples are suggestive of what other emacs apps (calc, gnus, magit, erc, etc. etc.) might do. Why? Because they can? I don’t know.

My favorite is impatient-mode, which spontaneously update a web page as you edit your buffer of, typically, html. There’s a video:

You can add filters to the refresh pipeline. So if you want your org-mode files displayed you might refine the filtering scheme. I did this, but I doubt this is the best approach.


(defun imp-htmlize-filter (buffer)
  "Alternate htmlization of BUFFER before sending to clients."
  ;; leave the result in the current-buffer
  (let ((m (with-current-buffer buffer major-mode)))
    (case m
      (org-mode
       (let ((output (current-buffer)))
         (with-current-buffer buffer
           (org-export-as-html 100 nil output))))
      (t
       (let ((html-buffer (save-match-data (htmlize-buffer buffer))))
         (insert-buffer-substring html-buffer)
         (kill-buffer html-buffer))))))

Other things (graphviz?) would be fun too.

Leave a Reply

Your email address will not be published. Required fields are marked *