(require 'url) (require 'htmlize)
(defvar rwd-paste-http-destination
"http://p.zenspider.com"
"Publicly-accessible (via HTTP) location for pasted files.")
(defvar rwd-paste-destination
"~/Sites/pastes/"
"Directory corresponding to `rwd-paste-http-destination'.
You must have write-access to this directory.")
(defvar rwd-paste-sync-command
"cd ~/Sites; ./sync.sh"
"The command to use to sync to your paste website")
(defvar rwd-paste-footer
(concat "<p style='font-size: 8pt; font-family: monospace;'>Generated by "
user-full-name
" using <a href='"
rwd-paste-http-destination
"'>rwd-paste</a> at %s "
(cadr (current-time-zone)) ".</p>")
"HTML message to place at the bottom of each file.")
(defun rwd-paste (original-name)
"Paste the current buffer to `rwd-paste-http-destination'."
(interactive "MName (defaults to buffer name): ")
(let* ((b (htmlize-buffer))
(name (url-hexify-string (if (equal "" original-name)
(buffer-name)
original-name)))
(full-url (concat rwd-paste-http-destination "/" name ".html"))
(destination (concat rwd-paste-destination "/" name ".html")))
(save-excursion
(switch-to-buffer b)
(search-forward " </body>\n</html>")
(insert (format rwd-paste-footer (current-time-string)))
(write-file destination)
(kill-buffer b))
(message "syncing...")
(shell-command rwd-paste-sync-command)
(kill-new full-url)
(message "Pasted to %s (on kill ring)" full-url)))
(defun rwd-paste-index ()
"Generate an index of all existing pastes on server on the splash page."
(interactive)
(let ((dest-parts (split-string rwd-paste-destination ":")))
(eshell-command (concat "ssh " (car dest-parts) " ls " (cadr dest-parts)))
(save-excursion
(switch-to-buffer "*EShell Command Output*")
(flush-lines "^Password: $" (point-min) (point-max))
(flush-lines "private" (point-min) (point-max))
(let ((file-list (split-string (buffer-string) "\n")))
(with-temp-buffer
(insert-file-contents "~/.emacs.d/rwd-paste.el") (goto-char (point-min))
(search-forward ";;; Commentary")
(previous-line)
(insert "\n;;; Pasted Files\n\n")
(mapcar (lambda (file) (insert (concat ";; * <" rwd-paste-http-destination "/" file ">\n"))) file-list)
(emacs-lisp-mode) (font-lock-fontify-buffer) (rename-buffer "rwd-paste")
(rwd-paste "index")))
(ignore-errors (kill-buffer "*EShell Command Output*")))))
(provide 'rwd-paste)