diff options
Diffstat (limited to 'emacs/.emacs.d/lisp/my')
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-hnreader.el | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-hnreader.el b/emacs/.emacs.d/lisp/my/my-hnreader.el index 761fad6..9f31200 100644 --- a/emacs/.emacs.d/lisp/my/my-hnreader.el +++ b/emacs/.emacs.d/lisp/my/my-hnreader.el @@ -80,11 +80,12 @@ (let ((comments (dom-by-class dom "^athing comtr$")) (title (hnreader--get-title dom)) (info (hnreader--get-post-info dom)) - (more-link (dom-by-class dom "morelink"))) - (with-current-buffer (hnreader--get-hn-comment-buffer) + (more-link (dom-by-class dom "morelink")) + (buffer (my-hnreader-buffer url))) + (with-current-buffer buffer (read-only-mode -1) (erase-buffer) - (insert "-*-Org-*-\n") + (insert "-*- org -*-\n") (insert "#+TITLE: " (car title)) (insert (format "\n%s\n" (cdr title))) (insert (car info)) @@ -101,10 +102,22 @@ (insert "\n* " (format "[[elisp:(hnreader-comment \"%s\")][More]]" (concat "https://news.ycombinator.com/" (dom-attr more-link 'href))))) (insert "\n* " (format "[[elisp:(hnreader-comment \"%s\")][Reload]]" url)) - (org-mode) - ;; (org-shifttab 3) (goto-char (point-min)) - (forward-line 2)))) + (forward-line 2) + (save-buffer)) + (switch-to-buffer buffer))) + +(defvar my-hnreader-save-dir (locate-user-emacs-file "hn-archive") + "The directory to save hnreader org files.") + +(defun my-hnreader-buffer (url) + "Return file name to save to for URL." + (if (string-match + "https://news\\.ycombinator\\.com/item\\?id=\\([0-9]+\\)" url) + (find-file-noselect + (expand-file-name (format "%s.org" (match-string 1 url)) + my-hnreader-save-dir)) + (error "URL %s not supported." url))) (provide 'my-hnreader) ;;; my-hnreader.el ends here |