From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gulshan Singh Newsgroups: gmane.emacs.bugs Subject: bug#54346: persist-save doesn't persist variables when the value is set to the default Date: Fri, 11 Mar 2022 17:15:53 -0800 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000f4f3c805d9fb3045" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30181"; mail-complaints-to="usenet@ciao.gmane.io" To: 54346@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Mar 12 02:17:13 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nSqNc-0007g3-2W for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 12 Mar 2022 02:17:12 +0100 Original-Received: from localhost ([::1]:56676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSqNa-00082Z-12 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 11 Mar 2022 20:17:10 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:37706) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSqNS-00082P-KG for bug-gnu-emacs@gnu.org; Fri, 11 Mar 2022 20:17:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44958) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSqNS-0007e5-Bh for bug-gnu-emacs@gnu.org; Fri, 11 Mar 2022 20:17:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nSqNS-0003R1-55 for bug-gnu-emacs@gnu.org; Fri, 11 Mar 2022 20:17:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Gulshan Singh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 12 Mar 2022 01:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 54346 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.164704777113136 (code B ref -1); Sat, 12 Mar 2022 01:17:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 12 Mar 2022 01:16:11 +0000 Original-Received: from localhost ([127.0.0.1]:38855 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nSqMd-0003Pn-2Q for submit@debbugs.gnu.org; Fri, 11 Mar 2022 20:16:11 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:47140) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nSqMb-0003Pg-Bt for submit@debbugs.gnu.org; Fri, 11 Mar 2022 20:16:09 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:37638) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSqMb-00080E-7r for bug-gnu-emacs@gnu.org; Fri, 11 Mar 2022 20:16:09 -0500 Original-Received: from [2a00:1450:4864:20::52c] (port=39880 helo=mail-ed1-x52c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSqMZ-0007aV-2b for bug-gnu-emacs@gnu.org; Fri, 11 Mar 2022 20:16:08 -0500 Original-Received: by mail-ed1-x52c.google.com with SMTP id g20so12898912edw.6 for ; Fri, 11 Mar 2022 17:16:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=3vc4zow5ouRIkK+34pDeFXV49ZrhEwguifj5ZC0tQ5M=; b=PjfgQctlLaTySjat8cYCXpEDCwOu1LqrLeEE2uI62NU3UedZvdytzVBc9XBFVqOVur IGJGeLLUb2ZQQFw8DRHzu9YCuiJ2Tn5/f2SKgzzkrlJagJhkOiDYnNn+r7wzNUeFLhH9 tJ7RvpGKXlcEkLnEXTdbVXLs9SwjcDH89pmdjXlKB103aa3iW2JpBFhTGEbgdeevB4OR 93fLZPFSWrdGUNLKP4UVyO8/c+JQr/lw/+z4moLMUSvFvFSRdoLRAhD4kFet4bbVPwwV G8ueEOuh8pCjPeb8kByzA9rQDGylLtR+kN6uHwxLzxPUMlwqt7Go3jZjK4GUBFi8V/iW AvZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=3vc4zow5ouRIkK+34pDeFXV49ZrhEwguifj5ZC0tQ5M=; b=qRwwUKWhOcn5njgFgIxntdG6bhjrSd++EDBhIFgrRn2pixgeNbXSco+6mhNNXWUiZm qF4549qWn1pBhUnP4OwZdPZCMtSNloecG2LWdQ82+mAmwmpoHEVviJny7QIKr6CjgehK fSDEbEqkH3viVKLa+gfeF5B2Y6O4MFTXBjk35CZKlEhxtZLqYqvSeUOxUxfzWi2gOwsX Mc2vyhzwJBJZIdivFoVGhU2XiUHRGCyOVZ8snQE+a4n9O79Thp5r2Qq8fD5JpcK14ew1 9t0BAqWUbjuBauBPZy1PpH9TyNvE0RZVa72jThSwjeGxkVEtf4eYrXQ+G5UKeRSLIbdd vpWA== X-Gm-Message-State: AOAM532VKkaRHrFsSVIImPxo4767eNpXEnaeuB2gXnbA51xu+5WpyqUz j3vtBIPX3MsU+mZtZILrUSHAhbFA6WkIZ64ckoVuly/2XRA= X-Google-Smtp-Source: ABdhPJxnUpSTBHAED65rhRMVUDI0yF9+mUugy9vRWEuYTsXPI2QFQ5RA2XaI7wVhYad1rmeoSOy5sbWmcy/VO+BYIgA= X-Received: by 2002:aa7:d1c8:0:b0:415:c61a:8ec8 with SMTP id g8-20020aa7d1c8000000b00415c61a8ec8mr11302025edp.390.1647047764930; Fri, 11 Mar 2022 17:16:04 -0800 (PST) X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::52c (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::52c; envelope-from=gsingh2011@gmail.com; helo=mail-ed1-x52c.google.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:228239 Archived-At: --000000000000f4f3c805d9fb3045 Content-Type: text/plain; charset="UTF-8" Calling (persist-save 'myvar) should persist the value of myvar to a file. However, it doesn't do this if the value of myvar is the same as the default value. See lines 135 and 136 of persist.el: https://git.savannah.gnu.org/cgit/emacs/elpa.git/tree/persist.el?h=externals/persist&id=2a2f83b4d63734ed48603008c813cfacd9e99404#n135 The intention here could have been that there's no need to persist the variable if the user doesn't change it from the default. But it leads to a bug in the following case: (require 'persist) (persist-defvar myvar nil "docstring") ; #1 (persist-save 'myvar) ; #2 (setq myvar "foo") (persist-save 'myvar) ; #3 (setq myvar nil) (persist-save 'myvar) ; #4 At #1, the value of myvar is not persisted, which is fine. If myvar was persisted in the past, that value would be loaded, otherwise (like in my case), it will be set to nil. At #2, explicitly calling persist-save does not persist myvar. This is unexpected, but still not a bug: the in-memory value of myvar (nil) is still equal to the default, and it is not persisted, so the next time the code runs the default will be loaded again. At #3, myvar is persisted. The value is now "foo", which is different from the default value of "nil". #4 is where the bug happens. The persisted value of myvar is "foo", but the in-memory value of myvar is nil. We *should* persist the new value here, so that on the next load of the symbol we get the latest value. However, because the current in-memory value is equal to the default value (nil), it's not persisted. The next time this code runs, it will load "foo" as the value of myvar instead of nil. One fix could be to remove the check to see if the value is set to the default. Another could be that if the value is set to the default, remove the persist file. System information from report-emacs-bug: In GNU Emacs 27.2 (build 1, x86_64-apple-darwin18.7.0, NS appkit-1671.60 Version 10.14.6 (Build 18G95)) of 2021-11-18 built on builder10-14.lan Windowing system distributor 'Apple', version 10.3.2113 System Description: macOS 12.2.1 Configured using: 'configure --with-ns '--enable-locallisppath=/Library/Application Support/Emacs/${version}/site-lisp:/Library/Application Support/Emacs/site-lisp' --with-modules' Configured features: NOTIFY KQUEUE ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS MODULES THREADS JSON PDUMPER GMP Important settings: value of $LANG: en_US.UTF-8 locale-coding-system: utf-8-unix Major mode: Lisp Interaction Minor modes in effect: tooltip-mode: t global-eldoc-mode: t eldoc-mode: t electric-indent-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t line-number-mode: t transient-mark-mode: t Load-path shadows: None found. Features: (shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs format-spec rfc822 mml mml-sec password-cache epa derived epg epg-config gnus-util rmail rmail-loaddefs text-property-search seq byte-opt gv bytecomp byte-compile cconv mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils persist ispell help-fns radix-tree cl-print debug backtrace help-mode easymenu find-func time-date subr-x cl-loaddefs cl-lib tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel term/ns-win ns-win ucs-normalize mule-util term/common-win tool-bar dnd fontset image regexp-opt fringe tabulated-list replace newcomment text-mode elisp-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock syntax facemenu font-core term/tty-colors frame minibuffer cl-generic cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese composite charscript charprop case-table epa-hook jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice loaddefs button faces cus-face macroexp files text-properties overlay sha1 md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote threads kqueue cocoa ns multi-tty make-network-process emacs) Memory information: ((conses 16 52205 6991) (symbols 48 6523 1) (strings 32 17870 1009) (string-bytes 1 596696) (vectors 16 10502) (vector-slots 8 132509 11576) (floats 8 27 44) (intervals 56 378 4) (buffers 1000 13)) --000000000000f4f3c805d9fb3045 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Calling (persist-save 'myvar) should persist the value= of myvar to a
file. However, it doesn't do this if the value of myv= ar is the same as
the default value. See lines 135 and 136 of persist.el= :
https://git.savannah.gnu.org/= cgit/emacs/elpa.git/tree/persist.el?h=3Dexternals/persist&id=3D2a2f83b4= d63734ed48603008c813cfacd9e99404#n135

