diff options
-rw-r--r-- | .emacs.d/init/ycp-web.el | 6 | ||||
m--------- | .emacs.d/lisp/emacs-hnreader | 0 | ||||
-rw-r--r-- | .emacs.d/lisp/my/my-hnreader.el | 106 | ||||
-rw-r--r-- | .gitmodules | 2 |
4 files changed, 112 insertions, 2 deletions
diff --git a/.emacs.d/init/ycp-web.el b/.emacs.d/init/ycp-web.el index 90f9874..af13d5c 100644 --- a/.emacs.d/init/ycp-web.el +++ b/.emacs.d/init/ycp-web.el @@ -62,7 +62,11 @@ ) (my-package hnreader - (:delay 30)) + (:delay 30) + (require 'my-hnreader) + (my-override hnreader--print-frontpage) + (my-override hnreader--print-frontpage-item) + (my-override hnreader--print-comments)) (my-package buildbot (:delay 30) diff --git a/.emacs.d/lisp/emacs-hnreader b/.emacs.d/lisp/emacs-hnreader -Subproject 61412639bb9f6702f22a9154333148919edf362 +Subproject e17006072b0cd06ab7ff32c6187e9565131a78b diff --git a/.emacs.d/lisp/my/my-hnreader.el b/.emacs.d/lisp/my/my-hnreader.el new file mode 100644 index 0000000..4176f8b --- /dev/null +++ b/.emacs.d/lisp/my/my-hnreader.el @@ -0,0 +1,106 @@ +;;; my-hnreader.el -- Extensions to hnreader -*- lexical-binding: t -*- + +;; Copyright (C) 2023 Free Software Foundation. + +;; Author: Yuchen Pei <id@ypei.org> +;; Thanh Vuong <thanhvg@gmail.com> +;; Maintainer: Yuchen Pei <id@ypei.org> +;; Package-Requires: ((emacs "28.2")) + +;; This file is part of dotfiles. + +;; dotfiles is free software: you can redistribute it and/or modify it under +;; the terms of the GNU Affero General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; dotfiles is distributed in the hope that it will be useful, but WITHOUT +;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General +;; Public License for more details. + +;; You should have received a copy of the GNU Affero General Public +;; License along with dotfiles. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Extensions to hnreader. + +;;; Code: + +;; To override `hnreader--print-frontpage-item' +(defun my-hnreader--print-frontpage-item (thing subtext) + "Print THING dom and SUBTEXT dom." + (let* ((url (format "https://news.ycombinator.com/item?id=%s" (dom-attr thing 'id))) + (a-node (dom-child-by-tag (dom-by-class thing "^titleline$") 'a)) + (title-link (dom-attr a-node 'href))) + (insert (format "\n* %s [[%s][%s]] (%s) [[elisp:(hnreader-comment \"%s\")][%s]]" + ;; rank + (dom-text (dom-by-class thing "^rank$")) + title-link + ;; title + (dom-text a-node) + ;; points + (dom-text (dom-by-class subtext "^score$")) + ;; comments + url + (dom-text (last (dom-by-tag subtext 'a))))) + )) + + +;; To override `hnreader--print-frontpage' +(defun my-hnreader--print-frontpage (dom buf url) + "Print raw DOM and URL on BUF." + (let ((things (dom-by-class dom "^athing$")) + (subtexts (dom-by-class dom "^subtext$"))) + (with-current-buffer buf + (read-only-mode -1) + (erase-buffer) + (insert "#+STARTUP: overview indent\n") + (hnreader--print-header) + (insert (hnreader--get-route-top-info dom)) + (cl-mapcar #'hnreader--print-frontpage-item things subtexts) + ;; (setq-local org-confirm-elisp-link-function nil) + (if hnreader--history + (insert "\n* "(format "[[elisp:(hnreader-back)][< Back]]" ) " | ") + (insert "\n* ")) + (insert (hnreader--get-morelink dom) " | ") + (insert (format "[[elisp:(hnreader-read-page-back \"%s\")][Reload]]" url) ) + (org-mode) + (goto-char (point-min)) + (forward-line 2)))) + +;; To override `hnreader--print-comments' +(defun my-hnreader--print-comments (dom url) + "Print DOM comment and URL to buffer." + (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) + (read-only-mode -1) + (erase-buffer) + (insert "-*-Org-*-\n") + (insert "#+TITLE: " (car title)) + (insert (format "\n%s\n" (cdr title))) + (insert (car info)) + (when (cdr info) + (insert "\n") + (shr-insert-document (cdr info))) + (dolist (comment comments) + (insert (format "%s %s\n" + (hnreader--get-indent + (hnreader--get-img-tag-width comment)) + (hnreader--get-comment-owner comment))) + (shr-insert-document (hnreader--get-comment comment))) + (when more-link + (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)))) + +(provide 'my-hnreader) +;;; my-hnreader.el ends here diff --git a/.gitmodules b/.gitmodules index 758406e..d5a9934 100644 --- a/.gitmodules +++ b/.gitmodules @@ -57,7 +57,7 @@ url = https://github.com/chuntaro/emacs-promise [submodule ".emacs.d/lisp/emacs-hnreader"] path = .emacs.d/lisp/emacs-hnreader - url = https://g.ypei.me/emacs-hnreader.git + url = https://github.com/thanhvg/emacs-hnreader [submodule ".emacs.d/lisp/emacs-crystal-mode"] path = .emacs.d/lisp/emacs-crystal-mode url = https://github.com/crystal-lang-tools/emacs-crystal-mode |