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:
- Bookmarks > Manage Profiles
- expand Keyboard Profiles
- 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:
https://gist.github.com/1023272
Activate via:
(require ‘pbcopy)
(turn-on-pbcopy)
Tip: http://iterm2.com
Thanks for the tip. I upgraded from iTerm to iTerm2 today. Off the bat, I don’t see much difference. The preferences look a lot more intuitive, but iTerm2 seems to be obeying the preferences I had already established with iTerm, so I didn’t need to customize it at all.
Not sure if there’s some functionality in xclip.el that I’m missing, but I’m able to access the clipboard from terminal Emacs with the following elisp:
;;—————————————————————–
;; Mac Specific Configuration
;;—————————————————————–
;; Copy and Paste
(defun copy-from-osx ()
(shell-command-to-string “pbpaste”))
(defun paste-to-osx (text &optional push)
(let ((process-connection-type nil))
(let ((proc (start-process “pbcopy” “*Messages*” “pbcopy”)))
(process-send-string proc text)
(process-send-eof proc))))
;; Override defaults to use the mac copy and paste
(setq interprogram-cut-function ‘paste-to-osx)
(setq interprogram-paste-function ‘copy-from-osx)
I just keep this in a file entitled darwin.el and load it conditionally from my init.el with:
;; System-specific configuration
;; Loads system-type config; e.g. “darwin.el” on Mac
(let ((system-type-config (concat emacs-dir (symbol-name system-type) “.el”)))
(if (file-exists-p system-type-config)
(load system-type-config)))