Racket: Using Emacs racket-mode

By Xah Lee. Date: . Last updated: .

You can use emacs to code Racket lisp. It works very well.

emacs racket mode 2015-10
Emacs racket-mode

Download

Download racket-mode from MELPA. [see Emacs: How to Install Packages Using ELPA, MELPA].

When opening a file ending in .rkt, racket-mode will be activated.

Here's most useful commands.

Run Racket REPL in Emacs

Ctrl+c Ctrl+z racket-repl
Switch to REPL. (start it if not started.)

Eval Code

Ctrl+c Ctrl+c racket-run
Eval buffer.
F5 racket-run-and-switch-to-repl
Run current buffer code, then switch to REPL.
Ctrl+x Ctrl+e racket-send-last-sexp
Send the sexp before cursor to REPL.
Ctrl+x Ctrl+r racket-send-region
Send the region to REPL.

Doc Lookup

Ctrl+c Ctrl+d racket-doc
Show doc in browser using local copy. (if cursor is on a function, show doc of that function without prompt.).
Ctrl+c Ctrl+. racket-describe
Show doc in emacs as plain text. First time may be slow.

Completion

Ctrl+Alt+i complete-symbol

To make the Tab key do completion, put the following in your emacs init then restart emacs. (yes, need to restart emacs, not just eval.)

;; make the tab key do indent AND completion
(set-default 'tab-always-indent 'complete)
[see Emacs: Tabs, Space, Indentation Setup]

Editing

Emacs has lots builtin features to edit lisp code, any lisp. See: How to Edit Lisp Code with Emacs .

Misc

Ctrl+c Ctrl+p racket-cycle-paren-shapes
Change the current surrounding brackets. (racket allows any of ()[]{})

When in racket-mode, call describe-mode to see a list of complete command and keys.