Function: gnus-get-unread-articles-in-group
gnus-get-unread-articles-in-group is a byte-compiled function defined
in gnus-start.el.gz.
Signature
(gnus-get-unread-articles-in-group INFO ACTIVE &optional UPDATE)
Source Code
;; Defined in /usr/src/emacs/lisp/gnus/gnus-start.el.gz
(defun gnus-get-unread-articles-in-group (info active &optional update)
(when (and info active)
;; Allow the backend to update the info in the group.
(when (and update
(gnus-request-update-info
info (inline (gnus-find-method-for-group
(gnus-info-group info)))))
(gnus-activate-group (gnus-info-group info) nil t))
(let* ((range (gnus-info-read info))
(num 0))
;; These checks are present in gnus-activate-group but skipped
;; due to setting dont-check in the preceding call.
;; If a cache is present, we may have to alter the active info.
(when (and gnus-use-cache info)
(inline (gnus-cache-possibly-alter-active
(gnus-info-group info) active)))
;; If the agent is enabled, we may have to alter the active info.
(when (and gnus-agent info)
(gnus-agent-possibly-alter-active (gnus-info-group info) active info))
;; Modify the list of read articles according to what articles
;; are available; then tally the unread articles and add the
;; number to the group hash table entry.
(cond
((zerop (cdr active))
(setq num 0))
((not range)
(setq num (- (1+ (cdr active)) (car active))))
((not (listp (cdr range)))
;; Fix a single (num . num) range according to the
;; active hash table.
;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
(and (< (cdr range) (car active)) (setcdr range (1- (car active))))
(and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
;; Compute number of unread articles.
(setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
(t
;; The read list is a list of ranges. Fix them according to
;; the active hash table.
;; First peel off any elements that are below the lower
;; active limit.
(while (and (cdr range)
(>= (car active)
(or (and (atom (cadr range)) (cadr range))
(caadr range))))
(if (numberp (car range))
(setcar range
(cons (car range)
(or (and (numberp (cadr range))
(cadr range))
(cdadr range))))
(setcdr (car range)
(or (and (numberp (nth 1 range)) (nth 1 range))
(cdadr range))))
(setcdr range (cddr range)))
;; Adjust the first element to be the same as the lower limit.
(when (and (not (atom (car range)))
(< (cdar range) (car active)))
(setcdr (car range) (1- (car active))))
;; Then we want to peel off any elements that are higher
;; than the upper active limit.
(let ((srange range))
;; Go past all valid elements.
(while (and (cdr srange)
(<= (or (and (atom (cadr srange))
(cadr srange))
(caadr srange))
(cdr active)))
(setq srange (cdr srange)))
(when (cdr srange)
;; Nuke all remaining invalid elements.
(setcdr srange nil))
;; Adjust the final element.
(when (and (not (atom (car srange)))
(> (cdar srange) (cdr active)))
(setcdr (car srange) (cdr active))))
;; Compute the number of unread articles.
(while range
(setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
(cdar range)))
(or (and (atom (car range)) (car range))
(caar range)))))
(setq range (cdr range)))
(setq num (max 0 (- (cdr active) num)))))
;; Set the number of unread articles.
(when (and info
(gnus-group-entry (gnus-info-group info)))
(setcar (gnus-group-entry (gnus-info-group info)) num))
num)))