Find file
Fetching contributors…
Cannot retrieve contributors at this time
52 lines (45 sloc) 1.65 KB
;; Expose your running emacs to the local web by using elnode
;; Copyright (C) 2010 by Nic Ferrier
(defun insideout-html-escape (str)
"Escape significant HTML characters in 'str'"
(lambda (src)
((equal src "&") "&amp;")
((equal src "<") "&lt;")))
(defun insideout-render (buf-name)
"Render buffer 'buf' as HTML"
(with-current-buffer (get-buffer buf-name)
(format "<html>
(buffer-substring-no-properties (point-min) (point-max))))))
(defun insideout-handler (httpcon)
"Turn your emacs insideout with elnode.
This exposes all your non * buffers to localhost - so beware."
(let ((p (elnode-http-pathinfo httpcon)))
(let ((buf-name (progn
(string-match "/\\(.*\\)" p)
(match-string 1 p))))
;; An individual buffer
(elnode-http-start httpcon 200 '("Content-Type" . "text/html"))
(if (bufferp (get-buffer buf-name))
(insideout-render buf-name)
;; The buffer index
(format "<html><body><ul>%s</ul></body></html>"
(lambda (buf)
(if (not (string-match "\\*" (buffer-name buf)))
(format "<li><a href='/%s'>%s</a></li>"
(buffer-name buf)
(buffer-name buf))))
(elnode-start 'insideout-handler 8028 "localhost")
;; End