Resolving conflicts (in version control)

When Git (or another VCS) attempts to apply a patch that doesn't apply cleanly, it will defer to you, the user, to figure out the right thing to do. Usually you get, dumped in your lap, a file that has all these funny conflict markers in it, showing alternative versions of the content:

    <action name="Execute"><execute>google-chrome</execute></action>
  </keybind>
  <keybind key="W-s-b">
<<<<<<< HEAD
    <action name="Execute"><execute>firefox-3.6</execute></action>
=======
    <action name="Execute"><execute>firefox-3.7</execute></action>
>>>>>>> f50523b...
  </keybind>
  <keybind key="W-a">
    <action name="Execute"><execute>rhythmbox</execute></action>

You can edit that file by hand to get the state you want, but Emacs has a specialized mode for resolving conflicts. Type M‑x vc‑resolve‑conflicts and you get a three-paned frame like the following:

  • Press n and p to move between diff hunks.
  • For each hunk you can press a or b to transfer the version from the left or right side, respectively, to the output. You can leave the conflicted versions if there's something you really need to fix up by hand.
  • Press q when you're done. Emacs returns you to your fixed-up file. Save it.

Some Emacs macro tricks

Keyboard macros are the Emacs feature that I wish every program had. Especially web browsers: having to carry out repetitive tasks in web apps always feels to me like a throwback to a less civilized era.

(More information about keyboard macros, for the uninitiated: see #2.)

Here are some useful macro-related commands that I recently learned to use:

Extending a macro. If you record a macro, then realize you forgot to add an important step at the end, you don't have to re-record it. C-u F3 replays the last macro and then lets you tack on more commands to the end of it.

For example, C-u F3 RET F4 replays the last macro and then appends RET to the end of it. (You can also use C-u C-u F3 ... F4 to extend a macro without replaying it again first.)

Editing a macro. For more intensive fixes or changes to macros, you can edit your most recent macro with C-x C-k C-e (kmacro-edit-macro-repeat). You get a buffer like the following, and you can remove keystrokes or add new ones:

;; Keyboard Macro Editor.
;; Press C-c C-c to finish; press C-x k RET to cancel.
;; Original keys: ESC c ESC f ESC f ESC f C-d RET<

Command: last-kbd-macro
Key: none

Macro:

ESC c   ;; capitalize-word
ESC f   ;; forward-word
ESC f   ;; forward-word
ESC f   ;; forward-word
C-d   ;; delete-char
RET   ;; newline

Creating a macro from your keyboard history. If you just performed some task that you'd like to repeat, but didn't have the foresight to start recording a macro before you started, all is not lost. C-x C-k l (kmacro-edit-lossage) brings up a buffer (like the edit buffer above) containing your most recent 300 keystrokes, which you can pare down to create a new macro.

Bringing Gmail Muzzle out of retirement

I really liked the Gmail Labs "Muzzle" feature, which hides the status messages of contacts in the Gmail chat list. Unfortunately, Google retired this lab last week.

Happily, Yojimbow has replicated the functionality of Muzzle in a Greasemonkey script. (The script is only 8 lines long, with just 2 lines of Javascript! A very elegant solution.)

Firefox users can install Greasemonkey, and then install this user script; meanwhile, Google Chrome natively understands user scripts (making them look like extensions), and you can just click on links to them to install.