2019-04-05 03:16:37 -04:00
|
|
|
;;; tools/direnv/config.el -*- lexical-binding: t; -*-
|
|
|
|
|
2020-02-06 15:29:28 -05:00
|
|
|
(defvar +direnv-keywords
|
2019-07-10 02:29:13 +02:00
|
|
|
'("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")
|
2020-08-21 02:34:07 -04:00
|
|
|
"A list of direnv keywords, which are fontified when in `+direnv-rc-mode'.")
|
2019-07-10 02:29:13 +02:00
|
|
|
|
2020-02-02 03:18:49 -05:00
|
|
|
|
|
|
|
;;
|
|
|
|
;;; Packages
|
|
|
|
|
2020-08-21 02:34:07 -04:00
|
|
|
(use-package! envrc
|
|
|
|
:when (executable-find "direnv")
|
2020-08-23 15:17:37 -04:00
|
|
|
:after-call doom-first-file-hook
|
2020-08-21 02:34:07 -04:00
|
|
|
:mode ("\\.envrc\\'" . +direnv-rc-mode)
|
2019-04-05 03:16:37 -04:00
|
|
|
:config
|
2020-08-21 02:34:07 -04:00
|
|
|
(add-to-list 'doom-debug-variables 'envrc-debug)
|
2019-07-10 02:29:13 +02:00
|
|
|
|
2020-08-21 02:34:07 -04:00
|
|
|
;; I'm avoiding `global-envrc-mode' intentionally, because it has the
|
|
|
|
;; potential to run too late in the mode startup process (and after, say,
|
|
|
|
;; server hooks that may rely on that local direnv environment).
|
|
|
|
(add-hook! 'change-major-mode-after-body-hook
|
|
|
|
(defun +direnv-init-h ()
|
|
|
|
(unless (or envrc-mode
|
|
|
|
(minibufferp)
|
|
|
|
(file-remote-p default-directory))
|
|
|
|
(envrc-mode 1))))
|
|
|
|
|
|
|
|
(define-derived-mode +direnv-rc-mode sh-mode "envrc"
|
|
|
|
"Major mode for .envrc files."
|
|
|
|
;; Fontify .envrc keywords; it's a good indication of whether or not we've
|
|
|
|
;; typed them correctly, and that we're in the correct major mode.
|
2020-02-06 15:29:28 -05:00
|
|
|
(font-lock-add-keywords
|
|
|
|
nil `((,(regexp-opt +direnv-keywords 'symbols)
|
|
|
|
(0 font-lock-keyword-face)))))
|
2019-07-09 16:11:36 +02:00
|
|
|
|
2020-02-02 03:18:49 -05:00
|
|
|
(defadvice! +direnv--fail-gracefully-a (&rest _)
|
|
|
|
"Don't try to use direnv if the executable isn't present."
|
2020-08-21 02:34:07 -04:00
|
|
|
:before-while #'envrc-mode
|
2020-02-02 03:18:49 -05:00
|
|
|
(or (executable-find "direnv")
|
2020-08-21 02:34:07 -04:00
|
|
|
(ignore (doom-log "Couldn't find direnv executable")))))
|