diff options
author | Thanh Vuong <thanhvg@gmail.com> | 2019-08-22 00:34:16 -0600 |
---|---|---|
committer | Thanh Vuong <thanhvg@gmail.com> | 2019-08-22 00:34:16 -0600 |
commit | 55106f3bc78cc39cb95f7183f87f35d6b2abc60f (patch) | |
tree | 2c57fb1200e472a01fa9bd5122b8144819abd04e | |
parent | 7569b8f7d993862f04ad6482bcee967b310bff38 (diff) |
wip wip
-rw-r--r-- | TODOs.org | 10 | ||||
-rw-r--r-- | hnreader.el | 61 |
2 files changed, 55 insertions, 16 deletions
@@ -22,7 +22,8 @@ https://emacs.stackexchange.com/questions/10245/counting-sub-headings-in-org-mod or recursive on dom will be just fine don't know about the performance impact -* TODO run eslip on org link +* DONE run eslip on org link +CLOSED: [2019-08-21 Wed 23:46] #+begin_example org-mode [[elisp:(find-function 'describe-function)]] @@ -55,11 +56,10 @@ autoload? just a private flag on running * DONE comment page show main link and intro text -* TODO display page takes page number +* DONE display page takes page number * TODO reload page -* TODO frontpage has next page link +* DONE frontpage has next page link * DONE remove * in text -CLOSED: [2019-08-20 Tue 13:39] find and replace raw htlm '>*' with '>-' * add eww link * TODO long links are cut off @@ -84,3 +84,5 @@ Assuming the current buffer is an org-mode buffer, the following code collects p #+end_example In an org buffer, (org-element-parse-buffer) returns the parse tree of the current buffer. And you can map over it with org-element-map. +* DONE first run on comment buffer won't have right width +also need to shadow shr-use-fonts to nil diff --git a/hnreader.el b/hnreader.el index 4dfc91f..e5150b3 100644 --- a/hnreader.el +++ b/hnreader.el @@ -5,18 +5,18 @@ (require 'dom) (require 'cl-lib) -(defvar hn--buffer "*HN*" +(defvar hnreader--buffer "*HN*" "Buffer for HN pages.") -(defvar hn--comment-buffer "*HNComments*") +(defvar hnreader--comment-buffer "*HNComments*") (defun hnreader--get-hn-buffer () "Get hn buffer." - (get-buffer-create hn--buffer)) + (get-buffer-create hnreader--buffer)) (defun hnreader--get-hn-comment-buffer () "Get hn commnet buffer." - (get-buffer-create hn--comment-buffer)) + (get-buffer-create hnreader--comment-buffer)) (defvar hnreader--indent 40 "Tab value which is the width of an indent. @@ -73,6 +73,13 @@ third one is 80.") id id)) )) +(defun hnreader--get-morelink (dom) + "Get more link from DOM." + (let ((more-link (dom-by-class dom "morelink"))) + ;; (setq thanh more-link) + (format "\n* [[elisp:(hnreader-read-page \"https://news.ycombinator.com/%s\")][More]]" + (dom-attr more-link 'href)))) + (defun hnreader--print-frontpage (dom buf) "Print raw DOM on BUF." (let ((things (dom-by-class dom "^athing$")) @@ -83,8 +90,10 @@ third one is 80.") (insert "#+STARTUP: overview indent\n") (cl-mapcar #'hnreader--print-frontpage-item things subtexts) ;; (setq-local org-confirm-elisp-link-function nil) + (insert (hnreader--get-morelink dom)) (org-mode) - (goto-line 3)))) + (goto-char (point-min)) + (forward-line 2)))) (defun hnreader--get-title (dom) "Get title and link from DOM comment page." @@ -108,11 +117,13 @@ third one is 80.") (hnreader--get-indent (hnreader--get-img-tag-width comment)) (hnreader--get-comment-owner comment))) - (let ((shr-width 80)) + (let ((shr-width 80) + (shr-use-fonts nil)) (shr-insert-document (hnreader--get-comment comment)))) (org-mode) (org-shifttab 3) - (goto-line 3)))) + (goto-char (point-min)) + (forward-line 2)))) (defun hnreader--get-img-tag-width (comment-dom) "Get width attribute of img tag in COMMENT-DOM." @@ -133,16 +144,42 @@ third one is 80.") "Get comment dom from COMMENT-DOM." (dom-by-class comment-dom "^commtext")) -(defun hnreader-frontpage () - "Testing." - (interactive) +(defun hnreader-readpage-promise (url) + "Promise HN URL." (hnreader--prepare-buffer (hnreader--get-hn-buffer)) - (promise-chain (hnreader--promise-dom "https://news.ycombinator.com/news") + (promise-chain (hnreader--promise-dom url) (then (lambda (result) (hnreader--print-frontpage result (hnreader--get-hn-buffer)))) (promise-catch (lambda (reason) (message "catch error in promise prontpage: %s" reason))))) +(defun hnreader-read-page (url) + "Print HN URL page." + (interactive "sLink: ") + (message url) + (hnreader-readpage-promise url) + nil) + +(defun hnreader-front() + "Read front page." + (interactive) + (hnreader-read-page "https://news.ycombinator.com/news")) + +(defun hnreader-ask () + "Read ask page." + (interactive) + (hnreader-read-page "https://news.ycombinator.com/ask")) + +(defun hnreader-show () + "Read show page." + (interactive) + (hnreader-read-page "https://news.ycombinator.com/show")) + +(defun hnreader-jobs () + "Read jobs page." + (interactive) + (hnreader-read-page "https://news.ycombinator.com/jobs")) + (defun hnreader-promise-comment (comment-id) "Promise to print hn COMMENT-ID page to buffer." (hnreader--prepare-buffer (hnreader--get-hn-comment-buffer)) @@ -153,7 +190,7 @@ third one is 80.") (defun hnreader-comment (comment-id) "Print hn COMMENT-ID page to buffer." - (interactive "sQuery: ") + (interactive "sComment ID: ") (hnreader-promise-comment comment-id) nil) |