Skip to content

Commit

Permalink
Remove old lighter variables
Browse files Browse the repository at this point in the history
This commits to the new function-based lighter.
  • Loading branch information
sellout committed Aug 17, 2024
1 parent 6a541d0 commit 87d31de
Showing 1 changed file with 29 additions and 43 deletions.
72 changes: 29 additions & 43 deletions envrc.el
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ Messages are written into the *envrc-debug* buffer."
"The direnv executable used by envrc."
:type 'string)

(define-obsolete-variable-alias 'envrc--lighter 'envrc-lighter "2021-05-17")
(make-obsolete-variable 'envrc-lighter 'envrc-lighter-function "2024-08-06")
(make-obsolete-variable 'envrc-none-lighter
'envrc-lighter-function
"2024-08-06")
(make-obsolete-variable 'envrc-on-lighter 'envrc-lighter-function "2024-08-06")
(make-obsolete-variable 'envrc-error-lighter
'envrc-lighter-function
"2024-08-06")

(defcustom envrc-lighter-function #'envrc-standard-lighter
"A function that returns a mode-line lighter for the provided status.
Expand All @@ -98,37 +105,6 @@ set to nil, which disables the lighter."
:type '(choice (const :tag "Disable lighter" nil) function))
(put 'envrc-lighter-function 'risky-local-variable t)

(defcustom envrc-lighter
'(:eval (when envrc-lighter-function
(funcall envrc-lighter-function envrc--status)))
"The mode line lighter for `envrc-mode'.
You can set this to nil to disable the lighter."
:type 'sexp)
(put 'envrc-lighter 'risky-local-variable t)

(defun envrc--default-lighter (status)
"Return a lighter for envrc depending on the provided STATUS."
`( " envrc["
(:propertize ,(format "%s" status)
face
,(pcase status
('on 'envrc-mode-line-on-face)
('error 'envrc-mode-line-error-face)
(_ 'envrc-mode-line-none-face)))
"]"))

(defcustom envrc-none-lighter (envrc--default-lighter 'none)
"Lighter spec used by the default `envrc-lighter' when envrc is inactive."
:type 'sexp)

(defcustom envrc-on-lighter (envrc--default-lighter 'on)
"Lighter spec used by the default `envrc-lighter' when envrc is on."
:type 'sexp)

(defcustom envrc-error-lighter (envrc--default-lighter 'error)
"Lighter spec used by the default `envrc-lighter' when envrc has errored."
:type 'sexp)

(defcustom envrc-command-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "a") 'envrc-allow)
Expand All @@ -151,7 +127,7 @@ e.g. (define-key envrc-mode-map (kbd \"C-c e\") \\='envrc-command-map)"
(define-minor-mode envrc-mode
"A local minor mode in which env vars are set by direnv."
:init-value nil
:lighter envrc-lighter
:lighter envrc--lighter
:keymap envrc-mode-map
(if envrc-mode
(progn
Expand All @@ -163,9 +139,11 @@ e.g. (define-key envrc-mode-map (kbd \"C-c e\") \\='envrc-command-map)"

;;;###autoload
(define-globalized-minor-mode envrc-global-mode envrc-mode
(lambda () (when (and (not (minibufferp)) (not (file-remote-p default-directory))
(executable-find envrc-direnv-executable))
(envrc-mode 1))))
(lambda ()
(when (and (not (minibufferp))
(not (file-remote-p default-directory))
(executable-find envrc-direnv-executable))
(envrc-mode 1))))

(defface envrc-mode-line-on-face '((t :inherit success))
"Face used in mode line to indicate that direnv is in effect.")
Expand All @@ -188,16 +166,24 @@ The values are as produced by `envrc--export'.")
"Symbol indicating state of the current buffer's direnv.
One of \\='(none on error).")

;;; Internals
(defvar envrc--lighter
'(:eval (when envrc-lighter-function
(funcall envrc-lighter-function envrc--status)))
"The mode line lighter for `envrc-mode'.
This is updated based on ‘envrc-lighter-function’.")

(defun envrc-standard-lighter (status)
"Return a lighter for envrc depending on the provided STATUS."
;; TODO: When ‘envrc-STATUS-lighter’ are removed, this can just be replaced
;; with the body of ‘envrc--default-lighter’.
(pcase status
('on envrc-on-lighter)
('error envrc-error-lighter)
(_ envrc-none-lighter)))
`( " envrc["
(:propertize ,(format "%s" status)
face
,(pcase status
('on 'envrc-mode-line-on-face)
('error 'envrc-mode-line-error-face)
(_ 'envrc-mode-line-none-face)))
"]"))

;;; Internals

(defun envrc--env-dir-p (dir)
"Return non-nil if DIR contains a config file for direnv."
Expand Down

0 comments on commit 87d31de

Please sign in to comment.