From e69a573daece1fc7e3f5a4d940a18d3f66b5a0a3 Mon Sep 17 00:00:00 2001 From: Thanh Vuong Date: Tue, 20 Aug 2019 01:56:03 -0600 Subject: wip , --- TODOs.org | 8 ++++++-- hnreader.el | 28 +++++++++++++++++++++------- test/comments.html | 16 ++++++++++------ 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 @@
- Can we survive technology? (1955) - [pdf] (uchicago.edu) + + + Can we survive technology? (1955) [pdf] + + + ( + uchicago.edu + ) + -- cgit v1.2.3