Using Emacs for the FIRST Robotics Competition
For a large portion of the Infinite Recharge build season, I’ve been attempting to entirely forgo usage of Visual Studio Code, which is WPILib’s official IDE. Not only have I had countless issues with it (specifically, Microsoft’s “IntelliSense”, which often acts less intelligent than the name implies), but the majority of my programming and digital life lives in Emacs. In particular, I use DOOM Emacs, which makes the majority of this configuration extremely easy to implement; however, all the advice in this post will apply to vanilla Emacs in a similar fashion.
Also, I use
evil-mode. Sue me.
These bits are essentials that you should probably already have if you’re writing any large projects in Emacs. All of these are bundled with DOOM.
frc-mode is basically just a Gradle wrapper that integrates with Projectile. I wrote it over the course of thirty minutes while not paying attention in E&M. In retrospect, I probably should have been paying attention.
Due to the advent of GradleRIO, this was really, really simple to do. It also
means all I have to do to deploy robot code is
C-x C-f d.
config.el (for vanilla,
(add-hook 'java-mode-hook (lambda () (frc-mode 1)))
Meghanada is pretty much obsoleted by LSP (as described later), but is still worth a mention for the fact that I have both enabled for some reason and because it does auto-formatting.
(setq meghanada-java-path "/home/hazel/wpilib/2020/jdk/bin/java") (add-hook 'java-mode-hook (lambda () (add-hook 'before-save-hook 'meghanada-code-beautify-before-save)))
LSP is pretty much the bread and butter of what makes Java development in Emacs not only bearable, but extremely enjoyable, aside from the fact that you’re still writing Java. LSP, and by extension lsp-java, uses Eclipse’s syntax checker and auto-corrector, which is miles ahead of IntelliSense (albeit I don’t believe it to be quite as good as IntelliJ IDEA’s syntax checker).
It was extremely easy to set up for DOOM (just uncomment
don’t have experience configuring vanilla Emacs with LSP, so I recommend looking
into their documentation. Once you have both LSP and
lsp-java installed, just
M-x lsp-install-server RET jdtls RET.
(add-hook 'java-mode-hook #'lsp)
The end result
Of course, you could just… (but actually don’t. not yet.)