|
5 | 5 | "join_args" "expand_path" "dotenv" "user_rel_path" "find_up" "source_env" |
6 | 6 | "watch_file" "source_up" "direnv_load" "MANPATH_add" "load_prefix" "layout" |
7 | 7 | "use" "rvm" "use_nix" "use_guix") |
8 | | - "TODO") |
| 8 | + "A list of direnv keywords, which are fontified when in `+direnv-rc-mode'.") |
9 | 9 |
|
10 | 10 |
|
11 | 11 | ;; |
12 | 12 | ;;; Packages |
13 | 13 |
|
14 | | -(use-package! direnv |
15 | | - :hook (before-hack-local-variables . direnv--maybe-update-environment) |
16 | | - :hook (flycheck-before-syntax-check . direnv--maybe-update-environment) |
17 | | - :hook (direnv-envrc-mode . +direnv-envrc-fontify-keywords-h) |
| 14 | +(use-package! envrc |
| 15 | + :when (executable-find "direnv") |
| 16 | + :after-call doom-first-file |
| 17 | + :mode ("\\.envrc\\'" . +direnv-rc-mode) |
18 | 18 | :config |
19 | | - (add-to-list 'direnv-non-file-modes 'vterm-mode) |
| 19 | + (add-to-list 'doom-debug-variables 'envrc-debug) |
20 | 20 |
|
21 | | - (defun +direnv-envrc-fontify-keywords-h () |
22 | | - "Fontify special .envrc keywords; it's a good indication of whether or not |
23 | | -we've typed them correctly." |
| 21 | + ;; I'm avoiding `global-envrc-mode' intentionally, because it has the |
| 22 | + ;; potential to run too late in the mode startup process (and after, say, |
| 23 | + ;; server hooks that may rely on that local direnv environment). |
| 24 | + (add-hook! 'change-major-mode-after-body-hook |
| 25 | + (defun +direnv-init-h () |
| 26 | + (unless (or envrc-mode |
| 27 | + (minibufferp) |
| 28 | + (file-remote-p default-directory)) |
| 29 | + (envrc-mode 1)))) |
| 30 | + |
| 31 | + (define-derived-mode +direnv-rc-mode sh-mode "envrc" |
| 32 | + "Major mode for .envrc files." |
| 33 | + ;; Fontify .envrc keywords; it's a good indication of whether or not we've |
| 34 | + ;; typed them correctly, and that we're in the correct major mode. |
24 | 35 | (font-lock-add-keywords |
25 | 36 | nil `((,(regexp-opt +direnv-keywords 'symbols) |
26 | 37 | (0 font-lock-keyword-face))))) |
27 | 38 |
|
28 | 39 | (defadvice! +direnv--fail-gracefully-a (&rest _) |
29 | 40 | "Don't try to use direnv if the executable isn't present." |
30 | | - :before-while #'direnv-update-directory-environment |
| 41 | + :before-while #'envrc-mode |
31 | 42 | (or (executable-find "direnv") |
32 | | - (ignore (doom-log "Couldn't find direnv executable")))) |
33 | | - |
34 | | - (direnv-mode +1)) |
| 43 | + (ignore (doom-log "Couldn't find direnv executable"))))) |
0 commit comments