Function: gnus-save-newsrc-file

gnus-save-newsrc-file is a byte-compiled function defined in gnus-start.el.gz.

Signature

(gnus-save-newsrc-file &optional FORCE)

Documentation

Save .newsrc file.

Use the group string names in gnus-group-list to pull info values from gnus-newsrc-hashtb, and write a new value of gnus-newsrc-alist.

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/gnus-start.el.gz
(defun gnus-save-newsrc-file (&optional force)
  "Save .newsrc file.
Use the group string names in `gnus-group-list' to pull info
values from `gnus-newsrc-hashtb', and write a new value of
`gnus-newsrc-alist'."
  (when (and (or gnus-newsrc-alist gnus-killed-list)
	     gnus-current-startup-file)
    ;; Save agent range limits for the currently active method.
    (when gnus-agent
      (gnus-agent-save-local force))

    (save-excursion
      (if (and (or gnus-use-dribble-file gnus-child)
	       (not force)
               (or (not (buffer-live-p gnus-dribble-buffer))
		   (zerop (with-current-buffer gnus-dribble-buffer
			    (buffer-size)))))
	  (gnus-message 4 "(No changes need to be saved)")
	(gnus-run-hooks 'gnus-save-newsrc-hook)
	(if gnus-child
	    (gnus-child-save-newsrc)
	  ;; Save .newsrc only if the select method is an NNTP method.
	  ;; The .newsrc file is for interoperability with other
	  ;; newsreaders, so saving non-NNTP groups there doesn't make
	  ;; much sense.
	  (when (and gnus-save-newsrc-file
		     (eq (car (gnus-server-to-method gnus-select-method))
			 'nntp))
	    (gnus-message 8 "Saving %s..." gnus-current-startup-file)
	    (gnus-gnus-to-newsrc-format)
	    (gnus-message 8 "Saving %s...done" gnus-current-startup-file))

	  ;; Save .newsrc.eld.
	  (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
          (setq-local version-control gnus-backup-startup-file)
	  (setq buffer-file-name
		(concat gnus-current-startup-file ".eld"))
	  (setq default-directory (file-name-directory buffer-file-name))
	  (buffer-disable-undo)
	  (erase-buffer)
          (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)

          ;; Check timestamp of `gnus-current-startup-file'.eld against
          ;; `gnus-save-newsrc-file-last-timestamp'.
	  (if (let* ((checkfile (concat gnus-current-startup-file ".eld"))
		     (mtime (file-attribute-modification-time
			     (file-attributes checkfile))))
		(and gnus-save-newsrc-file-last-timestamp
                     (time-less-p gnus-save-newsrc-file-last-timestamp
                                  mtime)
		     (not
		      (y-or-n-p
                       (format "%s was updated externally after %s, save?"
                               checkfile
                               (format-time-string
				"%c"
				gnus-save-newsrc-file-last-timestamp))))))
              (gnus-message
	       4 "Didn't save %s: updated externally"
	       (concat gnus-current-startup-file ".eld"))
            (if gnus-save-startup-file-via-temp-buffer
		(let ((coding-system-for-write gnus-ding-file-coding-system)
                      (standard-output (current-buffer)))
                  (gnus-gnus-to-quick-newsrc-format)
                  (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
                  (save-buffer)
                  (setq gnus-save-newsrc-file-last-timestamp
			(file-attribute-modification-time
			 (file-attributes buffer-file-name))))
              (let ((coding-system-for-write gnus-ding-file-coding-system)
                    (version-control gnus-backup-startup-file)
                    (startup-file (concat gnus-current-startup-file ".eld"))
                    (working-dir (file-name-directory gnus-current-startup-file))
                    working-file
                    (i -1))
		;; Generate the name of a non-existent file.
		(while (progn (setq working-file
                                    (format
                                     (if (and (eq system-type 'ms-dos)
                                              (not (gnus-long-file-names)))
					 "%s#%d.tm#" ; MSDOS limits files to 8+3
				       "%s#tmp#%d")
                                     working-dir (setq i (1+ i))))
                              (file-exists-p working-file)))

		(unwind-protect
		    (with-file-modes (file-modes startup-file)
                      (gnus-with-output-to-file working-file
			(gnus-gnus-to-quick-newsrc-format)
			(gnus-run-hooks 'gnus-save-quick-newsrc-hook))

                      ;; These bindings will mislead the current buffer
                      ;; into thinking that it is visiting the startup
                      ;; file.
                      (let ((buffer-backed-up nil)
                            (buffer-file-name startup-file)
			    (file-precious-flag t))
			;; Backup the current version of the startup file.
			(backup-buffer)

			;; Replace the existing startup file with the temp file.
			(rename-file working-file startup-file t)
			(setq gnus-save-newsrc-file-last-timestamp
			      (file-attribute-modification-time
			       (file-attributes startup-file)))))
                  (condition-case nil
                      (delete-file working-file)
                    (file-error nil)))))

	    (gnus-kill-buffer (current-buffer))
	    (gnus-message
	     5 "Saving %s.eld...done" gnus-current-startup-file)))
	(gnus-dribble-delete-file)
	(gnus-group-set-mode-line)))))