获取 Spacemacs/Emacs GUI 版本以识别 nix-shell 环境

Get Spacemacs/Emacs GUI version to recognize nix-shell environment

我在 Nix shell 中进行开发(在我的项目根目录中创建一个 default.nix 文件,然后 运行 nix-shell . 给我一个 shell 可以访问项目依赖项)。

Spacemacs 是我的主要编辑器,但是当我尝试通过 emacs & 运行 GUI 版本时,我无法访问我的 nix-shell 中的程序(如果例如,我在 Rails 项目的 Ruby 中,并且 Ruby 在我的 default.nix 中被声明为依赖项,我不会在 Spacemacs 中突出显示语法,因为 GUI 版本Emacs 看不到我的 Nix-shell 依赖项)。如果我运行:!which ruby,它甚至找不到which命令。

现在,我正在通过 emacs -nw 运行ning spacemacs 并只是从控制台使用它,但我真的很想能够使用 GUI 编辑器并获得完整的配色方案可用,而不是仅限于在 256 色模式下看起来不错的那些。对我来说,在终端和编辑器之间切换比在 tmux 窗格或终端拆分之间切换到我的 CLI 编辑器更快。

with import <nixpkgs> {}; {
  cannyFreeRadicalEnv = stdenv.mkDerivation rec {
    name = "rails-project-env";
    version = "0.1";
    src = ./.;
    buildInputs = [
        stdenv
        ruby_2_2_2
        bundler
        zlib
        postgresql94
        sqlite
        zsh
        git
        nodejs-0_12
    ];
  };
}

您可以运行您的 GUI Emacs 作为

setsid nix-shell . --command "emacs" &> /dev/null

另见关于 nix-shell integrationflycheckghc-mode 的讨论。


提示: 您可以在 .zshrc.bashrc 中为此使用别名

run-nix-emacs () {
  setsid nix-shell . --command "emacs" &> /dev/null
}

alias ne='run-nix-emacs'

我能够在守护进程模式下通过 运行 space emacs 解决这个问题。 https://www.emacswiki.org/emacs/EmacsAsDaemon

在 default.nix 的目录中: nix-shell . emacs --daemon emacsclient -c -a emacs

我推荐 this nix-shell.el. My fork of it provides some configuration examples. While direnv integration to Emacs works, it is very slow. Not that this is faster, but it happens when you execute M-x nix-shell-activate and so you control when the latency happens. This becomes import if for instance you have a shell.nix in your org-directory for org source blocks in a multi-language environment and do not always want the direnv delay when you are opening an org file. Mario's nix-shell.el should be more widely known. Here 是我发现它的地方。