aboutsummaryrefslogtreecommitdiff
path: root/emacs/.emacs.d
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/.emacs.d')
-rw-r--r--emacs/.emacs.d/lisp/my/reddio.el49
1 files changed, 38 insertions, 11 deletions
diff --git a/emacs/.emacs.d/lisp/my/reddio.el b/emacs/.emacs.d/lisp/my/reddio.el
index 2198e43..f8bc77f 100644
--- a/emacs/.emacs.d/lisp/my/reddio.el
+++ b/emacs/.emacs.d/lisp/my/reddio.el
@@ -28,19 +28,46 @@
(defvar reddio-buffer "*reddio*")
-(defun reddio-open-url (url)
- (interactive "sReddit link: ")
- (when (string-match "/\\(comments/[^/]+\\)/" url)
- (with-current-buffer (get-buffer-create reddio-buffer)
+(defvar reddio-dir (locate-user-emacs-file "reddio")
+ "Path to local directory of saved threads.")
+
+(defun reddio-make-filename (url)
+ (string-match "/r/\\([^/]+\\)/comments/\\([^/]+\\)/\\([^/]+\\)" url)
+ (file-name-concat
+ reddio-dir
+ (format "%s.%s.%s.txt"
+ (match-string 1 url)
+ (match-string 3 url)
+ (match-string 2 url))))
+
+(defun reddio-save-text-and-switch-to-buffer (text file-name)
+ "Save TEXT to FILE-NAME and switch to buffer."
+ (let ((buffer (find-file-noselect file-name))
+ (coding-system-for-write 'utf-8))
+ (with-current-buffer buffer
(let ((inhibit-read-only t))
(erase-buffer)
- (when (= 0 (call-process "reddio" nil reddio-buffer nil "print"
- (match-string 1 url)))
- (goto-char (point-min)))
- (delete-trailing-whitespace))
- (text-mode)
- (view-mode))
- (display-buffer reddio-buffer)))
+ (insert text))
+ (goto-char (point-min))
+ (save-buffer)
+ (revert-buffer t t))
+ (switch-to-buffer buffer)))
+
+(defun reddio-open-url (url)
+ (interactive "sReddit link: ")
+ (let ((text
+ (when (string-match "/\\(comments/[^/]+\\)/" url)
+ (with-temp-buffer
+ (if (= 0 (call-process "reddio" nil (current-buffer) nil
+ "print" "-l" "500"
+ (match-string 1 url)))
+ (goto-char (point-min))
+ (error "reddio process failed: %s" (buffer-string)))
+ (delete-trailing-whitespace)
+ (buffer-string)))))
+ (reddio-save-text-and-switch-to-buffer
+ text
+ (reddio-make-filename url))))
(defun reddio-reddit-url-p (url)
"e.g.