Emacs support for Racket programming

Say I was going to try Racket with Emacs.

There are quite a few options in the Racket Guide: 24.2 Emacs

I'd appreciate it if you could tell me what you use and why it suits you?

(I'm drafting a PR to update that page )

racket-mode is fire and all the kudos to @greghendershott for creating it. Combine that with paredit-mode and I have a smooth, fluid editing environment that lets me move fast through coding, easily check docs, evaluate (sub)expressions, and everything else I need to do.

3 Likes

I never realised you could combine them!

1 Like

Yup! paredit is a minor mode, meaning it layers on top of the buffer's major mode (e.g. racket-mode, fundamental-mode, text-mode, etc)

2 Likes

How do you manage conflicts? What if you have two minor modes that do the same thing or have competing keybindings?

There is no DrRacket for Android so I am using Emacs with racket-mode and paredit-mode on my tablet. I am running both Emacs and Racket in the Termux app, which is a Linux command line environment with a pretty good package manager. I also use Emacs on the desktop but still use DrRacket some of the time as well.

2 Likes

I have been using Racket Mode with Paredit for a couple years now. It works very smoothly and I have never had any conflicts.

@spdegabrielle I suppose that if you have two minor modes doing similar things (e.g. Paredit and Smartparens) you may get weird behavior. If your problem is only in the keybindings though, they are pretty easy to redefine, but YMMV.

3 Likes

I am using https://www.spacemacs.org/ this is basically like a linux distribution but for emacs.
Just like arch is pretty cool, but can be a PITA to install and manjaro allows you to use an arch like system but makes it easier to use.

The same applies to spacemacs you can use emacs without having to configure packages and keyboard shortcuts so that everything fits neatly together, instead spacemacs has something called "layers" and you can pick and choose from the pre-configured layers (like "auto-completion", "git", "version-control", "neotree", "org", "racket", "sql", "helm", etc.) or even create a new layer (if you want to add things that aren't pre-configured) to have emacs mostly pre-configured.
You can choose between emacs or vim style keyboard keys. Via space you open a menu of most of the special functions you may need, that menu tries to use mnemonic grouping of functionality so after a while you don't think about the keys anymore.

Overall I like it a lot, because before I spent too much time on configuring my emacs in custom adhoc ways, now I can just use an emacs that was configured better than I would have had time to do it. Of course a hardcore emacs user might have a highly specialized personal configuration, but I think if you don't want to do everything yourself as an emacs beginner, spacemacs is really good for that. I just added a few of my favorite keybinds and for the rest I use default spacemacs with a bunch of layers.

It comes with lots of features searching, multi-line editing, different kinds of navigation, perspectives, projects, etc.. I don't use that many features because I mostly write racket, but I have used other things in the past, its git support (magit) is really great.

I think one thing about spacemacs that is a bit of a downside is that the master version moves quite slow, most people seem to be using the development version instead.

1 Like

Does SpaceEmacs work with Racket Mode, Geiser, Quack, Paredit and the other major and minor modes in the racket guide?

racket

I am using spacemacs with Racket Mode (layer "racket"), its editing support seems to rely on smartparens (an alternative to paredit) it has preconfigured keys for copying, slurping s-expressions etc. (this allows editing based on text or based on expressions "non-strict")
It also has optional support for a strict mode that forces you to keep parentheses balanced.

https://practical.li/spacemacs/alternative-tooling/paredit.html:

Smartparens is the actively maintained alternative to paredit and is applicable to all languages, not just lisp based languages.

scheme

There is also a scheme layer that uses geiser. (Haven't used it yet)

Currently support is available for the following scheme implementations:
chez, chibi, chicken, gambit, gauche, guile, kawa, mit and racket.

(quoted from in editor documentation of the layer (develop version))

Note that combined usage of racket-mode and geiser has not been tested.

(But it doesn't really make sense to use both at the same time, you would pick one and disable the other, for example based on the file you are currently in (may already happen via autoload for certain file types e.g. rkt -> racket-mode))

quack

Quack doesn't have a pre-configured layer and isn't used by the scheme or racket layers, but you could add it to your personal/manual list of packages and start it, or even create a layer for it.
Another approach might be to add it as a custom feature to the racket layer, but personally I don't have a lot experience with custom layers and integrating different emacs packages.

But if somebody has successfully integrated racket mode and quack that could be a useful fork of the racket layer. That said, to me quack looks like it may be a bit dated and no longer maintained implementation, for mostly older scheme style racket code (MzScheme) and personally I only use modern racket, so racket-mode is all I need.

improvements

Although adding syntax highlighting for scribble to the racket layer via scribble mode might be a good idea/improvement.
If there are multiple people who want to use the racket or scheme layer and notice certain features that they miss from those, we could try to come up with a list of improvements and how those could be added. Personally I haven't found things that I miss, but that might be due to my relatively limited use of advanced features and maybe there are things that I just don't know that would be cool, but racket mode already has a lot, e.g. support for pictures in its racket repl.

In general everything you can do with emacs should also be possible to do with spacemacs, because it is just a way to use and configure emacs.

3 Likes

Thanks for the initiative @spdegabrielle , as always!

I use (and I'm the author of) Symex. It's a structural editing DSL that has a modal (Vim/Evil) user interface. It is a minor mode and can be used (must be used) together with language specific major modes like Racket Mode (for Racket).

There is an animated guide that shows what Symex does.

2 Likes

@countvajhula can you use Symex at the same time as racket-xp-mode?

@simonls am I right in assuming it is only a little configuration to use Symex minor mode with the Racket Layer in Spacemacs?

@spdegabrielle Yes, symex interoperates fully with everything provided by Racket Mode, including racket-xp-mode.
Re: spacemacs, I am not a spacemacs user myself but I know that some Symex users are, so I don't anticipate problems with integration. From my limited knowledge of Spacemacs, I think symex config would go in the user-config file (@simonls please correct me if I'm wrong).

1 Like

An interesting thing to do is M-x describe-mode in some buffer. It is quite a long description, starting with a section like this:

Enabled minor modes: Async-Bytecomp-Package Auto-Composition
Auto-Compression Auto-Encryption Blink-Cursor Column-Number
Delete-Selection Diff-Auto-Refine Display-Time Electric-Indent Engine
File-Name-Shadow Flx-Ido Font-Lock Global-Font-Lock Global-Git-Commit
Global-Magit-File Global-Paren-Face Hs Ido-Everywhere Ido-Ubiquitous
Ido-Vertical Line-Number Magit-Auto-Revert Mouse-Wheel Override-Global
Paredit Paren-Face Projectile Racket-Xp Shell-Dirtrack Tooltip
Transient-Mark Which-Key

Quite a few minor modes are enabled. Some are Emacs features/packages I've chosen to enable; someone else's list might be longer or shorter.

But it's also interesting that things like Blink-Cursor and Line-Number are minor modes! :smile:

Anyway, things usually coexist surprisingly well. Every mode also defines a keybinding map, which as @scolobb mentioned you can modify if you need or want to.

3 Likes

I think that's correct, although I haven't tested it.
I think symex looks interesting, but I am unsure about whether I would actually end up using it personally, currently It is not a priority for me to test it out, because I would have to adapt to it, to figure out whether it makes me more productive. It's a difficult to gauge tradeoff, considering I currently have something simple that works for me.

my view on keybinds

I tend to use keybindings that are less "strict" and "formal", mixed with a few relatively rare uses of copy / delete / slurp / barf some S-expression and mostly my own set of keybinds to quickly insert things which are annoying to type on some keyboard layouts.

I think currently I prefer mostly "mechanical" / non-context dependent keybinds, being used to those keybinds I can skip around in code quite quickly, without having to first visually parse what kind of structure I am currently in and also (mostly) independently of whether it is lisp or some other language. Also because the keybinds are simple, It doesn't require a lot of work to make those available in case I am in a context where it is difficult to bring my own editor.

I used to work in a context where I quite often had to ssh into some machine and do something on that machine, so I had a one-liner that would curl/wget my single file vim config from my dotfile repository into my home on that machine. I also bound that to a key combination in my terminal, so I only had to press a key-combination to install my vim config on a server. That config was the minimalized subset of my desktop config that used multiple plugins. Later I switched to emacs (with evil mode) and added some of the old keybinds.
That was a kind of hacky, but reliable way to be productive in an environment, where I couldn't really get a desktop development experience, maybe that has influenced me. Overall I think that is less of an issue with current tendencies to have things containerized etc..

For example I use keybinds to jump up 5 or 25 lines, I am still used to that from my vim days and haven't so far found something that is better (for me) than that, because I can use that to skip around in code without having to think about it, look for clues (like you have to with things like avy, which is cool but also seems a bit "gimicky" to me). I guess I would describe my style as having a controller/gamepad - like keyboard in your hand and letting the brain optimize the picking up clues from what you see and what sequence of taps to output through muscle memory.
I also have "," in insert mode rebound to open a custom transient state that makes the next key do something special, I use that for example to insert different pairs of brackets around the cursor, or whatever I find annoying to type (sometimes things are setup so that they are easier to type with an US keyboard layout which I don't use).

2 Likes

The gamepad analogy got your style across pretty well :slight_smile: Thanks for sharing your UX in such detail, it's always interesting to learn from these accounts. I actually didn't mean to suggest that you install Symex - only vet whether what I was saying about the user-config file was in general correct (which you did!).

@greghendershott true, the fact that blink-cursor and line-number are modes is very telling! Esp. as a window into Emacs for non-Emacs users.

3 Likes

I'm just using plain GNU EMACS with Geiser and Paredit runs plenty smooth and fine, I've not tried Racket-Mode yet, I checked out its website before and I think it could be better than Geiser for Racket, I did read somewhere before that Racket-Mode seems to work best with smartparens rather than Paredit, but I've yet to try as Geiser runs plenty good enough for me and I like that it can switch to support other Schemes, so I've not needed to try Racket-Mode yet.

1 Like