* lisp/gnus: Further reduce assumptions about gnus-data format

* lisp/gnus/gnus-registry.el (gnus-registry-fetch-message-id-fast)
(gnus-registry-fetch-simplified-message-subject-fast)
(gnus-registry-fetch-sender-fast, gnus-registry-fetch-recipients-fast)
(gnus-registry--set/remove-mark): Don't hardcode assoc for gnus-data-find-in.

* lisp/gnus/gnus-sum.el (gnus-data-update-list): Don't hardcode `nth 2`
for gnus-data-pos.
(gnus-summary-insert-old-articles, gnus-summary-insert-new-articles)
(gnus-summary-first-article-p): Don't hardcode `car` for `gnus-data-number`.
(gnus-summary-move-article, gnus-summary-expire-articles)
(gnus-summary-delete-article): Don't hardcode assoc for gnus-data-find-in.

* lisp/gnus/spam.el (spam-fetch-article-header): Don't hardcode `nth 3`
for gnus-data-header.
This commit is contained in:
Stefan Monnier 2019-06-07 15:28:12 -04:00
parent 77f96e2cc1
commit da1974fabd
3 changed files with 26 additions and 36 deletions

View file

@ -799,11 +799,9 @@ Overrides existing keywords with FORCE set non-nil."
;; message field fetchers
(defun gnus-registry-fetch-message-id-fast (article)
"Fetch the Message-ID quickly, using the internal gnus-data-list function."
(if (and (numberp article)
(assoc article (gnus-data-list nil)))
(mail-header-id (gnus-data-header (assoc article (gnus-data-list nil))))
nil))
"Fetch the Message-ID quickly, using the internal `gnus-data-find' function."
(when-let* ((data (and (numberp article) (gnus-data-find article))))
(mail-header-id (gnus-data-header data))))
(defun gnus-registry-extract-addresses (text)
"Extract all the addresses in a normalized way from TEXT.
@ -830,23 +828,18 @@ Addresses without a name will say \"noname\"."
nil))
(defun gnus-registry-fetch-simplified-message-subject-fast (article)
"Fetch the Subject quickly, using the internal gnus-data-list function."
(if (and (numberp article)
(assoc article (gnus-data-list nil)))
(gnus-string-remove-all-properties
(gnus-registry-simplify-subject
(mail-header-subject (gnus-data-header
(assoc article (gnus-data-list nil))))))
nil))
"Fetch the Subject quickly, using the internal `gnus-data-find' function."
(when-let* ((data (and (numberp article) (gnus-data-find article))))
(gnus-string-remove-all-properties
(gnus-registry-simplify-subject
(mail-header-subject (gnus-data-header data))))))
(defun gnus-registry-fetch-sender-fast (article)
(when-let* ((data (and (numberp article)
(assoc article (gnus-data-list nil)))))
(when-let* ((data (and (numberp article) (gnus-data-find article))))
(mail-header-from (gnus-data-header data))))
(defun gnus-registry-fetch-recipients-fast (article)
(when-let* ((data (and (numberp article)
(assoc article (gnus-data-list nil))))
(when-let* ((data (and (numberp article) (gnus-data-find article)))
(extra (mail-header-extra (gnus-data-header data))))
(gnus-registry-sort-addresses
(or (cdr (assq 'Cc extra)) "")
@ -887,9 +880,7 @@ FUNCTION should take two parameters, a mark symbol and the cell value."
(gnus-message 9 "Applying mark %s to %d articles"
mark (length articles))
(dolist (article articles)
(gnus-summary-update-article
article
(assoc article (gnus-data-list nil))))))
(gnus-summary-update-article article (gnus-data-find article)))))
;; This is ugly code, but I don't know how to do it better.
(defun gnus-registry-install-shortcuts ()

View file

@ -3246,7 +3246,7 @@ The following commands are available:
"Add OFFSET to the POS of all data entries in DATA."
(setq gnus-newsgroup-data-reverse nil)
(while data
(setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
(cl-incf (gnus-data-pos (car data)) offset)
(setq data (cdr data))))
(defun gnus-summary-article-pseudo-p (article)
@ -3574,7 +3574,7 @@ buffer that was in action when the last article was fetched."
"Return whether ARTICLE is the first article in the buffer."
(if (not (setq article (or article (gnus-summary-article-number))))
nil
(eq article (caar gnus-newsgroup-data))))
(eq article (gnus-data-number (car gnus-newsgroup-data)))))
(defun gnus-summary-last-article-p (&optional article)
"Return whether ARTICLE is the last article in the buffer."
@ -4725,10 +4725,10 @@ If LINE, insert the rebuilt thread starting on line LINE."
(push thr roots))
(setq thread (cdr thread)))
;; We now have all (unique) roots.
(if (= (length roots) 1)
;; All the loose roots are now one solid root.
(setq thread (car roots))
(setq thread (cons subject (gnus-sort-threads roots))))))
(setq thread (if (= (length roots) 1)
;; All the loose roots are now one solid root.
(car roots)
(cons subject (gnus-sort-threads roots))))))
(let (threads)
;; We then insert this thread into the summary buffer.
(when line
@ -4738,6 +4738,7 @@ If LINE, insert the rebuilt thread starting on line LINE."
(if gnus-show-threads
(gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
(gnus-summary-prepare-unthreaded thread))
;; FIXME: Why is this `nreverse' safe? Don't we need `reverse' instead?
(setq data (nreverse gnus-newsgroup-data))
(setq threads gnus-newsgroup-threads))
;; We splice the new data into the data structure.
@ -10170,7 +10171,7 @@ ACTION can be either `move' (the default), `crosspost' or `copy'."
(run-hook-with-args 'gnus-summary-article-delete-hook
action
(gnus-data-header
(assoc article (gnus-data-list nil)))
(gnus-data-find-in article (gnus-data-list nil)))
gnus-newsgroup-name nil
select-method)))
(t
@ -10280,8 +10281,7 @@ ACTION can be either `move' (the default), `crosspost' or `copy'."
;; run the move/copy/crosspost/respool hook
(run-hook-with-args 'gnus-summary-article-move-hook
action
(gnus-data-header
(assoc article (gnus-data-list nil)))
(gnus-data-header (gnus-data-find article))
gnus-newsgroup-name
to-newsgroup
select-method))
@ -10524,7 +10524,7 @@ This will be the case if the article has both been mailed and posted."
(run-hook-with-args
'gnus-summary-article-expire-hook
'delete
(gnus-data-header (assoc article (gnus-data-list nil)))
(gnus-data-header (gnus-data-find article))
gnus-newsgroup-name
(cond
((stringp nnmail-expiry-target) nnmail-expiry-target)
@ -10588,8 +10588,7 @@ confirmation before the articles are deleted."
(unless (memq (car articles) not-deleted)
(gnus-summary-mark-article (car articles) gnus-canceled-mark)
(let* ((article (car articles))
(ghead (gnus-data-header
(assoc article (gnus-data-list nil)))))
(ghead (gnus-data-header (gnus-data-find article))))
(run-hook-with-args 'gnus-summary-article-delete-hook
'delete ghead gnus-newsgroup-name nil
nil)))
@ -13038,7 +13037,7 @@ If ALL is non-nil, already read articles become readable.
If ALL is a number, fetch this number of articles."
(interactive "P")
(prog1
(let ((old (sort (mapcar #'car gnus-newsgroup-data) #'<))
(let ((old (sort (mapcar #'gnus-data-number gnus-newsgroup-data) #'<))
older len)
(setq older
;; Some nntp servers lie about their active range. When
@ -13108,7 +13107,7 @@ If ALL is a number, fetch this number of articles."
(defun gnus-summary-insert-new-articles ()
"Insert all new articles in this group."
(interactive)
(let ((old (sort (mapcar #'car gnus-newsgroup-data) #'<))
(let ((old (sort (mapcar #'gnus-data-number gnus-newsgroup-data) #'<))
(old-high gnus-newsgroup-highest)
(nnmail-fetched-sources (list t))
(new-active (gnus-activate-group gnus-newsgroup-name 'scan))

View file

@ -1520,7 +1520,7 @@ In the case of mover backends, checks the setting of
;; nil)))
(defun spam-fetch-field-fast (article field &optional prepared-data-header)
"Fetch a FIELD for ARTICLE with the internal `gnus-data-list' function.
"Fetch a FIELD for ARTICLE with the internal `gnus-data-find' function.
When PREPARED-DATA-HEADER is given, don't look in the Gnus data.
When FIELD is 'number, ARTICLE can be any number (since we want
to find it out)."
@ -1586,7 +1586,7 @@ to find it out)."
(defun spam-fetch-article-header (article)
(with-current-buffer gnus-summary-buffer
(gnus-read-header article)
(nth 3 (assq article gnus-newsgroup-data))))
(gnus-data-header (gnus-data-find article))))
;;}}}
;;{{{ Spam determination.