Skip to content

Commit

Permalink
Add: (ement--savehist-save-hook) Workaround for savehist-mode
Browse files Browse the repository at this point in the history
Fixes #216.

Reported-by: Phil Sainty <phil@catalyst.net.nz>
  • Loading branch information
alphapapa committed Sep 14, 2023
1 parent 358b125 commit 8363bfc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.org
Expand Up @@ -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

Expand Down
20 changes: 20 additions & 0 deletions ement.el
Expand Up @@ -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)
Expand Down

0 comments on commit 8363bfc

Please sign in to comment.