The intention here could h= ave been that there's no need to persist the
variable if the user do= esn't change it from the default. But it leads
to a bug in the follo= wing case:

(require 'persist)
(persist-defvar myvar nil "= ;docstring") ; #1
(persist-save 'myvar) ; #2
(setq myvar &qu= ot;foo")
(persist-save 'myvar) ; #3
(setq myvar nil)
(per= sist-save 'myvar) ; #4

At #1, the value of myvar is not persiste= d, which is fine. If myvar
was persisted in the past, that value would b= e loaded, otherwise (like
in my case), it will be set to nil.

At = #2, explicitly calling persist-save does not persist myvar. This is
unex= pected, but still not a bug: the in-memory value of myvar (nil) is
still= equal to the default, and it is not persisted, so the next time
the cod= e runs the default will be loaded again.

At #3, myvar is persisted. = The value is now "foo", which is different
from the default va= lue of "nil".

#4 is where the bug happens. The persisted v= alue of myvar is "foo",
but the in-memory value of myvar is ni= l. We *should* persist the new
value here, so that on the next load of t= he symbol we get the latest
value. However, because the current in-memor= y value is equal to the
default value (nil), it's not persisted. The= next time this code runs,
it will load "foo" as the value of = myvar instead of nil.

One fix could be to remove the check to see if= the value is set to the
default. Another could be that if the value is = set to the default,
remove the persist file.

Syst= em information from report-emacs-bug:

In GNU Emacs 27.2 (build 1, x8= 6_64-apple-darwin18.7.0, NS appkit-1671.60 Version 10.14.6 (Build 18G95))=C2=A0of 2021-11-18 built on builder10-14.lan
Windowing system distrib= utor 'Apple', version 10.3.2113
System Description: =C2=A0macOS = 12.2.1

Configured using:
=C2=A0'configure --with-ns '--en= able-locallisppath=3D/Library/Application
=C2=A0Support/Emacs/${version}= /site-lisp:/Library/Application
=C2=A0Support/Emacs/site-lisp' --wit= h-modules'

Configured features:
NOTIFY KQUEUE ACL GNUTLS LIBX= ML2 ZLIB TOOLKIT_SCROLL_BARS NS MODULES
THREADS JSON PDUMPER GMP

= Important settings:
=C2=A0 value of $LANG: en_US.UTF-8
=C2=A0 locale-= coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor = modes in effect:
=C2=A0 tooltip-mode: t
=C2=A0 global-eldoc-mode: t=C2=A0 eldoc-mode: t
=C2=A0 electric-indent-mode: t
=C2=A0 mouse-wh= eel-mode: t
=C2=A0 tool-bar-mode: t
=C2=A0 menu-bar-mode: t
=C2=A0= file-name-shadow-mode: t
=C2=A0 global-font-lock-mode: t
=C2=A0 font= -lock-mode: t
=C2=A0 blink-cursor-mode: t
=C2=A0 auto-composition-mod= e: t
=C2=A0 auto-encryption-mode: t
=C2=A0 auto-compression-mode: t=C2=A0 line-number-mode: t
=C2=A0 transient-mark-mode: t

Load-p= ath shadows:
None found.

Features:
(shadow sort mail-extr emac= sbug message rmc puny dired dired-loaddefs
format-spec rfc822 mml mml-se= c password-cache epa derived epg epg-config
gnus-util rmail rmail-loadde= fs text-property-search seq byte-opt gv
bytecomp byte-compile cconv mm-d= ecode mm-bodies mm-encode mail-parse
rfc2231 mailabbrev gmm-utils mailhe= ader sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils p= ersist ispell help-fns
radix-tree cl-print debug backtrace help-mode eas= ymenu find-func
time-date subr-x cl-loaddefs cl-lib tooltip eldoc electr= ic uniquify
ediff-hook vc-hooks lisp-float-type mwheel term/ns-win ns-wi= n
ucs-normalize mule-util term/common-win tool-bar dnd fontset image
= regexp-opt fringe tabulated-list replace newcomment text-mode elisp-modelisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch
= timer select scroll-bar mouse jit-lock font-lock syntax facemenu
font-co= re term/tty-colors frame minibuffer cl-generic cham georgian
utf-8-lang = misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms = cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyri= llic chinese composite charscript charprop
case-table epa-hook jka-cmpr-= hook help simple abbrev obarray
cl-preloaded nadvice loaddefs button fac= es cus-face macroexp files
text-properties overlay sha1 md5 base64 forma= t env code-pages mule
custom widget hashtable-print-readable backquote t= hreads kqueue cocoa ns
multi-tty make-network-process emacs)

Memo= ry information:
((conses 16 52205 6991)
=C2=A0(symbols 48 6523 1)
= =C2=A0(strings 32 17870 1009)
=C2=A0(string-bytes 1 596696)
=C2=A0(ve= ctors 16 10502)
=C2=A0(vector-slots 8 132509 11576)
=C2=A0(floats 8 2= 7 44)
=C2=A0(intervals 56 378 4)
=C2=A0(buffers 1000 13))
--000000000000f4f3c805d9fb3045--