aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2013-12-28 13:39:29 +0100
committerGravatar Tom Willemse2013-12-28 13:39:29 +0100
commitf8d7a0e267d305a841b130d2ba7a7c11e022e172 (patch)
tree6af3b5fc91479bc3527906a39c0eb3d767e094f2
parentbdbb16b57e154ac989cc9894c77d223290a6310d (diff)
downloadhypo-emacs-f8d7a0e267d305a841b130d2ba7a7c11e022e172.tar.gz
hypo-emacs-f8d7a0e267d305a841b130d2ba7a7c11e022e172.zip
Add hypo-get-file
-rw-r--r--hypo.el22
1 files changed, 22 insertions, 0 deletions
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