Function: nnmh-active-number

nnmh-active-number is a byte-compiled function defined in nnmh.el.gz.

Signature

(nnmh-active-number GROUP)

Documentation

Compute the next article number in GROUP.

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/nnmh.el.gz
(defun nnmh-active-number (group)
  "Compute the next article number in GROUP."
  (let ((active (cadr (assoc group nnmh-group-alist)))
	(dir (nnmail-group-pathname group nnmh-directory))
	(file-name-coding-system nnmail-pathname-coding-system)
	file)
    (unless active
      ;; The group wasn't known to nnmh, so we just create an active
      ;; entry for it.
      (setq active (cons 1 0))
      (push (list group active) nnmh-group-alist)
      (unless (file-exists-p dir)
	(gnus-make-directory dir))
      ;; Find the highest number in the group.
      (let ((files (sort
		    (mapcar #'string-to-number
			    (directory-files dir nil "\\`[0-9]+\\'"))
		    #'>)))
	(when files
	  (setcdr active (car files)))))
    (setcdr active (1+ (cdr active)))
    (while (or
	    ;; See whether the file exists...
	    (file-exists-p
	     (setq file (concat (nnmail-group-pathname group nnmh-directory)
				(int-to-string (cdr active)))))
	    ;; ... or there is a buffer that will make that file exist
	    ;; in the future.
	    (get-file-buffer file))
      ;; Skip past that file.
      (setcdr active (1+ (cdr active))))
    (cdr active)))