Function: gnus-agent-braid-nov

gnus-agent-braid-nov is a byte-compiled function defined in gnus-agent.el.gz.

Signature

(gnus-agent-braid-nov ARTICLES FILE)

Documentation

Merge agent overview data with given file.

Takes unvalidated headers for ARTICLES from gnus-agent-overview-buffer and validated headers from the given FILE and places the combined valid headers into nntp-server-buffer. This function can be used, when file doesn't exist, to valid the overview buffer.

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/gnus-agent.el.gz
(defun gnus-agent-braid-nov (articles file)
  "Merge agent overview data with given file.
Takes unvalidated headers for ARTICLES from
`gnus-agent-overview-buffer' and validated headers from the given
FILE and places the combined valid headers into
`nntp-server-buffer'.  This function can be used, when file
doesn't exist, to valid the overview buffer."
  (let (start last)
    (set-buffer gnus-agent-overview-buffer)
    (goto-char (point-min))
    (set-buffer nntp-server-buffer)
    (erase-buffer)
    (when (file-exists-p file)
      (nnheader-insert-file-contents file))
    (goto-char (point-max))
    (forward-line -1)

    (unless (or (= (point-min) (point-max))
		(< (setq last (read (current-buffer))) (car articles)))
      ;; Old and new overlap -- We do it the hard way.
      (when (nnheader-find-nov-line (car articles))
        ;; Replacing existing NOV entry
        (delete-region (point) (progn (forward-line 1) (point))))
      (gnus-agent-copy-nov-line (pop articles))

      (ignore-errors
	(while articles
	  (while (let ((art (read (current-buffer))))
		   (cond ((< art (car articles))
			  (forward-line 1)
			  t)
			 ((= art (car articles))
			  (beginning-of-line)
			  (delete-region
			   (point) (progn (forward-line 1) (point)))
			  nil)
			 (t
			  (beginning-of-line)
			  nil))))

	  (gnus-agent-copy-nov-line (pop articles)))))

    (goto-char (point-max))

    ;; Append the remaining lines
    (when articles
      (when last
	(set-buffer gnus-agent-overview-buffer)
	(setq start (point))
	(set-buffer nntp-server-buffer))

      (let ((p (point)))
	(insert-buffer-substring gnus-agent-overview-buffer start)
	(goto-char p))

      (setq last (or last -134217728))
      (while (catch 'problems
	       (let (sort art)
		 (while (not (eobp))
		   (setq art (gnus-agent-read-article-number))
		   (cond ((not art)
			  ;; Bad art num - delete this line
			  (beginning-of-line)
			  (delete-region (point) (progn (forward-line 1) (point))))
			 ((< art last)
			  ;; Art num out of order - enable sort
			  (setq sort t)
			  (forward-line 1))
			 ((= art last)
			  ;; Bad repeat of art number - delete this line
			  (beginning-of-line)
			  (delete-region (point) (progn (forward-line 1) (point))))
			 (t
			  ;; Good art num
			  (setq last art)
			  (forward-line 1))))
		 (when sort
		   ;; something is seriously wrong as we simply shouldn't see out-of-order data.
		   ;; First, we'll fix the sort.
		   (sort-numeric-fields 1 (point-min) (point-max))

		   ;; but now we have to consider that we may have duplicate rows...
		   ;; so reset to beginning of file
		   (goto-char (point-min))
		   (setq last -134217728)

		   ;; and throw a code that restarts this scan
		   (throw 'problems t))
		 nil))))))