5

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!

Alaneuler
  • 277
  • 1
  • 8
  • 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 : https://gitlab.com/ambrevar/emacs-gif-screencast – shoshin Jan 30 '19 at 17:25

2 Answers2

6

Bob is likely referring to the undo-browse.el package. According to the package's ub-introduction command,

In ub terminology, the undo-history is seen as a movie, each step being a frame of the movie. You can play (back/forth) the color-coded movie-history of your document, or manually go back and forth, and revert your document to the frame you like.

A little history...

The undo-browse.el package is written by Deepak Goel whose name disappears from the Internet record around 2012. This is back in the Emacs 21 days, before ELPA became the standard. Deepak seems to have been quite active in the Emacs community and published a lot of Emacs lisp in the early 2000's. Unfortunately, it looks like undo-browse, along with his many other packages, were never published to ELPA, MELPA, or Marmalade. His webpage is down and many links to his packages are now dead. I suspect his work is mostly forgotten because of this.

Clean Code was first published in 2009, before Deepak's disappearance. His packages would still have been available then. This leads me to believe Bob was using undo-browse.


Running undo-browse nowadays is a little tricky. Its implementation is...unconventional. I haven't had much luck getting it to work as described.

Here are a few ways to achieve playback-like behavior using more recent packages:

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!

Lorem Ipsum
  • 4,327
  • 2
  • 14
  • 35
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...

manandearth
  • 2,068
  • 1
  • 11
  • 23
  • A word of warning about `undo-tree`: it doesn't always retain the history. See: https://github.com/emacs-evil/evil/issues/1074 – Lorem Ipsum Jan 30 '19 at 17:48