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…
:) /\

  • Sunoc@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    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)))

    • EduMercoOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      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)))

      I tried it but still no joy…

      Looking at this issue I noticed 3 things that may help to pinpoint the origin…:

      • I have 2 variables set that affect the scratch buffer in my config (without yours, that it’s the 3rd):
                        (setq initial-major-mode 'org-mode)
                        (setq-default major-mode 'org-mode)
      
      • Before this reply, (setq-default major-mode 'org-mode) was (setq default-major-mode 'org-mode). Both expressions seems indistinguishable in the resulted behavior.
      • The scratch buffer starts in org-roam mode (and read-only mode), which is very strange, but can obviously be related and/or part of the problem. The org-roam section (my config is literate in org-mode) comes before this variables being set.

      What does this info may imply?

      • Sunoc@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        Okay, I could reproduce your situation by evaluating

        (setq initial-major-mode 'org-mode)
        (setq-default major-mode 'org-mode)
        

        This setup forces the scratch buffer to be in org-mode, apparently breaking most of the available keybindings for it, including the undo.

        The value for the initial-major-mode should be kept as lisp-interaction-mode, if your configuration requires to set it.

        Otherwise I would remove both of these lines all together and see if the default behavior brings back the scratch buffer to be in the expected lisp-interaction-mode again. The additional hook I provided in my previous post shouldn’t be needed either.