Code Monkey home page Code Monkey logo

emacs-direnv's People

Contributors

bcc32 avatar bricewge avatar collares avatar com4 avatar dkellner avatar erickgnavar avatar eush77 avatar glasser avatar jgarte avatar jobevers avatar juergenhoetzel avatar pclewis avatar phikal avatar profpatsch avatar rvl avatar stribb avatar syohex avatar wbolster avatar wyuenho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

emacs-direnv's Issues

release 1.5.0

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.

emacs-direnv breaks vterm prompt

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 loads too late sometimes

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

can make emacs hangs on kill-emacs

direnv can cause emacs to hangs on exit, following are the minimal steps to reproduce it:

  1. Opening a file as sudo through TRAMP and entering correct password
  2. sudo --remove-timestamp
  3. tramp-cleanup-all-connections, just afterward it already asks the sudo password (dismissing it)
  4. Exiting emacs hangs for sudo password

I find this strange since you seems to verify that the file is not remote:

(not (file-remote-p directory-name)))

Related to doomemacs/doomemacs#1444.

keep direnv stderr output

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).

Caching strategies

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.

Feature: Disable updating environment for certain files/modes

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.

summary message should not show ‘no changes’

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.

direnv-mode tries to parse direnv errors

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?

gracefully handle indirect buffers

...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.

direnv environment carrying over between buffers

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.

What I'm shooting for

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:

  • I open emacs
  • I open a buffer with a typescript file in a project I'm working on (eg. $PROJECT/src/index.ts)
    • I see direnv do it's thing and there's output indicating it's loading the environment
  • the language server connects, and BOOM! everything is groovy, I'm loving life, I can do all the cool LSP stuff and my development experience is lovely.

So what's the problem

  • I open a different file in the project (eg. $PROJECT/src/other-file.ts)
  • LSP complains "No LSP server for web-mode"
    This is the core problem, it kind of seems like it's unable to find the binary, but the lsp-log doesn't have very useful output
  • But then, if open a buffer for a file outside of the project (eg. $HOME/.config/something`)
    • I see direnv unload all the environment config
  • I then switch back to other-file
    • I see direnv do it's thing
  • I'm able to connect to the language server for that file!!

So what's the issue?

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!!

Show messages from `.envrc` in Emacs

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?

Add direnv-executable-find

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).

Show message when waiting for direnv

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.

Add to (Non)GNU ELPA?

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.

Error with zlib that doesn't occur in `direnv`

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=="
}

Python virtualenvwrapper

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.

Track previously set envvars, and unset them when loading a new direnv config

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.

`direnv-edit` doesn't work.

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 ?

Document minimum required version of direnv.

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.

Emacs daemon

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).

guard against directories that do not exist

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

Does not work with M-x compile RET

It would be really nice if the "compile" command that automatically used the direnv context of the current directory, at least for local compiles.

error handling for blocked directories is annoying

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.

Opening a new M-x shell fails sometimes

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!

Feature: hook for when environment changes

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.

Failed to apply prefix

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,

Summary not showing

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!

Not updating after upgrade

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.

Lots of these message "Invalid face reference: (diff-changed|dif-removed|diff-added)

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?

*Warnings* buffer pops up when .envrc is blocked

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?

Code actually requires Emacs 26.1

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.

magit status doesn't trigger a direnv update

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.

make direnv output buffer more discoverable

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 😉

#34 (comment)

Consider tagging a new release

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.

The post-command-hook will fail if the .envrc file isn't allowed

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

use closest dir with .envrc instead of direct parent for caching

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.

see https://twitter.com/wbolster/status/1265184858864828416

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.