Created
August 11, 2012 06:25
-
-
Save mogigoma/3321806 to your computer and use it in GitHub Desktop.
A hack to publish any buffer exactly as it appears in Emacs on demand over HTTP.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defvar mak/elnode-publish-port | |
4444 | |
"The port for published buffers to be served on.") | |
(defvar mak/elnode-publish-buffers | |
(make-hash-table :test 'equal) | |
"List of the buffers to publish over HTTP.") | |
(defun mak/elnode-publish-handler (httpcon) | |
"Handler for buffers published by Elnode." | |
(let* ((path (substring (url-unhex-string (elnode-http-pathinfo httpcon)) 1)) | |
(name (gethash path mak/elnode-publish-buffers))) | |
(if name | |
(progn | |
(elnode-http-start httpcon 200 '("Content-Type" . "text/html")) | |
(elnode-http-return | |
httpcon | |
(with-current-buffer | |
(htmlize-buffer name) | |
(buffer-string)))) | |
(progn | |
(elnode-http-start httpcon 404 '("Content-Type" . "text/plain")) | |
(elnode-http-return | |
httpcon | |
(format "'%s' is not in the list of published buffers." path)))))) | |
(defun mak/elnode-publish-buffer (buffer url) | |
"Publish a buffer through Elnode." | |
(interactive "bBuffer name: \nMURL: ") | |
(puthash url buffer mak/elnode-publish-buffers)) | |
(defun mak/elnode-unpublish-buffer (buffer) | |
"Unpublish a buffer through Elnode." | |
(interactive "MURL: ") | |
(remhash buffer mak/elnode-publish-buffers)) | |
(defun mak/elnode-publish-start () | |
"Start listening for requests for published buffers." | |
(interactive) | |
(when (y-or-n-p "Start publishing buffers? ") | |
(elnode-start 'mak/elnode-publish-handler :port mak/elnode-publish-port :host "*"))) | |
(defun mak/elnode-publish-stop () | |
"Stop listening for requests for published buffers." | |
(interactive) | |
(when (y-or-n-p "Stop publishing buffers? ") | |
(elnode-stop mak/elnode-publish-port))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
servers don't get fragments do they?
I will update the readme in the REPO with information about the other bits.