summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2023-03-24 16:53:52 -0700
committerSean Whitton <spwhitton@spwhitton.name>2023-04-16 13:07:22 -0700
commit519253b8a0f17ac7786c76eeeb33b0cf99b1787e (patch)
treed9157d9b23310e63aa6e26f0bb7ef29ffd9b62c9
parent5884cc8a83ad4d498e2bbfc77286633982f8180f (diff)
downloaddotfiles-519253b8a0f17ac7786c76eeeb33b0cf99b1787e.tar.gz
use nnselect-always-regenerate
-rw-r--r--.emacs.d/init.el88
1 files changed, 39 insertions, 49 deletions
diff --git a/.emacs.d/init.el b/.emacs.d/init.el
index 9c75eaee..49eac9ae 100644
--- a/.emacs.d/init.el
+++ b/.emacs.d/init.el
@@ -3269,8 +3269,8 @@ mutt's review view, after exiting EDITOR."
(unless (spw/on-host-p "athena.silentflame.com")
(with-temp-message "Fetching from all accounts on athena ..."
(call-process "ssh" nil nil nil "athena" "sh" "-lc" "movemymail")))
- (with-temp-message "Fetching & indexing mail locally ..."
- (call-process "notmuch" nil nil nil "new"))
+ (with-temp-message "Fetching mail locally ..."
+ (call-process "movemymail"))
(let* ((group (cl-case (prefix-numeric-value current-prefix-arg)
(4 "nnselect:Process-Weekend")
(16 "nnselect:Process-Weekday")))
@@ -3474,8 +3474,8 @@ mutt's review view, after exiting EDITOR."
;; From `gnus-group-make-search-group' (though marked "temporary"?).
else do (gnus-group-make-group name (list 'nnselect "nnselect")
nil `((nnselect-specs . ,specs)
- (nnselect-rescan . t)
- (nnselect-artlist . nil)))
+ (nnselect-always-regenerate . t)
+ (nnselect-rescan . t)))
;; Manual recommends keeping mail groups on levels 1 and 2. We have
;; browse groups higher for `gnus-group-best-unread-group'. Then `.'
;; to jump to the first processing group, `,' to jump to the first
@@ -3567,40 +3567,35 @@ mutt's review view, after exiting EDITOR."
(with-eval-after-load 'gnus-start
(add-hook 'gnus-started-hook #'spw/sync-notmuch-nnselect-groups))
-;; Rescan nnmaildir+fmail:inbox too, else rescanning the nnselect group will
-;; not display any new mail.
-(defun spw/gnus-request-group-scan (group _info)
- (when (eq 'nnselect (car (gnus-find-method-for-group group)))
- (gnus-activate-group "nnmaildir+fmail:inbox" 'scan)))
-(advice-add 'gnus-request-group-scan :before #'spw/gnus-request-group-scan)
-
-;; This works around Emacs bug#56592 without relying on duplicate suppression.
-(defun spw/gnus-summary-read-group (orig-fun group show-all &rest args)
- (let* ((nnselectp (string-prefix-p "nnselect:" group))
- (unread-before (gnus-group-unread group))
- (none-unread-before-p (and (numberp unread-before)
- (zerop unread-before))))
- (when nnselectp
- (with-current-buffer gnus-group-buffer
- (save-excursion
- (gnus-group-goto-group group)
- (gnus-group-get-new-news-this-group 1))))
- (let ((none-unread-after-p (and nnselectp
- (zerop (gnus-group-unread group)))))
- (cond ((and nnselectp (not show-all)
- (not none-unread-before-p) none-unread-after-p)
- ;; Ensure we return nil to `gnus-summary-next-group'.
- (ignore (message "No more unread articles")))
- ;; `gnus-group-read-group' passes SHOW-ALL t if it thinks the
- ;; group has no unread messages. Override that.
- ((and nnselectp
- (not (and current-prefix-arg
- (memq this-command '(gnus-topic-read-group
- gnus-topic-select-group))))
- none-unread-before-p (not none-unread-after-p))
- (apply orig-fun group nil args))
- (t (apply orig-fun group show-all args))))))
-(advice-add 'gnus-summary-read-group :around #'spw/gnus-summary-read-group)
+(defun spw/gnus-specs-search-notmuch-p (&optional specs group)
+ (and-let* ((specs
+ (or specs
+ (gnus-group-get-parameter (or group gnus-newsgroup-name)
+ 'nnselect-specs t))))
+ (require 'gnus-search)
+ (gnus-search-notmuch-p
+ (gnus-search-server-to-engine
+ (caadr (assq 'search-group-spec (cdr (assq 'nnselect-args specs))))))))
+
+(defvar spw/this-command-notmuch-updated-p nil)
+
+(defun spw/nnselect-update-notmuch (group &optional specs _info)
+ (when (and (not spw/this-command-notmuch-updated-p)
+ (spw/gnus-specs-search-notmuch-p specs group))
+ ;; Rescan nnmaildir+fmail:inbox to ensure we display new mail.
+ (gnus-activate-group "nnmaildir+fmail:inbox" 'scan)
+ ;; Update notmuch database before querying it.
+ (call-process "notmuch" nil nil nil "new" "--no-hooks")
+ ;; We want to avoid
+ ;; (i) changing the db between the calls to `nnselect-request-group'
+ ;; and `nnselect-request-headers' that occur when entering a group
+ ;; (see received mail date:@1681255438); and
+ ;; (ii) updating over and over again in `gnus-group-get-new-news'.
+ (setq spw/this-command-notmuch-updated-p t)
+ (spw/add-once-hook 'post-command-hook
+ (lambda ()
+ (setq spw/this-command-notmuch-updated-p nil)))))
+(advice-add 'nnselect-generate-artlist :before #'spw/nnselect-update-notmuch)
(defun spw/gnus-group-nnselect-query (group)
(when-let ((specs (gnus-group-get-parameter group 'nnselect-specs t)))
@@ -3835,17 +3830,12 @@ mutt's review view, after exiting EDITOR."
(defun spw/gnus-warp-to-article ()
(interactive)
- (let* ((specs
- (gnus-group-get-parameter gnus-newsgroup-name 'nnselect-specs t)))
- (if (gnus-search-notmuch-p
- (gnus-search-server-to-engine
- (caadr (assq 'search-group-spec
- (cdr (assq 'nnselect-args specs))))))
- (let* ((mid (gnus-summary-header "message-id"))
- (search (concat "id:" (string-trim mid "<" ">"))))
- (spw/gnus-notmuch-ephemeral-search search 0 t)
- (gnus-summary-goto-article mid))
- (gnus-warp-to-article))))
+ (if (spw/gnus-specs-search-notmuch-p)
+ (let* ((mid (gnus-summary-header "message-id"))
+ (search (concat "id:" (string-trim mid "<" ">"))))
+ (spw/gnus-notmuch-ephemeral-search search 0 t)
+ (gnus-summary-goto-article mid))
+ (gnus-warp-to-article)))
(with-eval-after-load 'gnus-sum
(define-key gnus-summary-mode-map
[remap gnus-warp-to-article] #'spw/gnus-warp-to-article))