reddit / emacs

Arduino development on emacs

UltraBlack_ · 2022-03-12 15:10
Hey there, I'd like to program some stuff for my arduino via (doom) emacs, but there are a few things, that I need: 1. Syntax Highlighting 2. Auto completion 3. Support for Arduino __and__ Teensy ### What I have tried 1. https://github.com/arduino/arduino-language-server - It needs modification of lsp-mode though, as it doesn't support passing cli arguments ootb 2. https://github.com/motform/arduino-cli-mode and https://github.com/yuutayamada/company-arduino/ - Together they seem somewhat fine, but as soon as the project has a few .c/.cpp files the .ino triggered arduino-cli-mode poofs. ### What I want to avoid Installing an IDE, I want to stay with emacs as far as possible. I don't like chonky bloated IDEs ### Other options https://github.com/sudar/Arduino-Makefile - How with the above mentioned QOL though Note: I'm very unfamiliar with elisp, I can do very basic things via trial and error while copying other stuff from my config. Do you have any idea what could be done here? I have tried everything I could. Thanks!
Skami859 · 2022-03-12 15:18
I just manually run c++-mode in the .ino file. It might be sufficient for you.
D1ck3r · 2022-03-12 15:44
I used https://platformio.org with Clangd
UltraBlack_ · 2022-03-12 15:46
Arduino or rather Teensy seems to have some data types that are not to be found anywhere else, which makes this a sadly not really working solution for me - Unless you changed something that I am forgetting right now
UltraBlack_ · 2022-03-12 15:47
Sadly, to this applies the same, as to the Platformio + Clangd comment :/
gdanov · 2022-03-12 16:41
You need to find the headers and include them. Also, by default cllangd will signal some false problems. You have to be using xtensa's clone of clang in their llvm port.
UltraBlack_ · 2022-03-12 16:47
I did try that, but then it somehow failed to find a library - “Fatal Error: avr/pgmspace.h no such file or directory” That doesn't work with teensy anyways I think
gdanov · 2022-03-12 16:56
This header must exist somewhere. Find it and include it. Arduino / platformio / esp-idf + emacs works great but you must learn how to configure emacs and lsp-mode, then master the respective C build system or you'll be relying on reddit for every basic problem and you'll have many of these.
Skami859 · 2022-03-12 17:07
I personally don’t have any problem with this when targeting the teensy. Hopefully you can find what the issue is.
UltraBlack_ · 2022-03-12 18:08
Well how did you get it to work? Install arduino and/or teensyduino and start programming?
UltraBlack_ · 2022-03-12 18:09
The issue was that Arduino.h wasn't able to find pgmspace.h, not my code - I installed the arduino-avr-core so iirc it was there and should have worked ootb, but it included "avr/pgmspace.h", but that folder was in the parent one and didn't even have the header
gdanov · 2022-03-12 18:16
the Arduino Language Server seems to be your best bet. Get your project running in the Arduino IDE, then switch to emacs + the ALS. If you want to use emacs, you have to learn elisp and some basic internals. There's no way around this.
phil_g · 2022-03-12 23:56
I use Emacs and PlatformIO, but I haven't gotten into stuff like clangd yet. Do you have a pointer on a good reference for getting clangd to work with PlatformIO projects? (Also, what do you use to connect clangd and Emacs? A quick search turned up LSP and eglot. Are there others? Do you have a preference?)
D1ck3r · 2022-03-14 20:20
I added those flags: (setq lsp-clients-clangd-args \`("-j=2" "--background-index" "--clang-tidy" "--completion-style=detailed" "--query-driver=/home/dicker/.platformio/packages/toolchain-atmelavr/bin/avr-g++" "--compile-commands-dir=.")) ​ Add I'm not sure what setup the compile\_commands.json (probably when you set it up) The file should be at: ./.pio/build/micro/compile\_commands.json Hope that is helpful.
D1ck3r · 2022-03-14 20:22
I used lsp-mode, but if you can setup the compile\_commands.json and add the flags I mentioned above, I think it will work on eglot too.
phil_g · 2022-03-14 20:35
Thanks! It looks like you can run `pio run -t compiledb` to generate `.pio/build/<environment>/compile_commands.json`. I just symlinked the latter into the project root. I'll experiment with the flags you mentioned. I'm using lsp-mode for now (and it seems pretty nice). I'm getting a lot of spurious errors about standard functions and objects (like `millis()` or `Serial`) not being defined. It seems like clangd isn't getting the stuff from Arduino.h for my board yet.
UltraBlack_ · 2022-03-14 21:27
Just what I needed, thanks!