This document will serve as an (opinionated) guide for setting up Racket and Emacs on a Mac OS X. If you are on a Windows machine, @jasonhemann's note should help.
- Download the latest version of Racket from http://download.racket-lang.org/. Make sure you choose "Racket" as the distribution; the platform should probably just be "Mac OS X (Intel 64-bit)".
- Open the downloaded
racket-blabla.dmg. Drag the entireRacket v6.x.xfolder toApplicationsas instructed. - Add
racketandracoto your$PATHso that they can be easily found.- Edit your
~/.bash_profile(or~/.zshrcif you use zsh). Run the following line in your terminal: echo 'export PATH="/Applications/Racket v6.4/bin":$PATH' >> ~/.bash_profile- As of February 2016, the latest version of Racket is v6.4; if you download a newer version of Racket, make sure you to edit the version above.
- Edit your
- Activate these changes. Open a terminal window — Mac comes with
Terminal.appby default; it's not bad but iTerm2 is a better and free alternative.- Run the following commands in your terminal:
source ~/.bash_profileecho "(require xrepl)" > ~/.racketrc(Optional, but recommended. This will enable Racket's XREPL in the command line)
- Try running
racketin your terminal. You should be able to see a working REPL.
There are quite a few Emacs versions for Mac. However, the most handy one I've found is Yamamoto Mitsuharu's port: a GitHub mirror of it can be found here. The following part will be a walk-through of installing it via brew (a package manager for Mac that just works™). You may also grab the pre-built binary files from https://github.com/railwaycat/mirror-emacs-mac/releases, but updating it won't be as convenient as using brew.
- Get brew.
- Go to http://brew.sh/
- Follow the instruction (paste the one-liner at a terminal prompt).
- Update brew.
brew update
- Install Emacs via brew.
brew tap railwaycat/emacsmacportbrew install emacs-mac(orbrew install emacs-mac --with-modern-iconif you don't like the default icon)brew linkapps emacs-mac
- You should be able to find
Emacs.appin yourApplicationsfolder. - If you want to be able to launch GUI Emacs via the terminal, add
alias e='open -a /Applications/Emacs.app'to your.bash_profile. - In the future, to upgrade your Emacs, run
brew update && brew upgrade emacs-mac.
Configuring Emacs from scratch could take you a loooong time. For your convenience, we've uploaded a minimal init.el file that provides some basic functionalities (for racket-mode) and fixes.
- Grab the file
init.elfrom this repo - Put it in the
~/.emacs.d/folder - Restart your Emacs.app and wait for it to install packages (warnings are normal).
- Automatic package installation, including:
racket-modefor all the greatness.- We rebind the
racket-runcommand tometa-enter(option-enter). This is basically equivalent with DrRacket'sRunbutton. If you don't like the keybinding, just modify it ininit.el.
- We rebind the
helmcuz nobody can memorize all the emacs functions.companyfor auto completion.rainbow-delimitersso we won't need to get LASIK.pareditis included but disabled by default.- We highly recommend activating paredit for Scheme/Racket/Lisp modes, but we understand that it could take a while to get used to it.
- Please read http://danmidwood.com/content/2014/11/21/animated-paredit.html first; when you are ready, change the line
(setq paredit-enabled nil)to(setq paredit-enabled t)ininit.elto activate paredit.
- Fixes
- All the temporary files will be placed under
~/.emacs.d/bkupso you won't see annoyingbla~files in your working folder again. - The Mac
optionkey becomesmeta. - Perserve some OS X default system shortcuts in Emacs. To name a few:
Command-a= "Select All"Command-x= "Cut",Command-c= "Copy", andCommand-v= "Paste"Command-s= "Save"Command-z= "Undo"
recentf-mode: useC-x C-rto access a list of recently edited files.- Emacs grabs the
$PATHvariable from your shell.
- All the temporary files will be placed under
That's it! Now you when you open a .rkt file, racket-mode will start working. The shortcut option-enter acts like DrRacket's Run button — make some changes, press option-enter, and you'll see some new stuff in the REPL.
Customizing Emacs is beyond the scope of this guide. You'll find tons of information on http://emacswiki.org/ and stackoverflow. http://emacsrocks.com/ also has some good staff to watch.
Feel free to modify the init.el file (it's fun!). For more questions, please open a GitHub issue here: https://github.com/keyanzhang/c311-get-started/issues. If you find a better way to do things, pull requests are more than welcome!
MIT