mirror of
https://gitlab.com/dwt1/dotfiles.git
synced 2026-04-23 11:30:23 +10:00
Moving to Doom Emacs!
This commit is contained in:
93
.emacs.d/modules/tools/direnv/README.org
Normal file
93
.emacs.d/modules/tools/direnv/README.org
Normal file
@@ -0,0 +1,93 @@
|
||||
#+TITLE: tools/direnv
|
||||
#+DATE: July 10, 2019
|
||||
#+SINCE: v2.1.0
|
||||
#+STARTUP: inlineimages
|
||||
|
||||
* Table of Contents :TOC_3:noexport:
|
||||
- [[#description][Description]]
|
||||
- [[#module-flags][Module Flags]]
|
||||
- [[#plugins][Plugins]]
|
||||
- [[#hacks][Hacks]]
|
||||
- [[#prerequisites][Prerequisites]]
|
||||
- [[#macos][MacOS]]
|
||||
- [[#arch-linux][Arch Linux]]
|
||||
- [[#nixos][NixOS]]
|
||||
- [[#troubleshooting][Troubleshooting]]
|
||||
- [[#direnv--nix-is-slow][direnv + nix is slow]]
|
||||
|
||||
* Description
|
||||
This module integrates direnv into Emacs.
|
||||
|
||||
#+begin_quote
|
||||
direnv is an environment switcher for the shell. It knows how to hook into bash,
|
||||
zsh, tcsh, fish shell and elvish to load or unload environment variables
|
||||
depending on the current directory. This allows project-specific environment
|
||||
variables without cluttering the ~/.profile file.
|
||||
|
||||
Before each prompt, direnv checks for the existence of a ".envrc" file in the
|
||||
current and parent directories. If the file exists (and is authorized), it is
|
||||
loaded into a bash sub-shell and all exported variables are then captured by
|
||||
direnv and then made available to the current shell.
|
||||
#+end_quote
|
||||
|
||||
** Module Flags
|
||||
This module provides no flags.
|
||||
|
||||
** Plugins
|
||||
+ [[https://github.com/wbolster/emacs-direnv][direnv]]
|
||||
|
||||
** Hacks
|
||||
+ Normally, the direnv environment is updated on ~post-command-hook~. We've
|
||||
changed it to update on ~doom-switch-buffer-hook~, ~doom-switch-window-hook~
|
||||
and ~doom-switch-frame-hook~ instead.
|
||||
+ Special direnv keywords/commands are highlighted in direnv-envrc-mode.
|
||||
+ A fix has been applied to ensure flycheck searches for executables from within
|
||||
the direnv environment, if any.
|
||||
|
||||
* Prerequisites
|
||||
This module requires the ~direnv~ utility.
|
||||
|
||||
** MacOS
|
||||
#+BEGIN_SRC bash
|
||||
brew install direnv
|
||||
#+END_SRC
|
||||
|
||||
** Arch Linux
|
||||
#+BEGIN_SRC bash
|
||||
sudo pacman -S direnv
|
||||
#+END_SRC
|
||||
|
||||
** NixOS
|
||||
#+BEGIN_SRC nix
|
||||
environment.systemPackages = [ pkgs.direnv ];
|
||||
#+END_SRC
|
||||
|
||||
Or ~nix-env -i direnv~
|
||||
|
||||
* Troubleshooting
|
||||
** direnv + nix is slow
|
||||
Consider augmenting direnv with [[https://github.com/target/lorri][lorri]], which will cache nix builds and speed up
|
||||
direnv tremendously.
|
||||
|
||||
At the time of writing, the lorri package in nixpkgs simply emits an error
|
||||
message, telling you to install it manually. You can get around this with:
|
||||
|
||||
#+BEGIN_SRC nix
|
||||
nixpkgs.overlays = [
|
||||
(self: super: {
|
||||
lorri =
|
||||
let src = (super.fetchFromGitHub {
|
||||
owner = "target";
|
||||
repo = "lorri";
|
||||
rev = "38eae3d487526ece9d1b8c9bb0d27fb45cf60816";
|
||||
sha256 = "11k9lxg9cv6dlxj4haydvw4dhcfyszwvx7jx9p24jadqsy9jmbj4";
|
||||
});
|
||||
in import src { inherit src; };
|
||||
})
|
||||
];
|
||||
|
||||
environment.systemPackages = [ pkgs.lorri ];
|
||||
#+END_SRC
|
||||
|
||||
Otherwise, follow [[https://github.com/target/lorri#installing-lorri][the instructions in lorri's README]] on how to install it
|
||||
manually.
|
||||
69
.emacs.d/modules/tools/direnv/config.el
Normal file
69
.emacs.d/modules/tools/direnv/config.el
Normal file
@@ -0,0 +1,69 @@
|
||||
;;; tools/direnv/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defvar +direnv--keywords
|
||||
'("direnv_layout_dir" "PATH_add" "path_add" "log_status" "log_error" "has"
|
||||
"join_args" "expand_path" "dotenv" "user_rel_path" "find_up" "source_env"
|
||||
"watch_file" "source_up" "direnv_load" "MANPATH_add" "load_prefix" "layout"
|
||||
"use" "rvm" "use_nix" "use_guix")
|
||||
"TODO")
|
||||
|
||||
(use-package! direnv
|
||||
:after-call after-find-file dired-initial-position-hook
|
||||
:config
|
||||
(add-hook! 'direnv-mode-hook
|
||||
(defun +direnv-init-h ()
|
||||
"Instead of checking for direnv on `post-command-hook', check only once,
|
||||
when the file is first opened/major mode is activated. This is significantly
|
||||
less expensive, but is less sensitive to changes to .envrc done outside of
|
||||
Emacs."
|
||||
(direnv--disable)
|
||||
(when direnv-mode
|
||||
(add-hook 'after-change-major-mode-hook
|
||||
#'direnv--maybe-update-environment))))
|
||||
|
||||
(defadvice! +direnv--make-process-environment-buffer-local-a (items)
|
||||
:filter-return #'direnv--export
|
||||
(when items
|
||||
(mapc 'kill-local-variable '(process-environment exec-path))
|
||||
(mapc 'make-local-variable '(process-environment exec-path)))
|
||||
items)
|
||||
|
||||
;; Fontify special .envrc keywords; it's a good indication of whether or not
|
||||
;; we've typed them correctly.
|
||||
(add-hook! 'direnv-envrc-mode-hook
|
||||
(defun +direnv-envrc-fontify-keywords-h ()
|
||||
(font-lock-add-keywords
|
||||
nil `((,(regexp-opt +direnv--keywords 'symbols)
|
||||
(0 font-lock-keyword-face)))))
|
||||
(defun +direnv-update-on-save-h ()
|
||||
(add-hook 'after-save-hook #'direnv--maybe-update-environment
|
||||
nil 'local)))
|
||||
|
||||
(defadvice! +direnv-update-a (&rest _)
|
||||
"Update direnv. Useful to advise functions that may run
|
||||
environment-sensitive logic like `flycheck-default-executable-find'. This fixes
|
||||
flycheck issues with direnv and on nix."
|
||||
:before #'flycheck-default-executable-find
|
||||
(direnv--maybe-update-environment))
|
||||
|
||||
(defadvice! +direnv--fail-gracefully-a (orig-fn)
|
||||
"Don't try to update direnv if the executable isn't present."
|
||||
:around #'direnv--maybe-update-environment
|
||||
(if (executable-find "direnv")
|
||||
(when (file-readable-p (or buffer-file-name default-directory))
|
||||
(funcall orig-fn))
|
||||
(doom-log "Couldn't find direnv executable")))
|
||||
|
||||
(defadvice! +direnv-update-async-shell-command-a (command &optional output-buffer _error-buffer)
|
||||
:before #'shell-command
|
||||
(when (string-match "[ \t]*&[ \t]*\\'" command)
|
||||
(let ((environment process-environment)
|
||||
(path exec-path)
|
||||
(shell shell-file-name))
|
||||
(with-current-buffer
|
||||
(get-buffer-create (or output-buffer "*Async Shell Command*"))
|
||||
(setq-local process-environment environment)
|
||||
(setq-local exec-path path)
|
||||
(setq-local shell-file-name shell)))))
|
||||
|
||||
(direnv-mode +1))
|
||||
4
.emacs.d/modules/tools/direnv/doctor.el
Normal file
4
.emacs.d/modules/tools/direnv/doctor.el
Normal file
@@ -0,0 +1,4 @@
|
||||
;;; tools/direnv/doctor.el -*- lexical-binding: t; -*-
|
||||
|
||||
(unless (executable-find "direnv")
|
||||
(warn! "Couldn't find direnv executable"))
|
||||
4
.emacs.d/modules/tools/direnv/packages.el
Normal file
4
.emacs.d/modules/tools/direnv/packages.el
Normal file
@@ -0,0 +1,4 @@
|
||||
;; -*- no-byte-compile: t; -*-
|
||||
;;; tools/direnv/packages.el
|
||||
|
||||
(package! direnv)
|
||||
Reference in New Issue
Block a user