crazyjoker96 · 2022-09-05 00:44
I found always frustrating that m emacs is not able to find the struct or function that I define in another file because my emacs configuration (from today's doom emacs configuration) is too basic to make me productive with emacs.
There are some suggestions on how I can make a good configuration of my emacs for a pure C project?
Ambitious-One-5860 · 2022-09-05 04:51
[Tree Sitter](https://github.com/emacs-tree-sitter/elisp-tree-sitter) and [lsp-mode](https://emacs-lsp.github.io/lsp-mode/tutorials/CPP-guide/) might be of help. Looks like both take a bit of work to get going. I have personally not used them, so try out which suits you and let us know how it went.
Soupeeee · 2022-09-05 08:08
lsp-mode is the way to go. Assuming you are on Linux, it's really easy to install and get working. You do need to configure your build system to create a `compile-commands.json` file an place it in your project's root directory for projects that have more than one file. I've also had better luck using `clang` as the compiler and `clangd` as the language server instead of gcc for whatever reason.
Here's how to install it:
1. Install `clangd` and related LLVM tools
2. Install and configure lsp-mode. Here's the config I have using `use-package`:
​
(use-package lsp-mode
:commands lsp
:ensure t
:config (setq lsp-prefer-flymake nil)
:hook ((c-mode c++-mode rust-mode objc-mode) . (lambda () (lsp))))
3. Install \`company-mode\` and turn it on to get a more IDE-like auto completion:
(use-package company
:config
(setq company-minimum-prefix-length 1)
(setq company-idle-delay 0.1)
(setq company-backends '(company-elisp
company-cmake
company-capf
company-files
(company-dabbrev-code company-gtags company-etags company-keywords)
company-oddmuse
company-dabbrev))
:ensure t)
When you open a C file, you should get asked some questions about how to find the project configuration. After that, everything should just work.
crazyjoker96 · 2022-09-05 08:55
Thanks! I will try this later :)
redguardtoo · 2022-09-05 12:46
`counsel-etags` for code navigation `company-ctags` for code completion
Both requires command line tool ctags (universal-ctags is recommended).
crazyjoker96 · 2022-09-05 13:12
do you have any tips to configure ctags?
redguardtoo · 2022-09-05 13:48
I don't have any special setup for universal-ctags which already supports C and many other languages out of box.
crazyjoker96 · 2022-09-05 22:11
works like a charm!
Ok-Analysis-7820 · 2022-09-05 23:21
If you're on doom, go to the init ~/.doom.d/init and find the programming language you want to set up, c or whatever. Add a parenthesis at the beginning and add lsp after the c (remove the ; ) so (c +lsp) whatever. If you push K and look at the flags you can see what might be needed
crazyjoker96 · 2022-09-06 12:46
Mh no for autosuggestion I need the addition before!