-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: hook for when environment changes #28
Comments
what exactly is your use case? i think you want to detect "i changed between projects" events? anything on top of that? because maybe there's a simpler way that does not involve diffing old and new environments and so on? |
Hi @wbolster, just getting to this. Thanks for the patience. I completely get the idea of wanting to keep the design simple on your end. I still think my request has merit, but let me explain my thoughts with a concrete example: Right now, for Haskell, I'm using Dante, and for Python I'm using anaconda-mode. These tools both run background services based on command-line tools assumed to be on the PATH. For me, Dante runs a Cabal REPL instance, based on tools defined in Nix. And anaconda-mode runs some Python server based on the Python interpreter the project is built against, and I use Nix to manage this too. Getting all the dependencies and versions right for these servers per-project is exactly what Direnv is great for, so in that regard, So right now, I'm making proxy commands for restarting services that make sure call If I had a hook that would trigger when the environment changed in a buffer, I wouldn't have to call my service restarts manually, and I would also not need to call It just makes my life so much cleaner as a consumer. What do you think? |
what information would be needed in such a hook? both the complete old and new environments? |
Hello! I have a similar use-case. I use Nix (and In { pkgs ? import ./pkgs.nix # pinned nixpkgs
}:
let
inherit (pkgs) beam;
erlang = pkgs.erlangR21.override {
enableHipe = false;
wxSupport = true;
};
elixir = (beam.packagesWith erlang).elixir_1_8;
in pkgs.mkShell {
buildInputs = with pkgs; [
elixir
erlang
pgcli
];
ERL_AFLAGS = "-kernel shell_history enabled";
ERLANG_SRC = "${erlang.src}";
ELIXIR_SRC = "${elixir.src}";
} These values are not static (i.e., they are not available system-wide) and may differ from project to project. I tried to set (defun set-erlang/elixir-source (&rest args)
(when (eq major-mode 'elixir-mode)
(when-let* ((erlang-src (getenv "ERLANG_SRC")))
(setq-local alchemist-goto-erlang-source-dir erlang-src))
(when-let* ((elixir-src (getenv "ELIXIR_SRC")))
(setq-local alchemist-goto-elixir-source-dir elixir-src))))
(advice-add 'direnv-update-directory-environment :after #'set-erlang/elixir-source) It feels kinda hackish to me, so I thought that having a hook that runs after |
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.
The text was updated successfully, but these errors were encountered: