aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanh Vuong <thanhvg@gmail.com>2019-08-20 01:56:03 -0600
committerThanh Vuong <thanhvg@gmail.com>2019-08-20 01:56:03 -0600
commite69a573daece1fc7e3f5a4d940a18d3f66b5a0a3 (patch)
tree875952557f225e174049f04ef1136ba5a0c12ca9
parent4754062b2c8bb9a985bf4154b66840010dc9b8c5 (diff)
wip ,
-rw-r--r--TODOs.org8
-rw-r--r--hnreader.el28
-rw-r--r--test/comments.html16
3 files changed, 37 insertions, 15 deletions
diff --git a/TODOs.org b/TODOs.org
index aa1d730..ae2d7f9 100644
--- a/TODOs.org
+++ b/TODOs.org
@@ -20,7 +20,7 @@ child
* TODO show number of child comments
https://emacs.stackexchange.com/questions/10245/counting-sub-headings-in-org-mode-using-elisp
or recursive on dom will be just fine
-* TODO run eslip on org link
+* DONE run eslip on org link
#+begin_example org-mode
[[elisp:(find-function 'describe-function)]]
@@ -28,4 +28,8 @@ or recursive on dom will be just fine
[[elisp:(hnreader-comment 20724363)][read]
-* TODO comment page show main link and intro text
+ ;; (setq-local org-confirm-elisp-link-function nil)
+
+* DONE comment page show main link and intro text
+* TODO display page takes page number
+* TODO reload page
diff --git a/hnreader.el b/hnreader.el
index bb7dbdf..5ac7aec 100644
--- a/hnreader.el
+++ b/hnreader.el
@@ -38,8 +38,8 @@ third one is 80.")
(defun hnreader--prepare-buffer (buf &optional msg)
"Print MSG message and prepare window for BUF buffer."
(when (not (equal (window-buffer) buf))
- ;; (switch-to-buffer-other-window howdoi-buffer))
- (display-buffer buf '(display-buffer-use-some-window (inhibit-same-window . t))))
+ (switch-to-buffer-other-window buf))
+ ;; (display-buffer buf '(display-buffer-use-some-window (inhibit-same-window . t))))
(with-current-buffer buf
(read-only-mode -1)
(erase-buffer)
@@ -76,15 +76,24 @@ third one is 80.")
(erase-buffer)
(insert "#+STARTUP: overview indent\n")
(cl-mapcar #'hnreader--print-frontpage-item things subtexts)
+ ;; (setq-local org-confirm-elisp-link-function nil)
(org-mode))))
+(defun hnreader--get-title (dom)
+ "Get title and link from DOM comment page."
+ (let ((a-link (dom-by-class dom "^storylink$")))
+ (cons (dom-text a-link) (dom-attr a-link 'href))))
+
(defun hnreader--print-comments (dom)
"Print DOM comment page to buffer."
- (let ((comments (dom-by-class dom "^athing comtr $")))
+ (let ((comments (dom-by-class dom "^athing comtr $"))
+ (title (hnreader--get-title dom)))
(with-current-buffer (hnreader--get-hn-comment-buffer)
(read-only-mode -1)
(erase-buffer)
(insert "#+STARTUP: overview indent\n")
+ (insert "#+TITLE: " (car title))
+ (insert "\n" (cdr title))
(dolist (comment comments)
;; (setq thanh comment)
(insert (format "%s %s\n"
@@ -104,7 +113,7 @@ third one is 80.")
(defun hnreader--get-indent (width)
"Return headline star string from WIDTH of img tag."
(let ((stars "\n*")) (dotimes (_ (round (/ width hnreader--indent)) stars)
- (setq stars (concat stars "*")))))
+ (setq stars (concat stars "*")))))
(defun hnreader--get-comment-owner (comment-dom)
"Return user who wrote this COMMENT-DOM."
@@ -124,13 +133,18 @@ third one is 80.")
(promise-catch (lambda (reason)
(message "catch error in promise prontpage: %s" reason)))))
-(defun hnreader-comment (comment-id)
- "Print hn COMMENT-ID page to buffer."
- (interactive "sQuery: ")
+(defun hnreader-promise-comment (comment-id)
+ "Promise to print hn COMMENT-ID page to buffer."
(hnreader--prepare-buffer (hnreader--get-hn-comment-buffer))
(promise-chain (hnreader--promise-dom (format "https://news.ycombinator.com/item?id=%s" comment-id))
(then #'hnreader--print-comments)
(promise-catch (lambda (reason)
(message "catch error in promise comments: %s" reason)))))
+(defun hnreader-comment (comment-id)
+ "Print hn COMMENT-ID page to buffer."
+ (interactive "sQuery: ")
+ (hnreader-promise-comment comment-id)
+ nil)
+
(provide 'hnreader)
diff --git a/test/comments.html b/test/comments.html
index 33c95a1..53ba18d 100644
--- a/test/comments.html
+++ b/test/comments.html
@@ -50,12 +50,16 @@
<div class='votearrow' title='upvote'></div>
</a></center>
</td>
- <td class="title"><a
- href="http://geosci.uchicago.edu/~kite/doc/von_Neumann_1955.pdf"
- class="storylink">Can we survive technology? (1955)
- [pdf]</a><span class="sitebit comhead"> (<a
- href="from?site=uchicago.edu"><span
- class="sitestr">uchicago.edu</span></a>)</span></td>
+ <td class="title">
+ <a href="http://geosci.uchicago.edu/~kite/doc/von_Neumann_1955.pdf"
+ class="storylink">
+ Can we survive technology? (1955) [pdf]
+ </a>
+ <span class="sitebit comhead">
+ (
+ <a href="from?site=uchicago.edu"><span class="sitestr">uchicago.edu</span></a>
+ )
+ </span></td>
</tr>
<tr>
<td colspan="2"></td>