emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ement 8363bfcdc2 4/4: Add: (ement--savehist-save-hook)


From: ELPA Syncer
Subject: [elpa] externals/ement 8363bfcdc2 4/4: Add: (ement--savehist-save-hook) Workaround for savehist-mode
Date: Thu, 14 Sep 2023 12:58:08 -0400 (EDT)

branch: externals/ement
commit 8363bfcdc29468b6e618e38ef880c4cc051da57d
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>

    Add: (ement--savehist-save-hook) Workaround for savehist-mode
    
    Fixes #216.
    
    Reported-by: Phil Sainty <phil@catalyst.net.nz>
---
 README.org |  1 +
 ement.el   | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/README.org b/README.org
index 207697bd06..3531bff6d9 100644
--- a/README.org
+++ b/README.org
@@ -313,6 +313,7 @@ Ement.el doesn't support encrypted rooms natively, but it 
can be used transparen
 + File event formatter assumed that file size metadata would be present (a 
malformed, e.g. spam, event might not have it).
 + Send correct file size when sending files/images.
 + Underscores are no longer interpreted as denoting subscripts when sending 
messages in Org format.  (Thanks to [[https://github.com/phil-s][Phil Sainty]].)
++ Add workaround for ~savehist-mode~'s serializing of the ~command-history~ 
variable's arguments.  (For ~ement-~ commands, that may include large data 
structures, like ~ement-session~ structs, which should never be serialized or 
reused, and ~savehist~'s doing so could cause noticeable delays for users who 
enabled it).  (See [[https://github.com/alphapapa/ement.el/issues/216][#216]].  
Thanks to [[https://github.com/phil-s][Phil Sainty]] and other users who helped 
to discover this problem.)
 
 ** 0.11
 
diff --git a/ement.el b/ement.el
index 8eb9187ca2..1baa9984e6 100644
--- a/ement.el
+++ b/ement.el
@@ -1063,6 +1063,26 @@ To be called after initial sync."
             (when-let ((child-room (cl-find child-id rooms :key 
#'ement-room-id :test #'equal)))
               (cl-pushnew parent-id (alist-get 'parents (ement-room-local 
child-room)) :test #'equal))))))))
 
+;;;;; Savehist compatibility
+
+;; See <https://github.com/alphapapa/ement.el/issues/216>.
+
+(defvar savehist-save-hook)
+
+(with-eval-after-load 'savehist
+  ;; TODO: Consider using a symbol property on our commands and checking that 
rather than
+  ;; symbol names; would avoid consing.
+  (defun ement--savehist-save-hook ()
+    "Remove all `ement-' commands from `command-history'.
+Because when `savehist' saves `command-history', it includes the
+interactive arguments passed to the command, which in our case
+includes large data structures that should never be persisted!"
+    (setf command-history
+          (cl-remove-if (pcase-lambda (`(,command . ,_))
+                          (string-match-p (rx bos "ement-") (symbol-name 
command)))
+                        command-history)))
+  (cl-pushnew 'ement--savehist-save-hook savehist-save-hook))
+
 ;;;; Footer
 
 (provide 'ement)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]