learning emacs incrementally

I’m taking a Coursera course that encourages using emacs as an editor. I’ve been fluent in vi for over a decade so this seemed like a good time to try out emacs. You don’t actually need to use emacs for the class; it is just adding syntax highlighting. However, being minimally functional in emacs happened within two hours. And that was focusing on sml and not emacs. The idea is to become minimally functional quickly and then add “optimizations” to become faster.

Minimally functional commands:

Note that C means Control and M means meta (which is the escape key on the mac rather than alt – annoying because I can touch type alt but not escape)

  1. C-x, C-f – open a file
  2. C-x, C-s – save current file – I use this one a lot!
  3. C-x, C-c – quit emacs
  4. C-x 0 (that is a zero) – close the current split window and merge into one
  5. C-x o (that is a lower case o) – switch between split windows
  6. C-x 2 – split into two buffers – I actually stopped using this pretty quickly as I found it easier to have two tabs with emacs open.  I’ve seen multiple buffers used very effectively though.
  7. C-c, C-s – open sml RPEL – I stopped using this quickly as well
  8. Cx Cc – prompt to save and exit
  9. C-D – restart RPEL – stopped using as well
  10. M-p -previous RPEL – stopped using as well

Second iteration of using emacs better – navigating with the keyboard

  1. C-a – beginning of line
  2. C-e – end of line
  3. C-v – page down
  4. M-v page up – note must re-press escape each time
  5. C-s – regular expression search

Third iteration

  1. C-k – delete to end of line
  2. M < – beginning of file (yes that is escape + shift + , on a mac
  3. M > – end of file

And that’s as far as I got.  I was able to have “emacs” not get in my way with just this.  I can’t even call what I did learning emacs since I know there are many features that would make it more efficient.  But it was enough for the class.  And then I go back to vi.

svn, global search/replace and recovery

I started with a nice simple problem: do a global search and replace on the image directory path to save bandwidth (by pointing to a caching server.)  I used this regular expression and then had two problems:

  1. This isn’t easy to read (which isn’t a huge deal since I only have to run it once.)
  2. The find and replace updated the hidden .svn directory too.  Which meant when I went to sync with SVN, it thought it was up to date and didn’t commit anything.
More on both these problems.
Problem 1 – Unreadable regexp

find $path/templates/default -type f | xargs perl -pi -e ‘s/\$\{contextPath\}\/templates\/default\/images/\$\{imagesServedFrom\}\/templates\/default\/images/g’

All right.  What does this do?
  1. Find all files in the templates/default directory or any subdirectories
  2. Do a search for ${contextPath}/templates/default/images and replace with ${imagesServedFrom}/templates/default/images
I’m sure there is a clearer way of writing this.  I didn’t bother once I had something working because I only have to run it once.  (Famous last words, I know.)
Problem 2 – Updating SVN

The bigger problem is that I made a bunch of other changes in my commit and didn’t notice that none of the template/default/image changes got committed.  Eclipse/SVN didn’t commit the changed files because the .svn directory’s base file was changed as well.

I solved this by disconnecting from SVN in Eclipse. (Team disconnect) and deleting the metadata when prompted.  I then reconnected to SVN, Eclipse saw the difference and I committed normally.

If I was doing this again, I’d update the find statement to exclude the .svn directories.