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.x
folder toApplications
as instructed. - Add
racket
andraco
to your$PATH
so that they can be easily found.- Edit your
~/.bash_profile
(or~/.zshrc
if 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.app
by default; it's not bad but iTerm2 is a better and free alternative.- Run the following commands in your terminal:
source ~/.bash_profile
echo "(require xrepl)" > ~/.racketrc
(Optional, but recommended. This will enable Racket's XREPL in the command line)
- Try running
racket
in 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/emacsmacport
brew install emacs-mac
(orbrew install emacs-mac --with-modern-icon
if you don't like the default icon)brew linkapps emacs-mac
- You should be able to find
Emacs.app
in yourApplications
folder. - 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.el
from 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-mode
for all the greatness.- We rebind the
racket-run
command tometa-enter
(option-enter
). This is basically equivalent with DrRacket'sRun
button. If you don't like the keybinding, just modify it ininit.el
.
- We rebind the
helm
cuz nobody can memorize all the emacs functions.company
for auto completion.rainbow-delimiters
so we won't need to get LASIK.paredit
is 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.el
to activate paredit.
- Fixes
- All the temporary files will be placed under
~/.emacs.d/bkup
so you won't see annoyingbla~
files in your working folder again. - The Mac
option
key 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-r
to access a list of recently edited files.- Emacs grabs the
$PATH
variable 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