From 9a44d45168b01d17f3bc29b0bb348eb28b9d9d2f Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 15 Jul 2022 15:33:23 -0700 Subject: replace spw/with-less-gc and wrapper inside spw/gnus with advice --- .emacs.d/init.el | 58 +++++++++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/.emacs.d/init.el b/.emacs.d/init.el index e3b5ec1e..d73588ee 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -551,13 +551,6 @@ that's something we can determine.") (set-window-prev-buffers nil ,prev-buffers)) . ,keyword-arguments))) -(defmacro spw/with-less-gc (&rest forms) - "Execute FORMS with temporarily much higher GC thresholds." - (declare (indent 0)) - `(let ((gc-cons-percentage 0.6) - (gc-cons-threshold 402653184)) - ,@forms)) - ;;;; The *scratch* and *notes* buffers @@ -1823,7 +1816,7 @@ The ideas behind these behaviours are as follows. ;; pass to that function, and if blank, do what function does now). (defun spw/browse-gmane () (interactive) - (spw/with-less-gc (gnus-no-server)) + (gnus-no-server) (gnus-group-browse-foreign-server '(nntp "news.gmane.io"))) (global-set-key "\C-cgG" #'spw/browse-gmane) @@ -2723,30 +2716,31 @@ mutt's review view, after exiting EDITOR." (with-eval-after-load 'gnus (unless (gnus-getenv-nntpserver) (setq gnus-select-method '(nnnil "")))) +(defun spw/gnus-startup-wrapper (orig-fun &rest args) + (if (and (daemonp) (file-directory-p "~/.fmail/") + (not (file-exists-p "~/.newsrc.eld"))) + (user-error "Must use dedicated Emacs for Gnus first run") + (let ((gc-cons-percentage 0.6) + (gc-cons-threshold 402653184)) + (apply orig-fun args)))) +(advice-add 'gnus :around #'spw/gnus-startup-wrapper) +(advice-add 'gnus-no-server :around #'spw/gnus-startup-wrapper) + (defun spw/gnus (&optional fetch-and-inbox) (interactive "P") - (cl-flet ((gnus () - ;; Require a dedicated Emacs so that primary session is not - ;; locked up for ages while maildir NOV files are generated. - (if (and (daemonp) (file-directory-p "~/.fmail/") - (not (file-exists-p "~/.newsrc.eld"))) - (user-error "Must use dedicated Emacs for Gnus first run") - (spw/with-less-gc (gnus))))) - (require 'gnus) - (if (not fetch-and-inbox) - (if (gnus-alive-p) - (pop-to-buffer-same-window gnus-group-buffer) - (spw/with-less-gc (gnus))) - ;; We want to see mail that we think has just come in. This is the only - ;; time we call 'notmuch new' without --no-hooks from Emacs rather than - ;; just waiting for cron, because it's slow. - (unless (gnus-alive-p) (spw/with-less-gc (gnus))) - (with-temp-message "Fetching & indexing mail ..." - (call-process "notmuch" nil nil nil "new")) - (if (not (get-buffer "*Summary nnselect:Process-Weekday*")) - (gnus-group-read-group nil t "nnselect:Process-Weekday") - (pop-to-buffer-same-window "*Summary nnselect:Process-Weekday*") - (gnus-summary-rescan-group))))) + (require 'gnus) + (if (not fetch-and-inbox) + (if (gnus-alive-p) (pop-to-buffer-same-window gnus-group-buffer) (gnus)) + ;; We want to see mail that we think has just come in. This is the only + ;; time we call 'notmuch new' without --no-hooks from Emacs rather than + ;; just waiting for cron, because it's slow. + (unless (gnus-alive-p) (gnus)) + (with-temp-message "Fetching & indexing mail ..." + (call-process "notmuch" nil nil nil "new")) + (if (not (get-buffer "*Summary nnselect:Process-Weekday*")) + (gnus-group-read-group nil t "nnselect:Process-Weekday") + (pop-to-buffer-same-window "*Summary nnselect:Process-Weekday*") + (gnus-summary-rescan-group)))) (global-set-key "\C-cgn" #'spw/gnus) (defun spw/gnus-notmuch-ephemeral-search (query &optional limit) @@ -2754,7 +2748,7 @@ mutt's review view, after exiting EDITOR." (and current-prefix-arg (prefix-numeric-value current-prefix-arg)))) (require 'gnus) - (unless (gnus-alive-p) (spw/with-less-gc (gnus))) + (unless (gnus-alive-p) (gnus)) (gnus-group-read-ephemeral-group (concat "nnselect-" (message-unique-id)) (list 'nnselect "nnselect") nil (cons (current-buffer) gnus-current-window-configuration) nil nil @@ -2870,7 +2864,7 @@ mutt's review view, after exiting EDITOR." (setq spw/gnus-all-process-groups (spw/nm| (mapcar #'cdr process-groups))) (require 'gnus) (require 'nnselect) - (unless (gnus-alive-p) (spw/with-less-gc (gnus-no-server))) + (unless (gnus-alive-p) (gnus-no-server)) ;; Kill all summaries in case any of their queries have changed. (catch 'done -- cgit v1.2.3