1

Having run into a bug with undo-tree, I'd rather use emacs default undo.

Mapping undo to undo-only and redo to undo.

This requires pressing Ctrl-G then undo to effectively redo an operation.

Is there a way to make the Ctrl-G implicit, so I don't need to press it in cases I've just used undo-only?

  • Not an answer to your question, but since you expressly mentioned a problem with the undo-tree library relating to the canary bug, the following snippet should fix the canary error: (setq undo-tree-enable-undo-in-region nil) – lawlist Aug 3 '19 at 5:11
  • Yes, I've tried this but still get the bug occasionally. – ideasman42 Aug 3 '19 at 5:12
1

Note, this is now available as a package undo-fu which also provides improved redo support.


Yes, it is possible. You need to write a wrapper.

  • For redo that sets the last-command to ignore.
  • The last-command is set to undo because undo internal logic checks for this.
  • condition-case is used so failing to undo doesn't prevent this-command from being set.
(defun simple-redo ()
  (interactive)
  (let
    (
      (last-command
        (cond
          ;; Break undo chain, avoid having to press Ctrl-G.
          ((string= last-command 'simple-undo) 'ignore)
          ;; Emacs undo uses this to detect successive undo calls.
          ((string= last-command 'simple-redo) 'undo)
          (t last-command))))
    (condition-case err
      (progn
        (undo) t)
      (error
        (message "%s" (error-message-string err)))))
  (setq this-command 'simple-redo))

(defun simple-undo ()
  (interactive)
  (let
    (
      (last-command
        (cond
          ;; Emacs undo uses this to detect successive undo calls.
          ((string= last-command 'simple-undo) 'undo)
          ((string= last-command 'simple-redo) 'undo)
          (t last-command))))
    (condition-case err
      (progn
        (undo-only) t)
      (error
        (message "%s" (error-message-string err)))))
  (setq this-command 'simple-undo))

Note that I've been using this for some months now and find it a surprisingly good alternative to more complex undo wrappers which were never entirely stable for me.

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.