Skip Navigation

How to make undo work in the scratch buffer

Dear fellow emacsers.

How can we make undo work on the scratch buffer? I'm sure it is a simple configuration issue, but I'm not getting the appropriate keyword to find the relevant documentation.

Thanks a lot in advance for your help and attention...
:) /\

6
6 comments
  • Hi, That's a surprising issue, especially if the scratch buffer is the only text buffer in which the undo doesn't work. Here is what I'm thinking right now:

    • Just to be sure, isn't your scratch buffer in read-only ? You can toggle that with C-x C-q.
    • Is the keybinding you are using to undo set properly ? You can check it with C-h k C-/ (for example, for checking C-/).
    • If it's none of these, I'd try to run the undo function directly with M-x undo to see if you can get some meaningful error messages.

    I confirmed with both my personal config that uses undo-tree (great tool btw) and also in a default configuration of Emacs; both cases work fine to undo in scratch.

    Hope any of that can help!

    Cheers

    • Hello Sunoc.

      • the buffer is not in read-only, but it always start as so.
      • the keybinding is ok since it works in all the rest of the buffers.
      • Upon calling undo, emacs says "no undo information in this buffer" (searching for this didn't seem to give relevant information except something from 2006 and then something about specific of a table-spreadsheet that I don't use).

      From this and @[email protected] (I will relpy after this one) it looks that it may be my configuration, since I'm using vanilla emacs with my own configuration.

      Anyway, thanks a lot for your time! :)

      • After checking the source, it looks like this error is triggered when the buffer-undo-list variable is equal to t, which means the buffer is unmodified, or at least that this variable is not modified from the scratch buffer.

        There is something else in the documentation of this variable: <If the value of the variable is t, undo information is not recorded.> Maybe you can try to fix your issue by forcing the buffer-undo-list variable to nil for the elisp mode, as follow:

        (add-hook 'elisp-mode (lambda () (setq-local buffer-undo-list nil)))

  • By default undo does work in the scratch buffer so it is something in your configuration that is keeping this from working. As a quick way to check, try running emacs -q, which skips loading your configuration, and see if you have undo in the scratch buffer there; if so, it's definitely something you have in you configuration.

    You can bisect your configuration to figure out how you are deactivating undo. You can do this manually or with the help of the bug-hunter package.

6 comments