wbolster / emacs-direnv Goto Github PK
View Code? Open in Web Editor NEWdirenv integration for emacs
License: BSD 3-Clause "New" or "Revised" License
direnv integration for emacs
License: BSD 3-Clause "New" or "Revised" License
We’ve got a few changes in, should we do a new release? I think I updated the Changelog with everything relevant in my last PR.
I'm using emacs-libvterm and activating emacs-direnv breaks my bash prompt when I start vterm from a project that has a direnv configuration:
\[\][user@host:~/direnv/project]$\[\]
the prompt is configured as per README of emacs-libvterm and the error occurs even if I deactivate the direnv hook for libvterm in .bashrc
.
direnv doesn't add itself to the front of the post-command-hook
meaning other things get to run before direnv has set up the environment.
One example is a haskell/stack project directory, where flycheck cannot find the executables because it runs before direnv has updated the PATH
.
Cc: @bkchr
My direnv version is 2.17.0.
When I browse to a directory in dired, it doesnt change what can be executed; that only changes when I open an actual file.
direnv
can cause emacs
to hangs on exit, following are the minimal steps to reproduce it:
sudo --remove-timestamp
tramp-cleanup-all-connections
, just afterward it already asks the sudo password (dismissing it)I find this strange since you seems to verify that the file is not remote:
Line 129 in 468f2fb
Related to doomemacs/doomemacs#1444.
this is a bit of a pain because (call-process)
does not support this, but a temporary file would work as a workaround.
being able to see the errors is very useful when investigating issues, e.g. errors caused by failing .envrc
scripts (broken paths, among other thinds).
...but let's resolve https://github.com/jml/direnv-el/issues/3 first
Have you thought about having a buffer-local variable (e.g. direnv--cached-environment
) which would be an association list of environment variables and their values. Its default value would be nil.
Any time that variable would be nil, emacs-direnv would run direnv in a sub-shell to get the envars. But if it were non-nil, emacs-direnv would trust the cached values in it and update exec-path
and process-environment
based on them.
I haven't (yet) used environment managers and don't know if this makes sense, but just a hunch.
I have a workflow where i switch to me org file for my projects quite often, and direnv updates the environment accordingly, but it's kind of slow, so it's pretty annoying. I would like if there was some kind of setting where we can put a list of modes or directories, so that direnv doesn't update the path.
when direnv-mode
is enabled, and direnv-always-show-summary
is on, the summary message shows ‘no changes’ when changing between files within the same (direnv managed) project, when those files reside in different directories, e.g. implementation and tests.
it would be nice if the ‘no changes’ message was not shown.
I've been experiencing a direnv configuration error, beyond the scope of this report. (FYI, "direnv export json" is erroring out for me with: Couldn't find a configuration directory for direnv)
When this happens, the problem is compounded by direnv--export trying to parse the stderr output. The symptom is that re-search-backward can't find "^{".
Does it make sense to refrain from parsing when exit-code is nonzero?
...by using the base buffer for directory detection. indirect buffers have no (buffer-file-name ...)
, but their base buffer may have one, so try to use that one instead.
I'm not 100% sure if the problem I'm facing is because of emacs-direnv, and there's a lot of software meant to be working together - so I'm sure the issue could be coming from anywhere - but this felt like a good starting place.
I'm using direnv with nix-shell and lorri such that project specific dependencies are automatically made available when switching into the directory (I believe this is a rather common approach)
I'm working on a typescript project, and I'd like to have the LSP niceities working properly.
I'm using doom-emacs
I've seen the light - and things are mostly working in a magical amazing way! That is to say, the following happens:
$PROJECT/src/index.ts
)
$PROJECT/src/other-file.ts
)other-file
Again, I'm actually not sure. There's a lot that could be going wrong here, but I'm a little stuck on figuring out how to troubleshoot. It seems to me that when I switch to a different buffer in the same directory, emacs-direnv isn't reloading/keeping the environment around... but that might not be the issue.
If you have any ideas for me, I'd be super grateful for your help. Perhaps you know where I can seek help? Perhaps you have an idea for where I can troubleshoot? Perhaps you know the problem immediately (seems unlikely!)
Thank you so much!!
Sometimes direnv-update-environment
takes a while, and it would be nice to see echo
messages from the .envrc
in Emacs to see progress. Is this possible?
hello there, i'm using ihaskell in an isolated nix environment in emacs, and for some reason, emacs is not recognizing jupyter, i'm not sure if this has to do with emacs-direnv, but i'm just checking, here's the issues from the other repos where i posted the errors:
Having support for TRAMP
would allow the use of emacs-direnv
on remote machines.
Hi,
It would be nice if you could add a direnv-executable-find function. This function should wrap executable-find and should just setup the environment variables, based on the current working directory.
I have the idea for this function from nix-executable-find (nix-emacs).
When loading some direnv environments that require to download packages,
in my example nix packages direnv currently blocks the editor without any indication why for the time of the download.
It would be therefore cool to show a message in order to see, where emacs currently blocks.
Hi,
first of all thanks for this package. I was wondering: what do you think about adding it to GNU ELPA or NonGNU ELPA? Is it something you might be interested in?
If so, may I suggest to get in touch with @phikal?
Thank you.
Of course, feel free to close this if there is no interest at all in such a proposal.
I recently started having a weird issue where emacs-direnv
throws an error that doesn't occur in regular direnv
. The output from the *direnv*
buffer is not very enlightening, but it looks related to zlib. Any ideas? Searching for this error leads to some old bug reports on Go, but I haven't been able to make any progress from there.
This happens on only one of my machines. The offending machine runs Arch linux while the working one runs Ubuntu, so I imagine it's related to a particular version or package, perhaps?
direnv: error unmarshal() zlib opening: unexpected EOF
{
"DIRENV_DIFF": "eJw0yl-XakAAAPDvMs_riFktztmHUawRF9MgXhzWdPOnVDSo03e_T_f99wJXoL_eH-AC9BfYYmL-ifMtJkAHgnjqz0xsi3sn_vYVE--sv47g479KEN3Y5h7ogDmLt_Ks27xB4cwtqJK5_jw3EbSHQbOU9cqbPQzjxmOK3B9ptZe1U8JqYcJ5rn1JQq0cw7gx3UeW0iXVwkGadu1tjoIrH4qSR-RA60diuM7sPgu0UX_6ifncWtEDL-fqeTsf1msm7fMOQ_pQSVSUHLd2oLR_izEV5GYclKCpM9PZyVvvOQ1kSBwrYhjWKMtghH6cS4rK3ZJKlEBVNgjE_qKgz4sd3EcYaqyvYjtwBf7l8y7wR7X7lZLQkJjmluWEEAry3KCSXKHvb_B-_wsAAP__9dxuUA==",
"DIRENV_DIR": "-/home/karl/test",
"DIRENV_WATCHES": "eJyM0MFqxCAQxvF38Rxi4mjU3Hss9F560MxMI3VjMe52ofTdS29hWei-wI__971-i5fQVjELuZYTyY9Qs1wKkqxUPpvsabvURXTiuWBLJxLzaAC8GoweOvF0TXvbxdzqmX66e1S_lI3Tu8RUabvIkHP5kgatY-2jts5PjiZEJK2DMzwsRsWJFUeI3iAZZ3UAGJnYAbKyY1TR382BR3IOy5A4nHPrt3Q9eodVHPL-v7OvlPOt8lc1WQB1e9LbbwAAAP__BT12dA=="
}
i really dislike gpl though
Here is my .envrc
:
layout virtualenvwrapper myenv
export TEST="test"
And here is what happens when I cd
in the directory in my shell:
direnv: export +TEST +VIRTUAL_ENV ~PATH
And here is the summary that emacs-direnv
prints when I open a buffer in the same directory:
direnv: +TEST (~/my/project/path)
Is it expected? I am trying to figure a way to get emacs to automatically use the right python version (as installed in my virtualenvs) in my projects with direnv. It works for the shell. I am unsure how much symmetry I should expect in Emacs out of the box with this package.
Thanks.
It would be nice when you detect a new direnv file (different from the active one) and are about to load it if you would unset the previous file's exports. This is one way to approximate direnv's normal unloading when you change out of a directory. This could prevent clashes and inconsistencies, because otherwise as you open several buffers, the environment within emacs will continue to accrete additional state that isn't easily understood by the end user.
This project is currently lacking a clearly stated free license.
Please consider adding one. :-)
Reference: https://github.com/emacsmirror/epkg-reports/blob/master/licenses-details.org
direnv-mode
works ok.
I can enabled and disabled it by direnv-mode
with no errors.
but when i try to add more environment variable with command direnv-edit
, Emacs gives error:
error in process filter: comint-output-filter: Symbol's function definition is void: dirtrack-filter-out-pwd-prompt
error in process filter: Symbol's function definition is void: dirtrack-filter-out-pwd-prompt
direnv edit: exited abnormally with code 1.
And C-h f
dirtrack-filter-out-pwd-prompt
gives me nothing .
and I searched around for dirtrack-filter-out-pwd-prompt
, and found a wiki which shows me how to custom define this function.
this is obviously neither what i want nor what I needed.
any suggestion i could solve this problem ?
Ubuntu 16.04 includes direnv version 2.7.0 but it seems as though 2.8.0 is required as emacs-direnv requires direnv export json
, correct?
https://github.com/direnv/direnv/blob/master/CHANGELOG.md#280--2016-03-27
With 2.7.0, the error from emacs-direnv is:
direnv--export: Error running direnv: exit code 1; output was:
""
However, from the command-line:
$ direnv export json
direnv: error Unknown target shell 'json'
I assume that's stderr and emacs-direnv only captures stdout.
Thanks for this package! It's long overdue.
Hi, I currently start emacs as a daemon with systemd --user.
Do you ever tried that? Because when I do that, direnv does not work. I don't really understand why, maybe it missing some environment variables?
When I start emacs from my terminal, it works as expected (stopped the daemon before).
the post-command-hook
fails with
Error in post-command-hook (direnv--maybe-update-environment): (file-missing "Setting current directory" "Filen eller katalogen finns inte" "/home/wbolster/Projects/abc/dump/")
when dump/
does not exist and using find-file
When changing a user's environment, the package tell the user in some way what envvars have been loaded or unloaded.
It would be really nice if the "compile" command that automatically used the direnv context of the current directory, at least for local compiles.
having direnv-mode
activated and switching to a file in a directory with an .envrc
that is not approved via direnv allow
results in annoying behaviour: a big warning buffer pops up.
the readme has instructions to reduce the severity of that warning buffer, but perhaps it can be skipped altogether by showing an appropriate error message in the echo area instead.
this requires detecting this error condition, propagating that up to the caller, which should ‘unload’ direnv (if coming from another dir), and then showing that error instead of (or in addition to) the usual ‘diff’ status output.
See this issue for description: doomemacs/doomemacs#2424
If I change the command with the prefix argument and prepend PYTHONPATH=src then it works. If I eval getenv "PYTHONPATH"
I get the correct env variable.
How can I run pytest with the correct PYTHONPATH?
When I open a new shell with M-x shell in a direnv-controlled directory, I sometimes find that my DIRENV_DIR/DIRENV_DIFF/DIRENV_WATCHES are set in the shell but the actual env vars I'm trying to set aren't set.
Specifically, the env vars are properly set in emacs in the buffer (ie M-: (getenv "PATH")
shows the right value) but echo $PATH
in the shell doesn't work.
If neither my env vars nor the DIRENV_ vars were set, then direnv itself would just run and fix things, which would be fine. But instead we end up in a place where direnv thinks everything is fine but the vars aren't set.
I can easily fix it with direnv reload
but this is annoying!
I think it would be kind of nice to have a hook that is called only when a direnv environment changes. Sometimes services need to be updated/restarted for a buffer when the context shifts. The two services that I've run into are the anaconda-mode server for Python development, and the dante-mode server for Haskell development.
If we get this hook, it would be nice if it passed along enough information to know exactly which environment variables changed. One way of doing it would be to pass in both the old and new environment map.
I just thought of this idea, so I don't have code for a pull request yet. But I also thought it might be good to talk through too before writing code.
Hi there,
Thank you for the useful package.
But I have found a bug how to use pcase function. I guess it accepts back quote not quote. Also, it fails byte-compile too.
Here is the diff:
@@ -119,9 +119,9 @@ usually results in coloured output."
(face)
(prefix))
(pcase state
- ('added (setq prefix "+" face 'diff-added))
- ('changed (setq prefix "~" face 'diff-changed))
- ('removed (setq prefix "-" face 'diff-removed)))
+ (`added (setq prefix "+" face 'diff-added))
+ (`changed (setq prefix "~" face 'diff-changed))
+ (`removed (setq prefix "-" face 'diff-removed)))
(propertize (concat prefix name) 'face face))
(--sort
(string-lessp (symbol-name (cdr it)) (symbol-name (cdr other)))
Thanks,
For me, the summary never shows in the mini-buffer.
I am not quite sure why I am getting this and (I presume) other people can see the message, but I think it's because somethign is blocking the redisplay. I'd suggest putting "(sit-for 0)" after the message form which normally does the trick!
I updated to the latest in MELPA (v.2) and now the paths don't upgrade.
I see the values in the *direnv*
buffer:
"DIRENV_DIFF": "eJxs0c2OokAcBPB3-Z8FVmWgJdlDoz2jLiIiwuKFtNAiiDB2N4hOfPfNJPuRTeZcVZdffcA7WB_w05smW-KHiylJXLwiYEHDczWvW5VcaCpUZExG8BxA_dmeLXzihsls4YMFirYTjAvtUpzZSfN4U7JUCu1I-Y1VlXajkvFD05wFDP4MIxxM52QLFrBlLx78dW1PyQa7dtJkZiqmt5np0Wgps_htI3M7V7yod3DUe2U3lNzMMzZu2_Hakz3Zt7hChrzdh0dl49RhifQyN5dSd508XXmH6zyiehqYSRr12y37oQ9RbM7dgnC6z_Z3cp4c2xi1UhJFiTKDLyfFOHQVG13dyaPTd21jn96MkK7u18u-Ek3rN8GOvAS2UVa6sUofVz8Tr7RIW4TsvkgxHW6q4HJAp5iH9EV3ks1ohDDGsyQZjZ2A4O8wAC_-ZAiJv12sXbDgN9a_ZOEHO-wkxA3Bgv-A1fc7qzutY1wUTS20sWqohsbq7i85DL668xs8n78CAAD__4cvn7E=",
"DIRENV_DIR": "-/Users/mikeh/Projects/farwell/waterbooks",
"DIRENV_WATCHES": "eJxszrFOBCEQANB_od7csCwD7PaWJtdYGQtgBg-PWxLAWxPjv1tr7gde3uu3OPtxEZuAl86twy1f-QLnVj84jg7Jt4NLgcMPbqHWa4cT7_cWxSSeK418Y7HNiEraZdZyEk9fuY8uttE--Wd6rJ9i3VN-B8qN9zv4UuoBhG6VaMyqmZlsouRoTUE5TB6jl46MczqRdsFaicu88BxicAa1QlTmb8hYrVa54L_Q228AAAD__23LTEA=",
"PYENV_VERSION": "farwell",
"PYENV_VIRTUAL_ENV": "/Users/mikeh/.pyenv/versions/3.6.6/envs/farwell",
"XPC_SERVICE_NAME": "0"
}
direnv: loading .envrc
direnv: export +PYENV_VERSION +PYENV_VIRTUAL_ENV ~XPC_SERVICE_NAME
But my environment isn't actually set in Emacs.
$ which python
/opt/local/bin/python
(this should point to my PYENV_VIRTUAL_ENV
)
As I said, this worked before and then I upgraded direnv and Projectile and now it no longer does.
See flycheck/flycheck-haskell#101 (comment).
I looked through issues and it's likely that this can be best solved by #28. I guess the before-hack-local-variables-hook
isn't blocking and since flycheck-haskell uses the local-variabls-hook
the expected binaries aren't available yet.
In the meantime I'll try this users workaround out.
I get lots of these *Messages*
when visiting first file under direnv
control:
Invalid face reference: diff-changed
Invalid face reference: diff-removed
Invalid face reference: diff-added
Invalid face reference: diff-changed
Invalid face reference: diff-removed
Invalid face reference: diff-added
Invalid face reference: diff-changed
Invalid face reference: diff-removed
Is this a bug?
I often visit files in projects where direnv
is not allowed.
I do not necessarily want to unblock .envrc
for these projects.
In this case, the *Warnings*
buffer keeps popping up with the error message from direnv
.
Is there any way to prevent these warnings from appearing?
Hi! provided-mode-derived-p
was only added in Emacs 26.1, so you might like to bump the required Emacs version, or use a different formulation for that logic. FWIW, recent package-lint
versions can detect this class of issues quite reliably.
My setup:
(setq projectile-switch-project-action 'magit-status)
When (effectively) I run this:
(projectile-switch-project-by-name "myproject")
it would help for direnv to set the environment based on the project directory.
I notice that (direnv--directory) => nil
in the context of magit-status buffers. Does it make sense for me to add magit-mode
to direnv-non-file-modes
? If so, may I propose to change direnv--directory
thus:
(defun direnv--directory ()
"Return the relevant directory for the current buffer, or nil."
(let* ((buffer (or (buffer-base-buffer) (current-buffer)))
(file-name (buffer-file-name buffer)))
(cond (file-name (file-name-directory file-name))
((apply derived-mode-p direnv-non-file-modes) default-directory))))
This way, any magit mode will be counted as a dired-non-file-modes
member.
i used a hidden buffer because it seems the right approach for ‘unintrusive’ buffers, but in practice it's just causing confusion, since people actually do care about that buffer quite often.
i'd happily accept a pull request that removes the space and updates the readme 😉
MELPA Stable lets users install stable¹ versions of software that is available through MELPA. As a MELPA Stable user I have been happily using emacs-direnv; it greatly simplifies my workflow.
I recently stumbled across direnv-non-file-modes
, introduced in this commit. Hoping to use it with Magit and emacs-python-pytest, I tried to set it. Unfortunately, it is not present in the most recent tagged release, version 1.2.1 from June, 2017 (the newest version available through MELPA Stable).
Assuming the code is relatively stable, please consider tagging a new release so MELPA Stable users can use direnv-non-file-modes
and other new features.
Thank you for your hard work!
¹Tagged versions of software are considered stable.
When I open a file in a project whose .envrc
wasn't whitelisted before, the direnv--export will error causing the post-command-hook to be removed. I believe post-command-hooks that fail/error are removed. This causes subsequent buffer switches not to trigger direnv hook.
I am not sure what's the best way to achieve this, but I applied the attached patch that replaces error
with message
locally and it seems to be working fine.
From 96e8c7a70f37167864a410bacad52950b31115b7 Mon Sep 17 00:00:00 2001
From: John Shahid <[email protected]>
Date: Fri, 15 Feb 2019 12:28:27 -0500
Subject: [PATCH] Replace error with message
Otherwise, direnv's post-command-hook could fail causing it to be removed from
the list.
---
direnv.el | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/direnv.el b/direnv.el
index 7d6c135..6bd824f 100644
--- a/direnv.el
+++ b/direnv.el
@@ -97,8 +97,8 @@ In these modes, direnv will use `default-directory' instead of
(exit-code (call-process "direnv" nil '(t t) nil "export" "json")))
(unless (zerop exit-code)
(display-buffer (current-buffer))
- (error "Error running direnv: exit code %s; output is in buffer '%s'"
- exit-code direnv--output-buffer-name))
+ (message "Error running direnv: exit code %s; output is in buffer '%s'"
+ exit-code direnv--output-buffer-name))
(unless (zerop (buffer-size))
(goto-char (point-max))
(re-search-backward "^{")
--
2.20.1
currently, this package will execute direnv export
when switching between two files residing in different directories in the same ‘direnv controlled’ file tree. this will produce empty results, but direnv export
is still executed.
instead, perhaps use locate-dominating-file
to look for an .envrc
file, and use that directory to ‘cache’ the current values, instead of the current behaviour which uses the immediate parent directory of a buffer's file.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.