reddit / emacs

buffer-env: A package to handle virtualenvs and the like

astoff1 · 2022-03-02 20:23
Since questions of the type “Emacs can't find my language server” are quite frequent here, I would like to announce a package that helps with that. [https://github.com/astoff/buffer-env](https://github.com/astoff/buffer-env) The package works in a manner similar to the direnv program (and is mostly compatible with it). Moreover, it sets the environment variables buffer-locally, so once things are configured everything runs on autopilot and you don't need to manually switch between different projects.
lastnamebird · 2022-03-02 21:37
I’ve had success using this. Had you seen it beforehand? https://github.com/purcell/envrc
astoff1 · 2022-03-02 21:53
They are very similar. The main difference is that buffer-env does not depend on direnv.
lightshadow1984 · 2022-03-03 01:23
Ok now I need to try this. Thank you for the package.
DrReadIt · 2022-03-03 03:42
direnv, you're welcome.
simbledress · 2022-03-05 09:34
I notice that the README refers to a `buffer-env-file` but the variable in the actual program is `buffer-env-script-name`. Btw thanks for this, I can see this being useful for `guix shell`.
astoff1 · 2022-03-05 09:54
Thanks, fixed.
astoff1 · 2022-03-05 09:59
Out of curiosity, does Guix offer a solution to manage environments in the shell? Also: if a meaningful Guix integration is possible through `buffer-env-script-name` and `buffer-env-command`, I'd be happy to add to the README.
simbledress · 2022-03-05 10:46
> does Guix offer a solution to manage environments in the shell? Yes. You can read about the latest features from [this blog post](https://guix.gnu.org/en/blog/2021/from-guix-environment-to-guix-shell/). > if a meaningful Guix integration is possible My shell scripting skills are a bit rusty, but at a quick glace it seems it'll involve stripping `guix shell --search-paths` of the leading `export ` commands and changing newlines to nulls (maybe using `tr`). If I get round to it I'll be sure to open a PR.
astoff1 · 2022-03-05 11:21
If I'm reading correctly, one can set buffer-env-script name to "guix.scm" and the command to "guix shell -D -f $0 -- env -0".
simbledress · 2022-03-05 12:10
Yes it does work! Thank you. Just for the record, I also tried `guix shell -m $0 -- env -0` with "manifest.scm" and it worked too. Please add it to the README.
simbledress · 2022-03-05 12:50
Just one small detail: The requisite packages should already have been built with one earlier run of `guix shell` at that location. Else the command output buffer of `buffer-env-command` is filled at the start with the (downloading and building) details that the code used to extract paths may not withstand. So a solution (that seems to work) is adding `2> /dev/null` before the `--`.