From f8d7a0e267d305a841b130d2ba7a7c11e022e172 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Sat, 28 Dec 2013 13:39:29 +0100 Subject: Add hypo-get-file --- hypo.el | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/hypo.el b/hypo.el index 4770400..4a197e5 100644 --- a/hypo.el +++ b/hypo.el @@ -125,5 +125,27 @@ STATUS is ignored." (setq hypo--last-post nil) (message "Deleted %s" url))) +(defun hypo--file-shower (filename) + "Make a function to show file as FILENAME." + (lambda (status) + (ignore status) + (let* ((start (1+ (marker-position url-http-end-of-headers))) + (end (point-max)) + (contents (buffer-substring-no-properties start end)) + (buffer (generate-new-buffer filename))) + (with-current-buffer buffer + (insert contents) + (write-file (concat "/tmp/" filename)) + (goto-char (point-min))) + (kill-buffer) + (set-window-buffer nil buffer)))) + +;;;###autoload +(defun hypo-get-file (hash filename) + "Get the file HASH/FILENAME from your hypo instance." + (interactive "MHash: \nMFile: ") + (let ((url (format "%s/raw/%s/%s" hypo-instance-url hash filename))) + (url-retrieve url (hypo--file-shower filename)))) + (provide 'hypo) ;;; hypo.el ends here -- cgit v1.2.3-54-g00ecf