Subject: bug#78303: 31.0.50; Allow nil as valid value for url-cookie-save-interval per doc and type

From: Eli Zaretskii <[email-masked]>
Date: Thu, 08 May 2025 12:40:48 +0300

> Cc: stefan monnier <[email-masked]>
> Date: Wed, 7 May 2025 22:59:47 +0200
> From:  Jens Schmidt via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> [ CC to Stefan, who seems to be the original author of that cookie
>   handling thingy ... apologies if that does not really concern you ]
> 
> Variable `url-cookie-save-interval' can be perfectly well configured to
> nil, as one can see in function `url-cookie-setup-save-timer' (which
> seems to be the only function referencing that variable):
> 
>   (defun url-cookie-setup-save-timer ()
>     "Reset the cookie saver timer."
>     (interactive)
>     (ignore-errors (cancel-timer url-cookie-timer))
>     (setq url-cookie-timer nil)
>     (if url-cookie-save-interval
>         (setq url-cookie-timer (run-at-time url-cookie-save-interval
>                                             url-cookie-save-interval
>                                             #'url-cookie-write-file))))
> 
> However, the docstring and the :type of the defcustom do not
> document/allow for nil as a valid value.
> 
> The attached patch fixes that, please check.

Thanks, my alternative suggestion is below.  Now Stefan gets to choose ;-)

diff --git a/lisp/url/url-cookie.el b/lisp/url/url-cookie.el
index bb7364e..7ec90fd 100644
--- a/lisp/url/url-cookie.el
+++ b/lisp/url/url-cookie.el
@@ -350,21 +350,23 @@ url-cookie-timer
 
 (defcustom url-cookie-save-interval 3600
   "The number of seconds between automatic saves of cookies.
-Default is 1 hour.  Note that if you change this variable outside of
+Default is 1 hour; set to nil to disable automatic saving.
+Note that if you change this variable outside of
 the `customize' interface after `url-do-setup' has been run, you need
 to run the `url-cookie-setup-save-timer' function manually."
   :set (lambda (var val)
          (set-default var val)
          (if (bound-and-true-p url-setup-done)
              (url-cookie-setup-save-timer)))
-  :type 'natnum)
+  :type '(choice (const :tag "Disable automatic saving" :value nil)
+                 (natnum :tag "Auto-save interval in seconds")))
 
 (defun url-cookie-setup-save-timer ()
   "Reset the cookie saver timer."
   (interactive)
   (ignore-errors (cancel-timer url-cookie-timer))
   (setq url-cookie-timer nil)
-  (if url-cookie-save-interval
+  (if (natnump url-cookie-save-interval)
       (setq url-cookie-timer (run-at-time url-cookie-save-interval
 					  url-cookie-save-interval
 					  #'url-cookie-write-file))))