From 9776c3f0516bf3a5de3f229de62e90e3e298bf16 Mon Sep 17 00:00:00 2001 From: dickmao Date: Sat, 18 Jan 2020 14:12:49 -0500 Subject: [PATCH 1/6] python 2.7.12 ssl problem --- tools/install-virtualenv.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/install-virtualenv.sh b/tools/install-virtualenv.sh index 05beee1..76e86df 100644 --- a/tools/install-virtualenv.sh +++ b/tools/install-virtualenv.sh @@ -13,8 +13,8 @@ if [ "x$TRAVIS_OS_NAME" = "xosx" ]; then case "${TOXENV}" in py27) - pyenv install -s 2.7.12 - pyenv virtualenv -f 2.7.12 py27 + pyenv install -s 2.7.13 + pyenv virtualenv -f 2.7.13 py27 ;; py35) pyenv install -s 3.5.2 -- 2.34.1 From ece875ef0a491ccad13c8c3e677169371560bbc1 Mon Sep 17 00:00:00 2001 From: dickmao Date: Tue, 4 Feb 2020 16:38:41 -0500 Subject: [PATCH 2/6] avoid advising everything under the sun if nnhackernews not a select method --- nnhackernews.el | 316 ++++++++++++++++++++++++------------------------ 1 file changed, 158 insertions(+), 158 deletions(-) diff --git a/nnhackernews.el b/nnhackernews.el index 85f8abb..0274aca 100644 --- a/nnhackernews.el +++ b/nnhackernews.el @@ -1563,180 +1563,180 @@ Written by John Wiegley (https://github.com/jwiegley/dot-emacs).") ;; ,nnhackernews--group-job ;; ,nnhackernews--group-stories))) ;; t) - ) -;; "Can't figure out hook that can remove itself (quine conundrum)" -(add-function :around (symbol-function 'gnus-summary-exit) - (lambda (f &rest args) - (let ((gnus-summary-next-group-on-exit - (if (nnhackernews--gate) nil - gnus-summary-next-group-on-exit))) - (apply f args)))) -(add-function :after (symbol-function 'gnus-summary-exit) - (symbol-function 'nnhackernews--score-pending)) + ;; "Can't figure out hook that can remove itself (quine conundrum)" + (add-function :around (symbol-function 'gnus-summary-exit) + (lambda (f &rest args) + (let ((gnus-summary-next-group-on-exit + (if (nnhackernews--gate) nil + gnus-summary-next-group-on-exit))) + (apply f args)))) -(add-function :before (symbol-function 'gnus-score-save) - (lambda (&rest _) - (when (nnhackernews--gate) - (setq nnhackernews-score-files - (assq-delete-all (intern gnus-newsgroup-name) - nnhackernews-score-files))))) + (add-function :after (symbol-function 'gnus-summary-exit) + (symbol-function 'nnhackernews--score-pending)) -;; `gnus-newsgroup-p' requires valid method post-mail to return t -(add-to-list 'gnus-valid-select-methods '("nnhackernews" post-mail) t) + (add-function :before (symbol-function 'gnus-score-save) + (lambda (&rest _) + (when (nnhackernews--gate) + (setq nnhackernews-score-files + (assq-delete-all (intern gnus-newsgroup-name) + nnhackernews-score-files))))) -(add-function - :around (symbol-function 'message-supersede) - (lambda (f &rest args) - (cond ((nnhackernews--gate) - (add-function :override - (symbol-function 'mml-insert-mml-markup) - 'ignore) - (condition-case err - (prog1 (apply f args) - (remove-function (symbol-function 'mml-insert-mml-markup) 'ignore) - (save-excursion - (save-restriction - (message-replace-header "From" (message-make-from)) - (message-goto-body) - (narrow-to-region (point) (point-max)) - (goto-char (point-max)) - (mm-inline-text-html nil) - (delete-region (point-min) (point))))) - (error (remove-function (symbol-function 'mml-insert-mml-markup) 'ignore) - (error (error-message-string err))))) - (t (apply f args))))) + ;; `gnus-newsgroup-p' requires valid method post-mail to return t + (add-to-list 'gnus-valid-select-methods '("nnhackernews" post-mail) t) -(add-function - :around (symbol-function 'message-send-news) - (lambda (f &rest args) - (cond ((nnhackernews--gate) - (let* ((dont-ask (lambda (prompt) - (when (cl-search "mpty article" prompt) t))) - (link-p (message-fetch-field "Link")) - (message-shoot-gnksa-feet (if link-p t message-shoot-gnksa-feet))) - (when link-p - (add-function :before-until (symbol-function 'y-or-n-p) dont-ask)) - (unwind-protect (apply f args) - (remove-function (symbol-function 'y-or-n-p) dont-ask)))) - (t (apply f args))))) - -(add-function - :around (symbol-function 'gnus-summary-post-news) - (lambda (f &rest args) - (cond ((nnhackernews--gate) - (let* ((nnhackernews-post-type (read-char-choice "[l]ink / [t]ext: " '(?l ?t))) - (link-header (apply-partially #'message-add-header "Link: https://")) - (add-link-header (apply-partially #'add-hook - 'message-header-setup-hook - link-header)) - (remove-link-header (apply-partially #'remove-hook - 'message-header-setup-hook - link-header))) - (cl-case nnhackernews-post-type - (?l (funcall add-link-header))) + (add-function + :around (symbol-function 'message-supersede) + (lambda (f &rest args) + (cond ((nnhackernews--gate) + (add-function :override + (symbol-function 'mml-insert-mml-markup) + 'ignore) (condition-case err - (progn - (apply f args) - (funcall remove-link-header)) - (error (funcall remove-link-header) - (error (error-message-string err)))))) - (t (apply f args))))) + (prog1 (apply f args) + (remove-function (symbol-function 'mml-insert-mml-markup) 'ignore) + (save-excursion + (save-restriction + (message-replace-header "From" (message-make-from)) + (message-goto-body) + (narrow-to-region (point) (point-max)) + (goto-char (point-max)) + (mm-inline-text-html nil) + (delete-region (point-min) (point))))) + (error (remove-function (symbol-function 'mml-insert-mml-markup) 'ignore) + (error (error-message-string err))))) + (t (apply f args))))) -(add-function - :filter-return (symbol-function 'message-make-fqdn) - (lambda (val) - (if (and (nnhackernews--gate) - (cl-search "--so-tickle-me" val)) - "ycombinator.com" val))) + (add-function + :around (symbol-function 'message-send-news) + (lambda (f &rest args) + (cond ((nnhackernews--gate) + (let* ((dont-ask (lambda (prompt) + (when (cl-search "mpty article" prompt) t))) + (link-p (message-fetch-field "Link")) + (message-shoot-gnksa-feet (if link-p t message-shoot-gnksa-feet))) + (when link-p + (add-function :before-until (symbol-function 'y-or-n-p) dont-ask)) + (unwind-protect (apply f args) + (remove-function (symbol-function 'y-or-n-p) dont-ask)))) + (t (apply f args))))) -(add-function - :before-until (symbol-function 'message-make-from) - (lambda (&rest _args) - (when (nnhackernews--gate) - (concat (nnhackernews--who-am-i) "@ycombinator.com")))) + (add-function + :around (symbol-function 'gnus-summary-post-news) + (lambda (f &rest args) + (cond ((nnhackernews--gate) + (let* ((nnhackernews-post-type (read-char-choice "[l]ink / [t]ext: " '(?l ?t))) + (link-header (apply-partially #'message-add-header "Link: https://")) + (add-link-header (apply-partially #'add-hook + 'message-header-setup-hook + link-header)) + (remove-link-header (apply-partially #'remove-hook + 'message-header-setup-hook + link-header))) + (cl-case nnhackernews-post-type + (?l (funcall add-link-header))) + (condition-case err + (progn + (apply f args) + (funcall remove-link-header)) + (error (funcall remove-link-header) + (error (error-message-string err)))))) + (t (apply f args))))) -(add-function - :around (symbol-function 'message-is-yours-p) - (lambda (f &rest args) - (let ((concat-func (lambda (f &rest args) - (let ((fetched (apply f args))) - (if (string= (car args) "from") - (concat fetched "@ycombinator.com") - fetched))))) + (add-function + :filter-return (symbol-function 'message-make-fqdn) + (lambda (val) + (if (and (nnhackernews--gate) + (cl-search "--so-tickle-me" val)) + "ycombinator.com" val))) + + (add-function + :before-until (symbol-function 'message-make-from) + (lambda (&rest _args) (when (nnhackernews--gate) - (add-function :around - (symbol-function 'message-fetch-field) - concat-func)) - (condition-case err - (prog1 (apply f args) - (remove-function (symbol-function 'message-fetch-field) concat-func)) - (error (remove-function (symbol-function 'message-fetch-field) concat-func) - (error (error-message-string err))))))) + (concat (nnhackernews--who-am-i) "@ycombinator.com")))) -(let ((protect (lambda (caller) - (add-function - :around (symbol-function caller) - (lambda (f &rest args) - (cond ((nnhackernews--gate) - (condition-case err - (apply f args) - (error (gnus-message 7 "%s: %s" - caller - (error-message-string err))))) - (t (apply f args)))))))) - (funcall protect 'url-http-generic-filter) - (funcall protect 'url-http-end-of-document-sentinel)) + (add-function + :around (symbol-function 'message-is-yours-p) + (lambda (f &rest args) + (let ((concat-func (lambda (f &rest args) + (let ((fetched (apply f args))) + (if (string= (car args) "from") + (concat fetched "@ycombinator.com") + fetched))))) + (when (nnhackernews--gate) + (add-function :around + (symbol-function 'message-fetch-field) + concat-func)) + (condition-case err + (prog1 (apply f args) + (remove-function (symbol-function 'message-fetch-field) concat-func)) + (error (remove-function (symbol-function 'message-fetch-field) concat-func) + (error (error-message-string err))))))) -;; Make the scoring entries Markovian -(add-function - :around (symbol-function 'gnus-summary-score-entry) - (lambda (f header match &rest args) - (cond ((nnhackernews--gate) - (let* ((new-touched - (let ((gnus-score-alist (copy-alist '((touched nil))))) - (cons (apply f header match args) - (cl-some #'identity (gnus-score-get 'touched))))) - (new (car new-touched)) - (touched (cdr new-touched))) - (when (and touched new) - (-if-let* ((old (gnus-score-get header)) - (elem (assoc match old)) - (match-type (eq (nth 3 elem) (nth 3 new))) - (match-date (or (and (numberp (nth 2 elem)) (numberp (nth 2 new))) - (and (not (nth 2 elem)) (not (nth 2 new)))))) - (setcar (cdr elem) (nth 1 new)) - (gnus-score-set header (cons new old) nil t)) - (gnus-score-set 'touched '(t))) - new)) - (t (apply f header match args))))) + (let ((protect (lambda (caller) + (add-function + :around (symbol-function caller) + (lambda (f &rest args) + (cond ((nnhackernews--gate) + (condition-case err + (apply f args) + (error (gnus-message 7 "%s: %s" + caller + (error-message-string err))))) + (t (apply f args)))))))) + (funcall protect 'url-http-generic-filter) + (funcall protect 'url-http-end-of-document-sentinel)) -;; the let'ing to nil of `gnus-summary-display-article-function' -;; in `gnus-summary-select-article' dates back to antiquity. -(add-function - :around (symbol-function 'gnus-summary-display-article) - (lambda (f &rest args) - (cond ((nnhackernews--gate) - (let ((gnus-summary-display-article-function - (symbol-function 'nnhackernews--display-article))) - (apply f args))) - (t (apply f args))))) + ;; Make the scoring entries Markovian + (add-function + :around (symbol-function 'gnus-summary-score-entry) + (lambda (f header match &rest args) + (cond ((nnhackernews--gate) + (let* ((new-touched + (let ((gnus-score-alist (copy-alist '((touched nil))))) + (cons (apply f header match args) + (cl-some #'identity (gnus-score-get 'touched))))) + (new (car new-touched)) + (touched (cdr new-touched))) + (when (and touched new) + (-if-let* ((old (gnus-score-get header)) + (elem (assoc match old)) + (match-type (eq (nth 3 elem) (nth 3 new))) + (match-date (or (and (numberp (nth 2 elem)) (numberp (nth 2 new))) + (and (not (nth 2 elem)) (not (nth 2 new)))))) + (setcar (cdr elem) (nth 1 new)) + (gnus-score-set header (cons new old) nil t)) + (gnus-score-set 'touched '(t))) + new)) + (t (apply f header match args))))) -;; disallow caching as firebase might change the article numbering? -(setq gnus-uncacheable-groups - (aif gnus-uncacheable-groups - (format "\\(%s\\)\\|\\(^nnhackernews\\)" it) - "^nnhackernews")) + ;; the let'ing to nil of `gnus-summary-display-article-function' + ;; in `gnus-summary-select-article' dates back to antiquity. + (add-function + :around (symbol-function 'gnus-summary-display-article) + (lambda (f &rest args) + (cond ((nnhackernews--gate) + (let ((gnus-summary-display-article-function + (symbol-function 'nnhackernews--display-article))) + (apply f args))) + (t (apply f args))))) -(custom-set-variables - '(gnus-score-after-write-file-function - (lambda (file) - (when (nnhackernews--gate) - (unless (member file (alist-get (intern gnus-newsgroup-name) - nnhackernews-score-files)) - (push file (alist-get (intern gnus-newsgroup-name) - nnhackernews-score-files))))))) + ;; disallow caching as firebase might change the article numbering? + (setq gnus-uncacheable-groups + (aif gnus-uncacheable-groups + (format "\\(%s\\)\\|\\(^nnhackernews\\)" it) + "^nnhackernews")) + + (custom-set-variables + '(gnus-score-after-write-file-function + (lambda (file) + (when (nnhackernews--gate) + (unless (member file (alist-get (intern gnus-newsgroup-name) + nnhackernews-score-files)) + (push file (alist-get (intern gnus-newsgroup-name) + nnhackernews-score-files)))))))) ;; (push '((and (eq (car gnus-current-select-method) 'nnhackernews) ;; (eq mark gnus-unread-mark) -- 2.34.1 From 6924c8530816d6cac0aa38107038370b7ed31935 Mon Sep 17 00:00:00 2001 From: dickmao Date: Tue, 4 Feb 2020 17:41:47 -0500 Subject: [PATCH 3/6] or... if you subscribe to this package, you commit to all the hooks in case you activate nnhackernews after startup. --- nnhackernews.el | 360 ++++++++++++++++++++++++------------------------ 1 file changed, 179 insertions(+), 181 deletions(-) diff --git a/nnhackernews.el b/nnhackernews.el index 0274aca..eef84f9 100644 --- a/nnhackernews.el +++ b/nnhackernews.el @@ -1539,204 +1539,202 @@ Written by John Wiegley (https://github.com/jwiegley/dot-emacs).") (when (nnhackernews--gate) (nnhackernews-summary-mode))) -(when (or (gnus-native-method-p '(nnhackernews "")) - (gnus-secondary-method-p '(nnhackernews ""))) - ;; I believe I did try buffer-localizing hooks, and it wasn't sufficient - (add-hook 'gnus-article-mode-hook #'nnhackernews-article-mode-activate) - (add-hook 'gnus-summary-mode-hook #'nnhackernews-summary-mode-activate) +;; I believe I did try buffer-localizing hooks, and it wasn't sufficient +(add-hook 'gnus-article-mode-hook #'nnhackernews-article-mode-activate) +(add-hook 'gnus-summary-mode-hook #'nnhackernews-summary-mode-activate) - ;; Avoid having to select the GROUP to make the unread number go down. - (mapc (lambda (hook) - (add-hook hook - (lambda () (mapc (lambda (group) - (nnhackernews--score-unread group)) - `(,nnhackernews--group-ask - ,nnhackernews--group-show - ,nnhackernews--group-job - ,nnhackernews--group-stories))))) - '(gnus-after-getting-new-news-hook)) - ;; (add-hook 'gnus-started-hook - ;; (lambda () (mapc (lambda (group) - ;; (nnhackernews--mark-scored-as-read group)) - ;; `(,nnhackernews--group-ask - ;; ,nnhackernews--group-show - ;; ,nnhackernews--group-job - ;; ,nnhackernews--group-stories))) - ;; t) +;; Avoid having to select the GROUP to make the unread number go down. +(mapc (lambda (hook) + (add-hook hook + (lambda () (mapc (lambda (group) + (nnhackernews--score-unread group)) + `(,nnhackernews--group-ask + ,nnhackernews--group-show + ,nnhackernews--group-job + ,nnhackernews--group-stories))))) + '(gnus-after-getting-new-news-hook)) +;; (add-hook 'gnus-started-hook +;; (lambda () (mapc (lambda (group) +;; (nnhackernews--mark-scored-as-read group)) +;; `(,nnhackernews--group-ask +;; ,nnhackernews--group-show +;; ,nnhackernews--group-job +;; ,nnhackernews--group-stories))) +;; t) - ;; "Can't figure out hook that can remove itself (quine conundrum)" - (add-function :around (symbol-function 'gnus-summary-exit) - (lambda (f &rest args) - (let ((gnus-summary-next-group-on-exit - (if (nnhackernews--gate) nil - gnus-summary-next-group-on-exit))) - (apply f args)))) +;; "Can't figure out hook that can remove itself (quine conundrum)" +(add-function :around (symbol-function 'gnus-summary-exit) + (lambda (f &rest args) + (let ((gnus-summary-next-group-on-exit + (if (nnhackernews--gate) nil + gnus-summary-next-group-on-exit))) + (apply f args)))) - (add-function :after (symbol-function 'gnus-summary-exit) - (symbol-function 'nnhackernews--score-pending)) +(add-function :after (symbol-function 'gnus-summary-exit) + (symbol-function 'nnhackernews--score-pending)) - (add-function :before (symbol-function 'gnus-score-save) - (lambda (&rest _) - (when (nnhackernews--gate) - (setq nnhackernews-score-files - (assq-delete-all (intern gnus-newsgroup-name) - nnhackernews-score-files))))) +(add-function :before (symbol-function 'gnus-score-save) + (lambda (&rest _) + (when (nnhackernews--gate) + (setq nnhackernews-score-files + (assq-delete-all (intern gnus-newsgroup-name) + nnhackernews-score-files))))) - ;; `gnus-newsgroup-p' requires valid method post-mail to return t - (add-to-list 'gnus-valid-select-methods '("nnhackernews" post-mail) t) +;; `gnus-newsgroup-p' requires valid method post-mail to return t +(add-to-list 'gnus-valid-select-methods '("nnhackernews" post-mail) t) - (add-function - :around (symbol-function 'message-supersede) - (lambda (f &rest args) - (cond ((nnhackernews--gate) - (add-function :override - (symbol-function 'mml-insert-mml-markup) - 'ignore) +(add-function + :around (symbol-function 'message-supersede) + (lambda (f &rest args) + (cond ((nnhackernews--gate) + (add-function :override + (symbol-function 'mml-insert-mml-markup) + 'ignore) + (condition-case err + (prog1 (apply f args) + (remove-function (symbol-function 'mml-insert-mml-markup) 'ignore) + (save-excursion + (save-restriction + (message-replace-header "From" (message-make-from)) + (message-goto-body) + (narrow-to-region (point) (point-max)) + (goto-char (point-max)) + (mm-inline-text-html nil) + (delete-region (point-min) (point))))) + (error (remove-function (symbol-function 'mml-insert-mml-markup) 'ignore) + (error (error-message-string err))))) + (t (apply f args))))) + +(add-function + :around (symbol-function 'message-send-news) + (lambda (f &rest args) + (cond ((nnhackernews--gate) + (let* ((dont-ask (lambda (prompt) + (when (cl-search "mpty article" prompt) t))) + (link-p (message-fetch-field "Link")) + (message-shoot-gnksa-feet (if link-p t message-shoot-gnksa-feet))) + (when link-p + (add-function :before-until (symbol-function 'y-or-n-p) dont-ask)) + (unwind-protect (apply f args) + (remove-function (symbol-function 'y-or-n-p) dont-ask)))) + (t (apply f args))))) + +(add-function + :around (symbol-function 'gnus-summary-post-news) + (lambda (f &rest args) + (cond ((nnhackernews--gate) + (let* ((nnhackernews-post-type (read-char-choice "[l]ink / [t]ext: " '(?l ?t))) + (link-header (apply-partially #'message-add-header "Link: https://")) + (add-link-header (apply-partially #'add-hook + 'message-header-setup-hook + link-header)) + (remove-link-header (apply-partially #'remove-hook + 'message-header-setup-hook + link-header))) + (cl-case nnhackernews-post-type + (?l (funcall add-link-header))) (condition-case err - (prog1 (apply f args) - (remove-function (symbol-function 'mml-insert-mml-markup) 'ignore) - (save-excursion - (save-restriction - (message-replace-header "From" (message-make-from)) - (message-goto-body) - (narrow-to-region (point) (point-max)) - (goto-char (point-max)) - (mm-inline-text-html nil) - (delete-region (point-min) (point))))) - (error (remove-function (symbol-function 'mml-insert-mml-markup) 'ignore) - (error (error-message-string err))))) - (t (apply f args))))) + (progn + (apply f args) + (funcall remove-link-header)) + (error (funcall remove-link-header) + (error (error-message-string err)))))) + (t (apply f args))))) - (add-function - :around (symbol-function 'message-send-news) - (lambda (f &rest args) - (cond ((nnhackernews--gate) - (let* ((dont-ask (lambda (prompt) - (when (cl-search "mpty article" prompt) t))) - (link-p (message-fetch-field "Link")) - (message-shoot-gnksa-feet (if link-p t message-shoot-gnksa-feet))) - (when link-p - (add-function :before-until (symbol-function 'y-or-n-p) dont-ask)) - (unwind-protect (apply f args) - (remove-function (symbol-function 'y-or-n-p) dont-ask)))) - (t (apply f args))))) +(add-function + :filter-return (symbol-function 'message-make-fqdn) + (lambda (val) + (if (and (nnhackernews--gate) + (cl-search "--so-tickle-me" val)) + "ycombinator.com" val))) - (add-function - :around (symbol-function 'gnus-summary-post-news) - (lambda (f &rest args) - (cond ((nnhackernews--gate) - (let* ((nnhackernews-post-type (read-char-choice "[l]ink / [t]ext: " '(?l ?t))) - (link-header (apply-partially #'message-add-header "Link: https://")) - (add-link-header (apply-partially #'add-hook - 'message-header-setup-hook - link-header)) - (remove-link-header (apply-partially #'remove-hook - 'message-header-setup-hook - link-header))) - (cl-case nnhackernews-post-type - (?l (funcall add-link-header))) - (condition-case err - (progn - (apply f args) - (funcall remove-link-header)) - (error (funcall remove-link-header) - (error (error-message-string err)))))) - (t (apply f args))))) +(add-function + :before-until (symbol-function 'message-make-from) + (lambda (&rest _args) + (when (nnhackernews--gate) + (concat (nnhackernews--who-am-i) "@ycombinator.com")))) - (add-function - :filter-return (symbol-function 'message-make-fqdn) - (lambda (val) - (if (and (nnhackernews--gate) - (cl-search "--so-tickle-me" val)) - "ycombinator.com" val))) - - (add-function - :before-until (symbol-function 'message-make-from) - (lambda (&rest _args) +(add-function + :around (symbol-function 'message-is-yours-p) + (lambda (f &rest args) + (let ((concat-func (lambda (f &rest args) + (let ((fetched (apply f args))) + (if (string= (car args) "from") + (concat fetched "@ycombinator.com") + fetched))))) (when (nnhackernews--gate) - (concat (nnhackernews--who-am-i) "@ycombinator.com")))) + (add-function :around + (symbol-function 'message-fetch-field) + concat-func)) + (condition-case err + (prog1 (apply f args) + (remove-function (symbol-function 'message-fetch-field) concat-func)) + (error (remove-function (symbol-function 'message-fetch-field) concat-func) + (error (error-message-string err))))))) - (add-function - :around (symbol-function 'message-is-yours-p) - (lambda (f &rest args) - (let ((concat-func (lambda (f &rest args) - (let ((fetched (apply f args))) - (if (string= (car args) "from") - (concat fetched "@ycombinator.com") - fetched))))) - (when (nnhackernews--gate) - (add-function :around - (symbol-function 'message-fetch-field) - concat-func)) - (condition-case err - (prog1 (apply f args) - (remove-function (symbol-function 'message-fetch-field) concat-func)) - (error (remove-function (symbol-function 'message-fetch-field) concat-func) - (error (error-message-string err))))))) +(let ((protect (lambda (caller) + (add-function + :around (symbol-function caller) + (lambda (f &rest args) + (cond ((nnhackernews--gate) + (condition-case err + (apply f args) + (error (gnus-message 7 "%s: %s" + caller + (error-message-string err))))) + (t (apply f args)))))))) + (funcall protect 'url-http-generic-filter) + (funcall protect 'url-http-end-of-document-sentinel)) - (let ((protect (lambda (caller) - (add-function - :around (symbol-function caller) - (lambda (f &rest args) - (cond ((nnhackernews--gate) - (condition-case err - (apply f args) - (error (gnus-message 7 "%s: %s" - caller - (error-message-string err))))) - (t (apply f args)))))))) - (funcall protect 'url-http-generic-filter) - (funcall protect 'url-http-end-of-document-sentinel)) +;; Make the scoring entries Markovian +(add-function + :around (symbol-function 'gnus-summary-score-entry) + (lambda (f header match &rest args) + (cond ((nnhackernews--gate) + (let* ((new-touched + (let ((gnus-score-alist (copy-alist '((touched nil))))) + (cons (apply f header match args) + (cl-some #'identity (gnus-score-get 'touched))))) + (new (car new-touched)) + (touched (cdr new-touched))) + (when (and touched new) + (-if-let* ((old (gnus-score-get header)) + (elem (assoc match old)) + (match-type (eq (nth 3 elem) (nth 3 new))) + (match-date (or (and (numberp (nth 2 elem)) (numberp (nth 2 new))) + (and (not (nth 2 elem)) (not (nth 2 new)))))) + (setcar (cdr elem) (nth 1 new)) + (gnus-score-set header (cons new old) nil t)) + (gnus-score-set 'touched '(t))) + new)) + (t (apply f header match args))))) - ;; Make the scoring entries Markovian - (add-function - :around (symbol-function 'gnus-summary-score-entry) - (lambda (f header match &rest args) - (cond ((nnhackernews--gate) - (let* ((new-touched - (let ((gnus-score-alist (copy-alist '((touched nil))))) - (cons (apply f header match args) - (cl-some #'identity (gnus-score-get 'touched))))) - (new (car new-touched)) - (touched (cdr new-touched))) - (when (and touched new) - (-if-let* ((old (gnus-score-get header)) - (elem (assoc match old)) - (match-type (eq (nth 3 elem) (nth 3 new))) - (match-date (or (and (numberp (nth 2 elem)) (numberp (nth 2 new))) - (and (not (nth 2 elem)) (not (nth 2 new)))))) - (setcar (cdr elem) (nth 1 new)) - (gnus-score-set header (cons new old) nil t)) - (gnus-score-set 'touched '(t))) - new)) - (t (apply f header match args))))) +;; the let'ing to nil of `gnus-summary-display-article-function' +;; in `gnus-summary-select-article' dates back to antiquity. +(add-function + :around (symbol-function 'gnus-summary-display-article) + (lambda (f &rest args) + (cond ((nnhackernews--gate) + (let ((gnus-summary-display-article-function + (symbol-function 'nnhackernews--display-article))) + (apply f args))) + (t (apply f args))))) - ;; the let'ing to nil of `gnus-summary-display-article-function' - ;; in `gnus-summary-select-article' dates back to antiquity. - (add-function - :around (symbol-function 'gnus-summary-display-article) - (lambda (f &rest args) - (cond ((nnhackernews--gate) - (let ((gnus-summary-display-article-function - (symbol-function 'nnhackernews--display-article))) - (apply f args))) - (t (apply f args))))) +;; disallow caching as firebase might change the article numbering? +(setq gnus-uncacheable-groups + (aif gnus-uncacheable-groups + (format "\\(%s\\)\\|\\(^nnhackernews\\)" it) + "^nnhackernews")) - ;; disallow caching as firebase might change the article numbering? - (setq gnus-uncacheable-groups - (aif gnus-uncacheable-groups - (format "\\(%s\\)\\|\\(^nnhackernews\\)" it) - "^nnhackernews")) - - (custom-set-variables - '(gnus-score-after-write-file-function - (lambda (file) - (when (nnhackernews--gate) - (unless (member file (alist-get (intern gnus-newsgroup-name) - nnhackernews-score-files)) - (push file (alist-get (intern gnus-newsgroup-name) - nnhackernews-score-files)))))))) +(custom-set-variables + '(gnus-score-after-write-file-function + (lambda (file) + (when (nnhackernews--gate) + (unless (member file (alist-get (intern gnus-newsgroup-name) + nnhackernews-score-files)) + (push file (alist-get (intern gnus-newsgroup-name) + nnhackernews-score-files))))))) ;; (push '((and (eq (car gnus-current-select-method) 'nnhackernews) ;; (eq mark gnus-unread-mark) -- 2.34.1 From c39146fa3ec650ab9f177565aab8d7ab99267298 Mon Sep 17 00:00:00 2001 From: dickmao Date: Tue, 4 Feb 2020 17:50:03 -0500 Subject: [PATCH 4/6] don't run rescore if nnhackernews not a select method --- Makefile | 29 ++++++++++++++++++++--------- nnhackernews.el | 4 +++- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 9fd7d77..c9e1d35 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,10 @@ EMACS ?= $(shell which emacs) -SRC=$(shell cask files) +export CASK := $(shell which cask) +ifeq ($(CASK),) +$(error Please install CASK at https://cask.readthedocs.io/en/latest/guide/installation.html) +endif +CASK_DIR := $(shell EMACS=$(EMACS) cask package-directory || exit 1) +SRC=$(shell $(CASK) files) PKBUILD=2.3 ELCFILES = $(SRC:.el=.elc) @@ -31,18 +36,24 @@ README.rst: README.in.rst nnhackernews.el test-clean: rm -rf tests/.emacs* tests/.newsrc* tests/Mail tests/News tests/request tests/request-log +.PHONY: cask +cask: $(CASK_DIR) + +$(CASK_DIR): Cask + $(CASK) install + touch $(CASK_DIR) + .PHONY: clean clean: test-clean - cask clean-elc + $(CASK) clean-elc rm -f tests/log/* rm -rf tests/test-install .PHONY: test-compile -test-compile: - cask install +test-compile: cask sh -ex tools/package-lint.sh nnhackernews.el - ! (cask eval "(let ((byte-compile-error-on-warn t)) (cask-cli/build))" 2>&1 | egrep -a "(Warning|Error):") - cask clean-elc + ! ($(CASK) eval "(let ((byte-compile-error-on-warn t)) (cask-cli/build))" 2>&1 | egrep -a "(Warning|Error):") + $(CASK) clean-elc .PHONY: test-install test-install: @@ -74,14 +85,14 @@ test-install: .PHONY: test-unit test-unit: - cask exec ert-runner -L . -L tests tests/test*.el + $(CASK) exec ert-runner -L . -L tests tests/test*.el .PHONY: test test: test-compile test-unit test-int .PHONY: test-int test-int: test-clean - cask exec ecukes --reporter magnars --debug + $(CASK) exec ecukes --reporter magnars --debug .PHONY: dist-clean dist-clean: @@ -89,7 +100,7 @@ dist-clean: .PHONY: dist dist: dist-clean - cask package + $(CASK) package .PHONY: install install: test-compile dist diff --git a/nnhackernews.el b/nnhackernews.el index eef84f9..7cafeaa 100644 --- a/nnhackernews.el +++ b/nnhackernews.el @@ -586,7 +586,9 @@ Originally written by Paul Issartel." "Can't figure out GROUP hook that can remove itself (quine conundrum). FORCE is generally t unless coming from `nnhackernews--score-pending'." - (when (nnhackernews--gate group) + (when (and (or (gnus-native-method-p '(nnhackernews "")) + (gnus-secondary-method-p '(nnhackernews ""))) + (nnhackernews--gate group)) (cl-loop repeat 5 for ensured = (nnhackernews--ensure-score-files group) until ensured -- 2.34.1 From b72d9417b1809b6b0e8ab174c5341aa040e19349 Mon Sep 17 00:00:00 2001 From: dickmao Date: Mon, 10 Feb 2020 18:41:08 -0500 Subject: [PATCH 5/6] use unwind-protect --- nnhackernews.el | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/nnhackernews.el b/nnhackernews.el index 7cafeaa..e25a8b0 100644 --- a/nnhackernews.el +++ b/nnhackernews.el @@ -483,7 +483,7 @@ If GROUP classification omitted, figure it out." (defmacro nnhackernews--with-group (group &rest body) "Disambiguate GROUP if it's empty and execute BODY." (declare (debug (form &rest form)) - (indent 1)) + (indent defun)) `(let* ((group (or ,group (gnus-group-real-name gnus-newsgroup-name))) (gnus-newsgroup-name (gnus-group-full-name group "nnhackernews:"))) ,@body)) @@ -586,9 +586,7 @@ Originally written by Paul Issartel." "Can't figure out GROUP hook that can remove itself (quine conundrum). FORCE is generally t unless coming from `nnhackernews--score-pending'." - (when (and (or (gnus-native-method-p '(nnhackernews "")) - (gnus-secondary-method-p '(nnhackernews ""))) - (nnhackernews--gate group)) + (when (nnhackernews--gate group) (cl-loop repeat 5 for ensured = (nnhackernews--ensure-score-files group) until ensured @@ -633,9 +631,11 @@ FORCE is generally t unless coming from `nnhackernews--score-pending'." "Filter unread messages for GROUP now. Otherwise *Group* buffer annoyingly overrepresents unread." - (nnhackernews--with-group group - (unless (nnhackernews-extant-summary-buffer gnus-newsgroup-name) - (nnhackernews--rescore gnus-newsgroup-name t)))) + (when (or (gnus-native-method-p '(nnhackernews "")) + (gnus-secondary-method-p '(nnhackernews ""))) + (nnhackernews--with-group group + (unless (nnhackernews-extant-summary-buffer gnus-newsgroup-name) + (nnhackernews--rescore gnus-newsgroup-name t))))) (defun nnhackernews--mark-scored-as-read (group) "If a root article (story) is scored in GROUP, that means we've already read it." @@ -1669,11 +1669,9 @@ Written by John Wiegley (https://github.com/jwiegley/dot-emacs).") (add-function :around (symbol-function 'message-fetch-field) concat-func)) - (condition-case err - (prog1 (apply f args) - (remove-function (symbol-function 'message-fetch-field) concat-func)) - (error (remove-function (symbol-function 'message-fetch-field) concat-func) - (error (error-message-string err))))))) + (unwind-protect + (apply f args) + (remove-function (symbol-function 'message-fetch-field) concat-func))))) (let ((protect (lambda (caller) (add-function -- 2.34.1 From 2f7433d065c5ad34caa34b0a445659e2315ecd87 Mon Sep 17 00:00:00 2001 From: dickmao Date: Mon, 17 Feb 2020 06:42:22 -0500 Subject: [PATCH 6/6] readme --- README.in.rst | 1 + README.rst | 1 + 2 files changed, 2 insertions(+) diff --git a/README.in.rst b/README.in.rst index 748c2e2..89f7eac 100644 --- a/README.in.rst +++ b/README.in.rst @@ -30,6 +30,7 @@ Then :: M-x package-refresh-contents RET + M-x package-initialize RET M-x package-install RET nnhackernews RET Alternatively, copy ``nnhackernews.el`` to a directory among ``C-h v RET load-path`` and add ``(require 'nnhackernews)`` to ``.emacs``. diff --git a/README.rst b/README.rst index 4ded675..ccc9a5f 100644 --- a/README.rst +++ b/README.rst @@ -30,6 +30,7 @@ Then :: M-x package-refresh-contents RET + M-x package-initialize RET M-x package-install RET nnhackernews RET Alternatively, copy ``nnhackernews.el`` to a directory among ``C-h v RET load-path`` and add ``(require 'nnhackernews)`` to ``.emacs``. -- 2.34.1