From 68971b3209424b56f7d55ba327eff24950980d80 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Mon, 1 Jun 2020 17:24:54 -0700 Subject: replace let vars with defvars This prevents them being reset to nil when we eval new versions of the functions which close over them. --- .emacs.d/init-notmuch.el | 294 ++++++++++++++++++++++++----------------------- 1 file changed, 148 insertions(+), 146 deletions(-) diff --git a/.emacs.d/init-notmuch.el b/.emacs.d/init-notmuch.el index a60f7fda..805ef194 100644 --- a/.emacs.d/init-notmuch.el +++ b/.emacs.d/init-notmuch.el @@ -177,152 +177,154 @@ Two ways to read: ;;;; ---- more variables & functions, with connectives ---- -(let ((lists-browse-searches) - (readall)) - (cl-flet* ((connective (word) - (apply-partially - (lambda (connec &rest queries) - (mapconcat (lambda (query) (concat "(" query ")")) - (-flatten queries) - (concat " " connec " "))) - word)) - (disjoin (connective "or")) - (conjoin (connective "and")) - (negate (query) (concat "not (" query ")")) - (thread (query) (concat "thread:{" query "}"))) - - (defvar spw--weekday-only-mail (disjoin "to:spwhitton@email.arizona.edu" - "from:arizona.edu" - (thread "tag:spw::work")) - "Mail to be filtered out of processing views at the weekend.") - - (defun spw--standard-notmuch-saved-searches () - (interactive) - (setq notmuch-saved-searches nil - lists-browse-searches nil) - (when (file-exists-p (locate-user-emacs-file "notmuch-groups.el")) - (load (locate-user-emacs-file "notmuch-groups")) - (dolist (group spw--lists-browse) - (let ((search - (if (atom group) - ;; assume we got a List: search and extract the first - ;; component of the List-Id to use as the name of the - ;; search - (let ((name (if (string-match ":\\([^.]+\\)\\." group) - (match-string 1 group) - (error "Could not extract a list name")))) - `(:name ,name :search-type nil :sort-order newest-first - :query ,group)) - ;; assume a plist and copy properties across - (let ((name (plist-get group :name)) - (key (plist-get group :key)) - (query (disjoin (plist-get group :queries)))) +(defvar spw/lists-browse-searches nil + "Internal cache variable.") +(defvar spw/readall nil + "Internal cache variable.") +(cl-flet* ((connective (word) + (apply-partially + (lambda (connec &rest queries) + (mapconcat (lambda (query) (concat "(" query ")")) + (-flatten queries) + (concat " " connec " "))) + word)) + (disjoin (connective "or")) + (conjoin (connective "and")) + (negate (query) (concat "not (" query ")")) + (thread (query) (concat "thread:{" query "}"))) + + (defvar spw--weekday-only-mail (disjoin "to:spwhitton@email.arizona.edu" + "from:arizona.edu" + (thread "tag:spw::work")) + "Mail to be filtered out of processing views at the weekend.") + + (defun spw--standard-notmuch-saved-searches () + (interactive) + (setq notmuch-saved-searches nil + spw/lists-browse-searches nil) + (when (file-exists-p (locate-user-emacs-file "notmuch-groups.el")) + (load (locate-user-emacs-file "notmuch-groups")) + (dolist (group spw--lists-browse) + (let ((search + (if (atom group) + ;; assume we got a List: search and extract the first + ;; component of the List-Id to use as the name of the + ;; search + (let ((name (if (string-match ":\\([^.]+\\)\\." group) + (match-string 1 group) + (error "Could not extract a list name")))) `(:name ,name :search-type nil :sort-order newest-first - :key ,key :query ,query))))) - (add-to-list 'notmuch-saved-searches search t) - (add-to-list 'lists-browse-searches - (cons (plist-get search :name) - (conjoin "tag:unread" (plist-get search :query))) - t)))) - - (setq readall - (conjoin - (disjoin - "folder:inbox" - - ;; can use this to include all mail addressed directly - ;; to me in processing views, as an alternative to - ;; relying on 'folder:inbox' - ;; (mapcar (lambda (a) (concat "to:" a)) (notmuch-user-emails)) - - spw--lists-readall) - (negate (thread "tag:spw::browse")))) - - ;; now prepend views for processing the day's mail addressed to me - (let* ((to-process (conjoin "tag:unread" readall)) - (to-process-weekend (conjoin to-process - (negate spw--weekday-only-mail)))) - (add-to-list 'notmuch-saved-searches - `(:name "weekend unread" :key "w" :search-type nil - :sort-order oldest-first - :query ,to-process-weekend)) - (add-to-list 'notmuch-saved-searches - `(:name "weekday unread" :key "u" :search-type nil - :sort-order oldest-first - :query ,to-process))) - - ;; append some miscellaneous views + :query ,group)) + ;; assume a plist and copy properties across + (let ((name (plist-get group :name)) + (key (plist-get group :key)) + (query (disjoin (plist-get group :queries)))) + `(:name ,name :search-type nil :sort-order newest-first + :key ,key :query ,query))))) + (add-to-list 'notmuch-saved-searches search t) + (add-to-list 'spw/lists-browse-searches + (cons (plist-get search :name) + (conjoin "tag:unread" (plist-get search :query))) + t)))) + + (setq spw/readall + (conjoin + (disjoin + "folder:inbox" + + ;; can use this to include all mail addressed directly + ;; to me in processing views, as an alternative to + ;; relying on 'folder:inbox' + ;; (mapcar (lambda (a) (concat "to:" a)) (notmuch-user-emails)) + + spw--lists-readall) + (negate (thread "tag:spw::browse")))) + + ;; now prepend views for processing the day's mail addressed to me + (let* ((to-process (conjoin "tag:unread" spw/readall)) + (to-process-weekend (conjoin to-process + (negate spw--weekday-only-mail)))) (add-to-list 'notmuch-saved-searches - '(:name "flagged" :key "f" :search-type tree - :query "tag:flagged" ) t) + `(:name "weekend unread" :key "w" :search-type nil + :sort-order oldest-first + :query ,to-process-weekend)) (add-to-list 'notmuch-saved-searches - `(:name "sent" :key "s" :search-type nil - :sort-order newest-first - :query ,(disjoin - (mapcar - (lambda (a) (concat "from:" a)) - (notmuch-user-emails)))) - t) - (add-to-list 'notmuch-saved-searches - '(:name "drafts" :key "D" :search-type nil - :sort-order newest-first - :query "tag:draft") t) - (add-to-list 'notmuch-saved-searches - '(:name "imported series" :key "P" :search-type nil - :sort-order newest-first - :query "subject:\"/PATCH .+ imported/\"") t) - - ;; finally, groups/lists where I don't know how or whether I want to - ;; follow them; I may have subscribed just to post something - (let* ((categorised (disjoin - readall - (mapcar (lambda (search) - (if (atom search) - search - (plist-get search :queries))) - spw--lists-browse) - spw--lists-archiveonly)) - (query `(:name "uncategorised unread" :key "U" :search-type nil - :sort-order newest-first - :query ,(conjoin "tag:unread" - (negate categorised))))) - (add-to-list 'notmuch-saved-searches query t) - (add-to-list 'lists-browse-searches - (cons "uncategorised unread" - (conjoin "tag:unread" - (negate categorised))) t))) - - (unless lists-browse-searches - (spw--standard-notmuch-saved-searches)) - - (defun spw/next-unread-group () - (interactive) - (let ((already-looking (boundp 'spw--more-unread-groups)) - (queries (bound-and-true-p spw--more-unread-groups)) - (remaining)) - (when already-looking - (notmuch-tree-close-message-window) - (kill-buffer (current-buffer))) - (if (or (and already-looking (not queries)) - (not (setq remaining (seq-drop-while - (lambda (q) - (zerop (string-to-number - (notmuch-saved-search-count - (cdr q))))) - (or queries lists-browse-searches))))) - (notmuch-hello) - (notmuch-tree (cdar remaining) nil nil - (concat "*notmuch-tree-saved-search-" - (caar remaining) "*")) - (set (make-local-variable 'spw--more-unread-groups) - (cdr remaining))))) - - ;; use on views produced by `spw--next-unread-group' - (defun spw--notmuch-tree-catchup () - (interactive) - (when (and (eq major-mode 'notmuch-tree-mode) - (y-or-n-p "Are you sure you want to mark all as read?") - readall) - (notmuch-tag (conjoin (notmuch-tree-get-query) (negate readall)) - '("-unread")) - (notmuch-refresh-this-buffer))))) + `(:name "weekday unread" :key "u" :search-type nil + :sort-order oldest-first + :query ,to-process))) + + ;; append some miscellaneous views + (add-to-list 'notmuch-saved-searches + '(:name "flagged" :key "f" :search-type tree + :query "tag:flagged" ) t) + (add-to-list 'notmuch-saved-searches + `(:name "sent" :key "s" :search-type nil + :sort-order newest-first + :query ,(disjoin + (mapcar + (lambda (a) (concat "from:" a)) + (notmuch-user-emails)))) + t) + (add-to-list 'notmuch-saved-searches + '(:name "drafts" :key "D" :search-type nil + :sort-order newest-first + :query "tag:draft") t) + (add-to-list 'notmuch-saved-searches + '(:name "imported series" :key "P" :search-type nil + :sort-order newest-first + :query "subject:\"/PATCH .+ imported/\"") t) + + ;; finally, groups/lists where I don't know how or whether I want to + ;; follow them; I may have subscribed just to post something + (let* ((categorised (disjoin + spw/readall + (mapcar (lambda (search) + (if (atom search) + search + (plist-get search :queries))) + spw--lists-browse) + spw--lists-archiveonly)) + (query `(:name "uncategorised unread" :key "U" :search-type nil + :sort-order newest-first + :query ,(conjoin "tag:unread" + (negate categorised))))) + (add-to-list 'notmuch-saved-searches query t) + (add-to-list 'spw/lists-browse-searches + (cons "uncategorised unread" + (conjoin "tag:unread" + (negate categorised))) t))) + + (unless spw/lists-browse-searches + (spw--standard-notmuch-saved-searches)) + + (defun spw/next-unread-group () + (interactive) + (let ((already-looking (boundp 'spw--more-unread-groups)) + (queries (bound-and-true-p spw--more-unread-groups)) + (remaining)) + (when already-looking + (notmuch-tree-close-message-window) + (kill-buffer (current-buffer))) + (if (or (and already-looking (not queries)) + (not (setq remaining (seq-drop-while + (lambda (q) + (zerop (string-to-number + (notmuch-saved-search-count + (cdr q))))) + (or queries spw/lists-browse-searches))))) + (notmuch-hello) + (notmuch-tree (cdar remaining) nil nil + (concat "*notmuch-tree-saved-search-" + (caar remaining) "*")) + (set (make-local-variable 'spw--more-unread-groups) + (cdr remaining))))) + + ;; use on views produced by `spw--next-unread-group' + (defun spw--notmuch-tree-catchup () + (interactive) + (when (and (eq major-mode 'notmuch-tree-mode) + (y-or-n-p "Are you sure you want to mark all as read?") + spw/readall) + (notmuch-tag (conjoin (notmuch-tree-get-query) (negate spw/readall)) + '("-unread")) + (notmuch-refresh-this-buffer)))) -- cgit v1.2.3