Archive for the ‘Emacs’ Category

Emacs in a terminal on OSX

My development workflow is based around a full-screen terminal running GNU screen (actually, Byobu, with the escape key mapped to j so that ctrl-a will still work…nice since is under the index finger, so very fast and gives the pinky a break), with one screen devoted to Emacs. I recently started working for a great company, and they supplied me with a new MacBook, so I needed to figure out how to get my Ubuntu workflow working on OSX.

Here is the short list of how I did that:

  • Install iTerm for true full-screen terminal loveliness
  • Disable OSX option-key madness so option keys work in the terminal:
    1. Bookmarks > Manage Profiles
    2. expand Keyboard Profiles
    3. select your keyboard profile and change “Option Key as” to “Meta”
  • Install a modern version of Emacs (the one that comes on OSX 10.6 is way out of date). Unfortunately, $ brew install emacs failed, but a blog post pointed out how to install Emacs 24 from Homebrew head:
    $ brew install emacs --use-git-head --HEAD

    (note that I removed the –cocoa option from the line used in the blog post since the goal is Emacs in a terminal)

  • Set up your Emacs configuration (or use the Emacs Starter Kit–here are my custom configurations on top of the starter kit)

The big problem remaining after taking these steps was that the kill-ring could not access the clipboard. On Ubuntu, xclip.el enabled a terminal based Emacs to access the Gnome clipboard via the xclip utility. On Mac OSX, there are a pair of utilities called pbcopy and pbpaste that do the same thing, so I modified xclip.el (written by Leo Shidai Liu) to work with those.

Here it is:

Activate via:
(require ‘pbcopy)


Read Full Post »

(For some reason, I found it difficult to find the solution to this online. I googled for it in the past, but always without success. Hopefully, this will help anyone else who wants to exclude / omit / ignore directories from an rgrep search in Emacs.)

rgrep performs grep recursively on a directory and all the directories contained therein. The nice thing about rgrep in Emacs–versus, say, ack–is that:

  1. it prompts you for the starting directory (and ido still works!)
  2. it prompts for the file name pattern to search (but defaults to the current extension, so you can just hit <return>)
  3. the line isn’t filled up with the raw grep or ack command

The Emacs grep commands already intelligently omit certain directories, but I am spending a lot of time in Rails projects, and rgrep-ing from the project root would dive into the “log” and “vendor” directories. Rails development and testing logs can become very large (which slows down rgrep) and often include a match for the term I am searching (so the search results would consist mainly of log entries). The vendor directory can contain a very large number of files (especially when Rails is frozen into the project), and I usually don’t want search results from 3rd party plugins or the Rails source.

The solution is the grep-find-ignored-directories option:
M-x customize-option

Add “log” and “vendor” as omitted directories, and then “save for future sessions”. That saves the settings to custom.el in your .emacs.d directory. If you keep your .emacs.d directory under source control (as you can do for free at Github if you make it a public repository), make sure you don’t exclude custom.el.

Note that if you ever do want to search the vendor directory, you can simply set the vendor directory as the “Base directory” in the rgrep prompt.

Unfortunately, this doesn’t appear to be taken into account by find-grep-dired, which is how I perform global search and replace. If anyone knows how to do this for find-grep-dired, please leave a comment. Thanks!

Read Full Post »

Slide presentation containing some useful links. Some slides are merely placeholders for me to talk around, so not very interesting.

Read Full Post »

My Global Git Settings

$ git config --global github.user <your GitHub user name>
$ git config --global github.token <your GitHub API token>
$ git config --global color.ui "auto"

The user and token settings work with gist.el (available through elpa: M-x package-list-packages, mark for installation by moving the cursor to desired line and pressing i, execute installation by pressing x). Once installed, you can easily create new Gists of the selected region or buffer. Use apropos to find a complete list of gist commands: C-h a gist- enter.

The color.ui setting results in nice red and green colorization of path names and diff results.

Read Full Post »

Caps lock is a wide key on the home row (at least for standard US keyboards), but most people seldom use it. Home row requires less wrist and finger contortion than the normal position of the Control key along the bottom row. I spend my time in Emacs, on the command line, and in Firefox with Emacs keybindings, so I give the control key a workout.

Caps lock be made into a control key on any system, but it is particularly easy in Ubuntu (it worked this way in 8.04 and 9.04, and maybe earlier, but I only got on the Ubuntu bandwagon last year, after 8.04 was released).

How to do it

System > Preferences > Keyboard opens the Keyboard Preferences dialog. Click the Layouts tab. Click Layout Options. Click the expansion arrow next to Ctrl key position. Select the radio button next to Make CapsLock and additional Ctrl. Close the dialog, and you should be good to go

Read Full Post »