GNU bug report logs - #68482
29.1; multisession does not seem to work with maps (e.g. alists or hash tables)

Previous Next

Package: emacs;

Reported by: Adam Porter <adam <at> alphapapa.net>

Date: Mon, 15 Jan 2024 19:29:02 UTC

Severity: normal

Found in version 29.1

To reply to this bug, email your comments to 68482 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#68482; Package emacs. (Mon, 15 Jan 2024 19:29:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Adam Porter <adam <at> alphapapa.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 15 Jan 2024 19:29:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Adam Porter <adam <at> alphapapa.net>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.1; multisession does not seem to work with maps (e.g. alists or
 hash tables)
Date: Mon, 15 Jan 2024 13:28:34 -0600
I've noticed that `multisession' does not seem to work with maps,
including alists and hash tables, although it does not seem to mention
this in the documentation.

Specifically, setting an initial value in an empty alist does cause the 
value file to be written to disk.  But afterward, updating the map 
leaves the file on disk un-updated, so after restarting Emacs, only the 
original value is available.

I found no tests in multisession-tests.el that would seem to cover these
use cases, so here are a couple that indeed fail, showing that it does
not work with them:

  (ert-deftest multi-test-files-alist-values ()
    (ert-with-temp-file dir
      :directory t
      (let ((user-init-file "/tmp/sfoo.el")
            (multisession-storage 'files)
            (multisession-directory dir)
            last-sequence)
        (define-multisession-variable multisession--alist nil)
        (should (eq (multisession-value multisession--alist) nil)) ; 
Comment out for interactive testing.

        ;; There seems to be no way to "unload" a multisession variable
        ;; within a session, so we test the sequence number to ensure
        ;; that the value was rewritten.

        (setf (alist-get 'KEY (multisession-value multisession--alist)) 1)
        (should (eq (alist-get 'KEY (multisession-value 
multisession--alist)) 1))
        ;; The file should have been written now, setting the sequence.
        (should (setf last-sequence (multisession--cached-sequence 
multisession--alist)))

        (setf (alist-get 'KEY (multisession-value multisession--alist)) 2)
        (should (eq (alist-get 'KEY (multisession-value 
multisession--alist)) 2))
        ;; The file should have been written again now, so the sequence
        ;; should have changed.
        (should-not (equal last-sequence (multisession--cached-sequence 
multisession--alist))))))

  (ert-deftest multi-test-files-hash-table-values ()
    (ert-with-temp-file dir
      :directory t
      (let ((user-init-file "/tmp/sfoo.el")
            (multisession-storage 'files)
            (multisession-directory dir)
            last-sequence)
        (define-multisession-variable multisession--hash-table 
(make-hash-table))
        (should (hash-table-p (multisession-value 
multisession--hash-table)))

        (setf (map-elt (multisession-value multisession--hash-table) 
'KEY) 1)
        (should (eq (map-elt (multisession-value 
multisession--hash-table) 'KEY) 1))
        ;; The file should have been written now, setting the sequence.
        (should (setf last-sequence (multisession--cached-sequence 
multisession--hash-table)))

        (setf (map-elt (multisession-value multisession--hash-table) 
'KEY) 2)
        (should (eq (map-elt (multisession-value 
multisession--hash-table) 'KEY) 2))
        ;; The file should have been written again now, so the sequence
        ;; should have changed.
        (should-not (equal last-sequence (multisession--cached-sequence
        multisession--hash-table))))))

I don't know how to fix this.  But AFAICT the persist.el library on
GNU ELPA does work with maps, so it may have some good examples.

Thanks,
Adam




This bug report was last modified 1 year and 151 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.