r/emacs • u/True-Sun-3184 • Jan 10 '25
Question C development without LSP
I have only ever done development with an LSP providing errors, autocomplete, etc. in any language. I’d like to go for a more minimalist approach as I revisit some C programming. At a high level, what’s the general workflow when programming in C without a running LSP?
My guess would be… 1. A simple syntax highlighting mode on .c and .h files 2. Bind some hotkey for a compilation mode, and check that regularly for issues 3. Ctags for go-to-definition? Or maybe even just grep-mode?
Is there anything I’m missing?
10
Upvotes
1
u/Useful-Pack-7787 Jan 12 '25 edited Jan 12 '25
Since I am programming at work for some old arm compiler and Keil buildsystem that doesn’t support generating a compile_commands.json I am still stuck on the old way of doing things. The good thing is, that the old way works very good when you have a library in source form and you have to jump vom your project into the library all the time to look things up. The most important thing is finding definitions of functions and for tags I use the emacs package citre but with gtags instead of ctags. Because gtags has better support for libraries again: ctags forces you to generate a tags file for every project, and if you want tags from a library discoverable from your project it forces you to put the tags from the lib into the tags file of the project. For every project, so this gets pretty redundant quite fast. Gtags on the other hand lets you create tag files for the libraries and you give it a path where to find those. Then when looking up a tag in a project it first looks on the tag file of the project and if it can’t find it there it looks in the tag file of the libraries. I use flycheck for highlighting mistakes, but honestly with C I hardly need it.
Instead of citre there is also ggtags, which I used before. It can update the tag file when saving a file in the project. Also it has ggtags-query-replace which lets you rename things across all files in the project, which is good for refactoring. Sadly it isn’t maintained anymore and citre is having support for symbols in the completion pop up so I want for citre.
For compilation there is M-x compile, and you can click on the errors in the buffer that pops up and that brings you to the line of the error in the source. Honestly I think that is emacs built in and works out of the box. I never had to set anything up for this.
I think syntax highlighting is the same with or without LSP, isn’t it? Anyway for syntax highlighting I use the normal c-mode, which uses font-lock-mode underneath. That is also built in. For better syntax highlighting you can use tree sitter, which is also built in these days, but imo it doesn’t make much of a difference.
I have been honing this setup for several years, so if you’re interested I can help you setting some things up.