reddit / emacs

A clear path to setting up emacs as an IDE

wiyomay249 · 2022-02-20 19:29
I am really sorry to ask this question, as there are already a lot of answers given, but I feel that none of them are definite and give the whole answer (in a clear and easy to follow way) I am looking for setting up auto-complete capabilities and code checking in emacs. I mostly want this for Python and C++, although having the capability to easily add other languages in the future would be much appreciated. What packages do you recommend for setting up emacs as an ide?
Horrih · 2022-02-20 19:58
Basically you need a few - a completion front end : company for example - a syntax error front end : flycheck or the built on flymake - a back end : lsp or eglot - a language specific language server : clangd or ccls for c++, python-language-server for python for example. All the language servers used by vs code should work here as well For c++, indications on includes / defines are done through a compile_commands.json file See more info here, i followed this guide myself a few months ago for c++ https://emacs-lsp.github.io/lsp-mode/tutorials/CPP-guide/
konrad1977 · 2022-02-20 19:58
https://emacs-lsp.github.io/lsp-mode/tutorials/CPP-guide/ looks like a solid start.
podtatranec · 2022-02-20 20:00
For someone starting out - I think easiest might be spacemacs or doom emacs. If you want to "roll your own" then you'll probably want to look into using LSP (I've been using lsp with pyright for python and clang backend for some light C coding I did a while ago). But for someone new to Emacs who wants to get started quickly a ready-made "emacs distribution" might be an easier way to get your feet wet...
R3D3-1 · 2022-02-20 21:49
Personally, I've given up for Python and have started experimenting with PyCharm and VSCode. I've never been able to get something like "type `linspace` and have `from numpy import linspace` added automatically" to work. So I am now testing, if other editors do a better job of the "intellisense" stuff. Never tried preconfigured ones like Doom Emacs though.
by_wicker · 2022-02-21 00:20
I get that sort of automatic import with just `lsp-pyright`. Sadly it often doesn't get the import sorting right so I have to run isort, but otherwise it works very well. Unless you're talking about a numpy-specific problem? Edit: your example didn't work for me before I had numpy imported in my project, but once it had been imported once, in a new file it added `from numpy.core.function_base import linspace`. So in this case it may not be exactly right(?) - in general I find it very usable.
glrsn · 2022-02-21 00:40
I second Horrih's reference to emacs-lsp/lsp-mode. I also found emacs-lsp/lsp-ui helpful. Have a look at alphapapa/with-emacs.sh, it helps one tinker with configurations without affecting your current configuration. I find tinkering a good way to figure out what one doesn't know they don't know.
KDallas_Multipass · 2022-02-21 01:33
The most foolproof setup I've found (and I've tried them all) is to use eglot, clangd, and a build system that produces compile_commands.json. If you're using plain make, the bear utility can be used as a wrapper around make calls to create this. issue bear make instead of make. In cmake, pass the parameter -DCMAKE_EXPORT_COMPILE_COMMANDS=ON. The only gotcha is the placement of the json file. In eglot, when you open a source file, eglot will search for the json file in the current directory and start searching up. with a cmake build, the file ends up in the build folder, so you have to move it where eglot will find it. Even worse, with different kinds of cmake builds, multiple json files will be created, which you'll have to combine and put in the right place. There's a command line jq oneliner to combine them, once you get the process down its not too bad. You will have to play this game no matter what LSP backend you choose due to the nature of c++. Clangd (the LSP server) and eglot are just dead simple to install. eglot and clangd make for the best editing experience, and the small amount of pain figuring out what to do with the json file pays dividends Edit: It's python I can't figure out. How to open a session in a virtualenv, etc. Just can't seem to hack it
yep808 · 2022-02-21 07:51
[https://emacs-lsp.github.io/lsp-mode/tutorials/CPP-guide/](https://emacs-lsp.github.io/lsp-mode/tutorials/CPP-guide/) [https://emacs-lsp.github.io/lsp-mode/tutorials/how-to-turn-off/](https://emacs-lsp.github.io/lsp-mode/tutorials/how-to-turn-off/)
Opening-Training-972 · 2022-02-21 09:08
I will recommand [eglot](https://github.com/joaotavora/eglot) \+ [clangd](https://clangd.llvm.org/installation) for C/C++, and eglot + pyright,because it's out of box, you don't need more setting. for completion , there are another option: [corfu](https://github.com/minad/corfu)
R3D3-1 · 2022-02-21 09:22
Thanks for the suggestion, will give it a try. My workflows are very Emacs-centric, and I hate how difficult it is to execute arbitrary shell commands without using the mouse at some point in most other editors, so I'll be glad to get it working.
R3D3-1 · 2022-02-21 10:01
Tried, though at least out-of-the box it is only partly helpful. E.g. it does not suggest `greet(NAME)` from `lib.py` in the same directory. I guess I can get it to work going from there though if I find out the necessary configuration. Its not like running tests in VS code works as well as I had hoped...
Temporary_Market_316 · 2022-02-21 12:36
As usual, System Crafters got some useful videos on setting Emacs up as an IDE. And as everyone have written. Package eglot or lsp-mode is the way to go, as they use lsp (language server protocol). The eglot package are smaller and and lsp-mode take much more space. That will support refactoring variables etc. and stuff like that. Then you need to have the right lsp-server for the language, and there are lots of them, so you have to try them out. You should also look into project (or projectile) to manage files in your project. And of course magit (for git support). There are vc-mode which have support for many different version control system. But if you use git, magit is probably the way to go (or combine magit and vc-mode). That is probably what you should look into to begin setting up your coding environment. Don't forget to read the info pages for Emacs and for each package. The project and vc-mode is already in Emacs, the others you need to load from ELPA, which isn't hard.
[deleted] · 2022-02-21 14:08
[deleted]
by_wicker · 2022-02-21 16:09
I get local dir completions - didn't do anything AFAIK to make that work. But mypy/pyright doesn't seem happy unless the directory has an `__init__.py` (usually empty) - not sure if that might be relevant. > running tests I don't think I'm using much from `elpy` right any more, but I keep it around for the function `elpy-test`, bound to `C-c C-t` by default, fits my modest needs for python testing (runs test at point, or tests in file, or with a prefix, tests in project).
coolstuff39 · 2022-02-21 18:21
lsp-mode also works OOTB with no additional settings
R3D3-1 · 2022-02-21 20:07
Are you using anything that might be queried by `lsp-pyright` for detecting "project structure" information? By default, I would not be surprised if `lsp-pyright` ignores files in the local directory, since nothing defines what directory is the *root* directory. If I execute `python ./app.py` and there is a file `./lib.py`, then I can do `from lib import myfunction` in `app.py`, but only because I've implicitly given it the information to treat `.` as part of `sys.path`.
by_wicker · 2022-02-22 02:20
It asks the project root when entering a new project. AFAIK that's the only config in particular.
R3D3-1 · 2022-02-22 09:14
\*What\* asks the project root? How do you \*define\* a project? That's pretty much what I have no workflow for :)
by_wicker · 2022-02-22 14:06
lsp, when you open a file that isn't already part of a project. Edit: to be clear. I don't actively do anything, and I don't have significant config AFAIK. It automatically asks to establish the project root if it doesn't already know it. It appears to me that it stores some internal data about this in ~/.emacs.d/.lsp-sesssion-v1, but that is not intended for manual editing.
not-the-droid- · 2022-09-14 01:20
Did not work. Missing libraries: configure: error: The following required libraries were not found: libXpm libgif/libungif
not-the-droid- · 2022-09-14 01:23
Did not work configure: error: The following required libraries were not found: libXpm libgif/libungif
konrad1977 · 2022-09-15 04:59
Maybe they can be installed? I dont know which OS you're using so its hard to give any advice.
not-the-droid- · 2022-09-15 05:28
Linux mint, and apt can't find them.