4

The book Clean code says emacs can play back an edit session (page 13):

You could work for an hour and then play back your whole edit session like a high-speed movie. When I did this, the results were fascinating.

The vast majority of the playback was scrolling and navigating to other modules!

Bob enters the module.
He scrolls down to the function needing change.
He pauses, considering his options.
Oh, he’s scrolling up to the top of the module to check the initialization of a variable. Now he scrolls back down and begins to type.

I want to do play back my own edit session, but I didn't find a way to accomplish this through googling. Can someone help me? Thanks a lot!

  • Yeah I also wondered how Bob managed this. I have not been able to find anything like this exactly. However, there are some packages now for recording gifs or screencasts like this one : gitlab.com/ambrevar/emacs-gif-screencast – shoshin Jan 30 at 17:25
4

I suspect Bob is exercising creative license in his description. To my knowledge, there isn't a formal playback functionality. This is because not everything in Emacs is strictly reversible.

Here are a few ways to achieve playback-like behavior:

undo

You ought to be able to achieve the same result, at least in spirit, with the default undo command (typically bound to C-/). Press C-/ until there is nothing left to undo. Then, press C-f. Now press C-/ repeatedly to redo.

The undo/redo will appear "chunky". This is because undo tracks "inserts" and not individual commands. For a detailed explanation of how undo works, see the Reddit post "How Emacs Undo Works".

undo-tree

You can achieve a fine-grain undo with undo-tree. User lawlist1 provides code that modifies the default to provide key-for-key undo:

(require 'undo-tree)
(when (timerp undo-auto-current-boundary-timer)
  (cancel-timer undo-auto-current-boundary-timer))

(fset 'undo-auto--undoable-change
      (lambda () (add-to-list 'undo-auto--undoably-changed-buffers (current-buffer))))

(fset 'undo-auto-amalgamate 'ignore)

This will undo/redo character insertions, copy/paste, etc. You can navigate these easily with undo-tree-visualize. However, undo-tree doesn't record movements. It only tracks changes.

further commentary

The section quoted looks a lot like what displays in view-lossage. Pressing C-h l runs view-lossage which shows the last 300 commands. Keystrokes can also be logged in raw form to a "dribble" file using (open-dribble-file FILE). I'm not aware of a way to "play back" lossage or a dribble, however.

Seeing which commands are most frequently used, the point Bob is emphasizing with his anecdote, can be achieved with keyfreq. Bin Chen's "How to be extremely efficient in Emacs" demonstrates its usage.


1If you like lawlist's snippet, give the post an upvote!

3

This is within the one buffer , not for the whole session, but it is worth mentioning:

With undo-tree , for example: https://www.emacswiki.org/emacs/UndoTree

You open undo tree buffer with C-x u then up and down arrow to step through your history while seeing it change in the original buffer.

I actually never went fast forward until you asked... but it does just run through your history.

q to quit by the way...

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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