I am modifying desktop.el to support restoring the buffer-undo-list, and am push-ing that list at the tail end of the function desktop-buffer-info because the buffer-undo-list is not included in the output of the function buffer-local-variables.

Q: Is there a built-in method to include the buffer-undo-list in the output of the function buffer-local-variables? If not, is there a reason why it's not included?

To make the buffer-undo-list get stored into the desktop file, I add:

(push (cons 'buffer-undo-list buffer-undo-list) ll)

It works, but I'd like to understand why a seemingly buffer-local variable is excluded from the function buffer-local-variables.

  • 2
    As far as I can tell buffer-undo-list is explicitly excluded from the return value of buffer-local-variables, but reasons are unclear. I ran git blame on buffer.{c|h}; seems like Stefan Monnier is the right person to ask. :-) Commented Nov 19, 2014 at 3:56
  • @Constantine Where do you see this being explicitly excluded?
    – tarsius
    Commented Dec 27, 2014 at 13:36
  • @tarsius: If you check buffer.c you can see that buffer-local-variables uses FOR_EACH_PER_BUFFER_OBJECT_AT. This macro is defined in buffer.h. The comment above FOR_EACH_PER_BUFFER_OBJECT_AT tells me that buffer-undo-list is excluded because it is not a "normal" Lisp_Object field of the buffer struct. Why it is not normal I do not know. Commented Dec 28, 2014 at 21:10

1 Answer 1


IIUC buffer-undo-list is missing from buffer-local-variables by accident. The accident is that some code clean up ended up making buffer-local-variables use the same loop over some of the buffer's local variables, as the loop used when the garbage collector looks for references in a buffer object.

As it turns out, buffer-undo-list needs to be handled specially by the GC because we try to throw away elements from it (i.e. some of the entries are treated as "weak references"). E.g. we throw away undo entries which manipulate markers which are not used elsewhere any more.

IOW I think it's just a plain bug, which you might like to report.

  • I gather no bug report was created for this? I still see this issue, would really like to be able to save the buffer-undo-list with desktop-save-mode. :)
    – terje
    Commented Nov 10, 2018 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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