reddit / emacs

N00b question: How can I use emacs as an IDE for non-Scheme related languages?

RepresentativePop · 2022-08-06 19:14
So I only started using emacs a few days ago, but after getting over hating it for the first day or two, I learned how to do basic things from memory, like install packages, open text files, and use custom themes. I'm a fan now. I'd like to set it up to do the sorts or things an IDE would do, but the way I'm doing it doesn't quite have the functionality I'm looking for. Currently what I'm doing is opening a buffer with a text file, saving it as "somefile.c" (because I mainly work in C), and using the C major mode by typing "M-x c-mode." That implements syntax highlighting, which is nice, but there's a few things it doesn't do that I'd like it to do: * debugging/error correction - At the moment, if I type something like # include <stdio.h it doesn't notice my dumb typo, and I'd prefer if it had some kind of feature to tell me what was wrong, rather than just getting a compilation error when I try to compile it. * real time terminal - Ideally, I'd like to open a window with a separate buffer containing a terminal emulator so that I can compile+execute the code within emacs. Also, if anyone has configured their emacs so that it can be used as an IDE and has found some features helpful, I'd be interested in hearing about them! (N.B. I also work in Haskell. I'm having similar issues with the Haskell mode that I'm having with the C mode)
Faerryn · 2022-08-06 20:27
For code intelligence (highlight errors, provide completions) in a `c` source file, you may want to try `eglot` together with `clangd`. `clangd` is an Language Server by the LLVM guys. It is a backend program that spits out a JSON message after analyzing source code. It is, by itself, unusable, as it is just the server. `eglot` is a Language Server Client by joaotavora. It is an EMACS package that interfaces with LSP servers such as `clangd`. It is part of ELPA, so you can install it with `M-x package-install eglot`. For a terminal, just run `M-x shell` (or `M-x term`, which keeps BASH keybindings, or whatever keybindings your shell has). Before that, you may want to split the EMACS window in two so you can have code on one side, by hitting `C-x 2`. Here are links to `eglot` and `clangd`. On Arch Linux, `clangd` is part of the `clang` package, and to run `eglot` on a file, just open the file in EMACS and run `M-x eglot`. [https://github.com/joaotavora/eglot](https://github.com/joaotavora/eglot) [https://clangd.llvm.org/](https://clangd.llvm.org/)
PhantomSeahorse · 2022-08-06 20:29
The standard practice is use `lsp-mode` plus a language server. Emacs can be very powerful if you install the required packages
magthe0 · 2022-08-06 21:08
If you haven't found it already I can recommend taking a look at https://www.youtube.com/c/SystemCrafters, in particular the [emacs from scratch](https://www.youtube.com/playlist?list=PLEoMzSkcN8oPH1au7H6B7bBJ4ZO7BXjSZ) videos.
xtifr · 2022-08-06 21:45
While Emacs certainly *can* run a shell in a buffer (as several other folks have mentioned), when you want to compile something, it's actually better to use the `M-x compile` command which, in turn, allows you to use the `next-error` function (bound to `C-x \`` or `M-g n` by default) to automatically jump to lines which triggered compiler errors.