From b379d8d1779e0190541ef7f8adf39dfe4d4c551a Mon Sep 17 00:00:00 2001 From: Joseph Turner Date: Sat, 2 Sep 2023 16:52:31 -0700 Subject: [PATCH 2/5] Add persist-equal * persist.el (persist-hash-equal): Like equal, but compares hash tables also. See bug#63671 for a discussion of built-in hash table comparison. --- persist.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/persist.el b/persist.el index d80943d19e..a707d038cd 100644 --- a/persist.el +++ b/persist.el @@ -187,5 +187,25 @@ (defun persist--save-all () (add-hook 'kill-emacs-hook 'persist--save-all) +(defun persist-equal (a b) + "Return non-nil when the values of A and B are equal. +A and B are compared using `equal' unless they are both hash +tables. In that case, the following are compared: + +- hash table count +- hash table predicate +- values, using `persist-equal'" + (if (and (hash-table-p a) (hash-table-p b)) + (and (= (hash-table-count a) (hash-table-count b)) + (eq (hash-table-test a) (hash-table-test b)) + (catch 'done + (maphash + (lambda (key a-value) + (unless (persist-equal a-value (gethash key b (not a-value))) + (throw 'done nil))) + a) + t)) + (equal a b))) + (provide 'persist) ;;; persist.el ends here -- 2.41.0