5

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.

lawlist
  • 18,826
  • 5
  • 37
  • 118
  • 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. :-) – Constantine Nov 19 '14 at 03:56
  • @Constantine Where do you see this being explicitly excluded? – tarsius Dec 27 '14 at 13:36
  • @tarsius: If you check [`buffer.c`](http://git.savannah.gnu.org/cgit/emacs.git/tree/src/buffer.c?id=83bad90efe943e7c88431b7a71bc1d5cf1304c92#n1274) you can see that `buffer-local-variables` uses `FOR_EACH_PER_BUFFER_OBJECT_AT`. This macro is defined in [`buffer.h`](http://git.savannah.gnu.org/cgit/emacs.git/tree/src/buffer.h?id=83bad90efe943e7c88431b7a71bc1d5cf1304c92#n1252). 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. – Constantine Dec 28 '14 at 21:10

1 Answers1

4

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.

Stefan
  • 26,154
  • 3
  • 46
  • 84
  • 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 Nov 10 '18 at 17:51