diff options
author | Yuchen Pei <id@ypei.org> | 2023-09-11 00:16:05 +1000 |
---|---|---|
committer | Yuchen Pei <id@ypei.org> | 2023-09-11 00:16:05 +1000 |
commit | 87b15618c4896d61789b8bd794162c7bacc48ef7 (patch) | |
tree | c731436dfb2329881fa9d935a261a66bd7ef4149 /emacs/.emacs.d/lisp | |
parent | efc4e66a51b991a5db17b1d2f6ad3aa269b4de80 (diff) |
[emacs] gnus keys and hnreader save page to an archive dir
Default hnreader archive dir is ~/.emacs.d/hn-archive/, filename is of
the format <hacker-news-id>.org.
Diffstat (limited to 'emacs/.emacs.d/lisp')
-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 |