* bug#68482: 29.1; multisession does not seem to work with maps (e.g. alists or hash tables)
@ 2024-01-15 19:28 Adam Porter
0 siblings, 0 replies; only message in thread
From: Adam Porter @ 2024-01-15 19:28 UTC (permalink / raw)
To: 68482
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-01-15 19:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-15 19:28 bug#68482: 29.1; multisession does not seem to work with maps (e.g. alists or hash tables) Adam Porter
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).