Disclaimer: Codex help a bit with the troubleshooting of some of the config with Spacemacs. There's so much stuff. And also did a proof read and ChatGPT found the project to test and the steps and commands to do.
So this is just a little blog about my journey of switching to Emacs as a main tool. I don't know how many posts there are going to be, or if they'll all have a narrative structure that holds together, but that's OK.
Why the hell Emacs?!
I guess I should explain the rationale behind my choice a bit. During university, I was a bit dissatisfied with VSCode and the general alternatives. VSCode was slow/heavy, and I hated how many pop-ups there were when you started it. It also lacked the possibility to run two VSCode instances of the same folder. You have to have a floating window of the file you want to check at the same time.
But I digress. I was also looking for ways to avoid depending on something Microsoft produces, because it's not always a guarantee of future-proofness, let's say. They don't have a reputation for abandoning their projects like Google or Netflix (mostly regarding their shows), but I didn't want to depend on a big company maintaining the software. And I was increasingly more knowledgeable about the different tools in the open source ecosystem for editors. It seemed to me that Vim, or one of its variants, would be an interesting place to start.
I mean, whenever I needed to edit a file through an SSH connection, that's what I used. I thought that if I could become a power user of Vim, then the value of learning the tool would compound, both for programming and for system administration.
Then I started looking on YouTube for tutorials about what was available and what people recommended. And I found this video: Evil Mode: Or, How I Learned to Stop Worrying and Love Emacs, and then I was hooked. In that video, he shows all the big features and some impressive details that are there. Essentially, Emacs' Evil mode allows you to put Emacs in a Vim-like mode. So you emulate, or should I say configure, a keybinding mode for Vim in your Emacs. There's not a whole lot of reason to go with Vim when you can have Vim and a lot more in Emacs.
In Emacs, you have all your package management, you configure your Emacs with Emacs Lisp, you can use it for email, IRC, organization (with org-mode), and you can remote onto a machine and edit files from your Emacs on a remote server. You can have multiple windows in the same editor, as if they were workspaces in i3/sway, and the list goes on and on and on.
There are drawbacks though. There are so many things to learn that it's pretty daunting. Like, I've learned Rust/Nix/Linux, and Emacs is definitely the most complex piece of software I've used. Then there's also the fact that it's software that started in the late 1970s, so it's not the most efficient software and doesn't benefit from all the newer techniques or technologies. I think Emacs is not fully optimized for multithreading, which means that sometimes the interface is not as snappy as it could be.
But except for those two downsides, let's say, it's pretty good. I know some people say that "Emacs is the best operating system that lacks a simple text editor." But I saw someone online suggesting that you can spawn an Emacs server daemon specifically for the terminal version of Emacs. So when you want to edit a file quickly, it's easy to just start up Emacs in evil-mode and start editing as if you were in Vim.
Anyway, all that being said, I started trying to learn Emacs, and it was HARD. At first, you're faced with vanilla Emacs, which uses Emacs keybindings, so getting to the point of having a configuration that's useful is, let's say, not the easiest. But then I checked and there are bundled Emacs versions where they have a preconfigured setup for you to use, and I settled on Spacemacs. I like it because it already has a lot of the packages that you need and also uses a simpler (at least to me) keybinding scheme. It's centered around the SPC key and also tries to use mnemonic keybindings, so for Magit (git client for Emacs), the keybinding is "g", as in Git. For Dired, which is the file browser, it's "d", and so on.
So it makes the learning curve a bit less difficult. But it was very much when I started having access to LLMs that I was able to ask questions, because there's not necessarily a lot of documentation out there to help you. Maybe I didn't look for it enough, but I wasn't too successful. And I'm relatively shy when it comes to asking questions online. So having access to a tool like that greatly helped. Also, sometimes it's not obvious what state you're in or what is displayed on your screen. To give an example, I'm editing this blog post in Spacemacs and I want to commit and push some changes to this file. I would pull out Magit with SPC g s for Magit status (something like git status), and then you're in Magit major mode. To stage whatever files you have modifications in, you navigate to them with the arrows and press "s" for staging. It makes sense when you know, but when it's just assumed, it's pretty frustrating to find what the hell you need to press to do your action. A quick tip for those reading this: you can do C-h m (C is for Ctrl, and when there's a -, it means they are pressed at the same time) to bring up the kind of man page for the major mode. And then simply do "/" to start grepping through whatever you need. So yeah, it's that kind of suffering, but in my mind, it's an investment. If Emacs is still ahead of most editors at the moment and continues to evolve, it can be an editor for most of the rest of your life. From Wikipedia, GNU Emacs has been around since the 1980s, so it's roughly a 40-year-old software project. And I doubt it'll be dethroned anytime soon.
So enough rambling, let's get into what I did to make it work with the different languages. I'm not gonna go into a full-blown Ludo's Spacemacs setup, because it'll be a bit too long. But I'll just show what needs to be done to be able to use Spacemacs for the different languages. Maybe there's going to be a part two talking about the rest.
Emacs journey for coding
I started with Spacemacs to make it easier for me, like I said, and also had a lot of help from Codex because I don't really know Emacs Lisp just yet. Basically, I want to share my journey of switching to Spacemacs and becoming somewhat useful in it.
And I'm working with ChatGPT to work through the exercise of being able to use Spacemacs. Essentially, I want to be able to use it for work.
C/C++
I also want to be as autonomous as possible, because I'm getting quite tired of VSCode and the Microsoft shenanigans. And I work primarily in C/C++.
-
You need to manually configure and compile the project files
-
In this case it was
-
libgpiod
meson setup buildninja -C buildln -sfthecompile_commands.jsonto the root of the project- That's it
-
-
- You need to
ln -sfthe build'scompile_commands.jsononto the root of the project - Then, when you open a file, it asks to import the folder, file, or ignore it
I had an issue where I was specifying the C/C++ compiler but that was causing issues. So removing them worked afterwards.
I've tried a couple of other projects, and most of them didn't complain after configuring the compile_commands.json. I was also able to use SPC c to do fast compilation without depending on doing it by hand in the vterm window.
And also, you can simply configure a .clangd file, which then points to where you want clangd to read the compile_commands.json.
Python
So interestingly enough, Python seems pretty good as long as you have the LSP server running for Python. I was able to get auto-completion with company but I didn't have a keybind to invoke it. So I added a C-SPC to invoke it whenever.
And I also wanted to test a project with both C++ and Python and see how it behaves. I think I need to have the venv set up, and then Spacemacs reads it and understands it.
Rust
As for Rust, like always, there are no issues at all. I played with ripgrep and didn't have any issues.
Bash
For Bash, it was a bit weird, and I kind of gave up since it's not like I do a lot of Bash programming. It's often just a simple script. So I thought it was fine if I was able to see the syntax, and that's about it.
Devcontainer/Remote edit
To access a devcontainer, you have to use the devcontainer.el package and then use TRAMP to remote onto it. It's very handy, because you can simply run M-x devcontainer-up and then M-x devcontainer-tramp-dired, which drops you into a dired buffer of the devcontainer workspace. And you can even do SPC ' and it opens a popup shell directly into the devcontainer. It's crazy. This probably has better integration with devcontainers than VSCode. But I had a little bit of confusion trying to stop the devcontainer. It's not too bad though. Worst case, I'll do it manually in a shell.
And then I tried to do remote editing and somehow made Spacemacs crash… Anyway, it's working OK. I tried to remote into my laptop and start editing. What's nice is that nothing in your setup really changes, and it's essentially just sharing the filesystem through SSH, I believe. It's nice, but a bit laggy. Maybe it's because I'm on WiFi? And sadly, sometimes that locks up Spacemacs and then it's just dead :/. But it's definitely more made for when you know what file you want to edit on the remote machine. It's not really made to replace a shell or to navigate with dired.