2

I'm using undo-tree with AUCTeX, and I am persisting my undo files like so:

(setq undo-tree-auto-save-history t)

Unfortunately, this regularly results in large (~1MB) undo save files which cause my Emacs to hang when they're loaded. The reason for this is the large number of text-properties that AUCTeX puts on its buffer contents, which bloats the file by orders of magnitude.

Is it safe to remove these properties from the save file, and if so, how can I do so?

  • As this one was also your question, I'm assuming that you've already attempted a variant of emacs.stackexchange.com/q/4187 with no success? – phils Feb 19 '17 at 21:49
  • @phils unfortunately, things are not as simple for undo-history. I do think it's possible I'll find a variation that works, but not yet. – PythonNut Feb 19 '17 at 23:07
  • 1
    I don't know anything about undo-tree, but my reading of buffer-undo-list indicates that text (and therefore text properties) should exist only for deletions, where the car of the entry is the text in question. So you might try using or adapting something like this? (dolist (x buffer-undo-list) (and (consp x) (stringp (car x)) (setcar x (substring-no-properties (car x))))) – phils Feb 19 '17 at 23:45
2

Here is the solution I eventually came up with. (Thanks to @phils for optimizations). As far as I can tell, it seems to be working without issues.

(defun nadvice/undo-tree-ignore-text-properties (old-fun &rest args)
  (dolist (item buffer-undo-list)
    (and (consp item)
         (stringp (car item))
         (setcar item (substring-no-properties (car item)))))
  (apply old-fun args))

(advice-add 'undo-list-transfer-to-tree :around
            #'nadvice/undo-tree-ignore-text-properties)
  • See the answer by Tobias in this related thread entitled "undo-tree — history file without text-properties": emacs.stackexchange.com/a/32230/2287 – lawlist May 2 '17 at 18:21
  • Indeed, that is a superior solution. Thanks! – PythonNut May 2 '17 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.