Skip to content

Instantly share code, notes, and snippets.

@333fred
Last active March 7, 2022 18:55
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 333fred/9c88c4bc04ecb51fda08 to your computer and use it in GitHub Desktop.
Save 333fred/9c88c4bc04ecb51fda08 to your computer and use it in GitHub Desktop.
Basic Racket Emacs Setup

On Ubuntu, install the racket package with:

sudo apt-get install racket

On Arch Linux, install racket with:

sudo pacman -S racket

On Windows, install Racket from racket-lang.org. Put Racket.exe and Raco.exe on your path.

Once Racket is installed, you need to install the plai-typed language. To do this, run: raco pkg install plai-typed in the console.

Make a folder .emacs.d in your home folder. Create a file init.el there and copy the contents of the file below in. This config provides the following packages:

  • ido - Ido mode provides an interative file find interface.
  • smex - Smart MEta-X provides an ido-like interface to M-X.
  • racket-mode - Provides racket syntax highlighting, REPL, and autocompletion backend.
  • flycheck - Provides on-the-fly syntax checking and error highlighting.
  • company - Provides popups for completions. Complete with tab or enter, switch between with up/down.
  • paredit - Autoinserts closing parens, adds a lot of features for editing racket-style code. For a tutorial, the nice gif-filled guide here.
  • rainbow-delimiters - Colorizes parenthesis, brackets, and other delimiters to make it easier to tell what matches with what.
  • uniquify - Helps make buffer names unique. If you open two files with the same name, it can be hard to tell the difference. This fixes that.

To get completions with specific things from your code, you need to run the file through the REPL first. To do this, either click Racket->Run->In REPL, or press CTRL+C, CTRL+K. Completions can take a second or two to pop up after you start typing.

;; -*- lexical-binding: t -*-
;; Add the melpa emacs repo, where most packages are
(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(package-initialize)
;; Ensure package-list has been fetched
(when (not package-archive-contents)
(package-refresh-contents))
;; We want to use use-package, not the default emacs behavior
(setq package-enable-at-startup nil)
;; Install use-package if it hasn't been installed
(when (not (package-installed-p 'use-package)) (package-install 'use-package))
(require 'use-package)
;; ido-mode provides a better file/buffer-selection interface
(use-package ido
:ensure t
:config (ido-mode t))
;; ido for M-x
(use-package smex
:ensure t
:config
(progn
(smex-initialize)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)
;; This is your old M-x.
(global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)))
;; Provides all the racket support
(use-package racket-mode
:ensure t)
;; Syntax checking
(use-package flycheck
:ensure t
:config
(global-flycheck-mode))
;; Autocomplete popups
(use-package company
:ensure t
:config
(progn
(setq company-idle-delay 0.2
;; min prefix of 2 chars
company-minimum-prefix-length 2
company-selection-wrap-around t
company-show-numbers t
company-dabbrev-downcase nil
company-echo-delay 0
company-tooltip-limit 20
company-transformers '(company-sort-by-occurrence)
company-begin-commands '(self-insert-command)
)
(global-company-mode))
)
;; Lots of parenthesis and other delimiter niceties
(use-package paredit
:ensure t
:config
(add-hook 'racket-mode-hook #'enable-paredit-mode))
;; Colorizes delimiters so they can be told apart
(use-package rainbow-delimiters
:ensure t
:config (add-hook 'prog-mode-hook 'rainbow-delimiters-mode))
;; Make buffer names unique
;; buffernames that are foo<1>, foo<2> are hard to read. This makes them foo|dir foo|otherdir
(use-package uniquify
:config (setq uniquify-buffer-name-style 'post-forward))
;; Highlight matching parenthesis
(show-paren-mode 1)
(setq show-paren-delay 0)
;; Allows moving through wrapped lines as they appear
(setq line-move-visual t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment