Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify mode-line lighter customization #86

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 33 additions & 27 deletions envrc.el
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,21 @@ 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")

(defcustom envrc-lighter '(:eval (envrc--lighter))
"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)

(defcustom envrc-none-lighter '(" envrc[" (:propertize "none" face envrc-mode-line-none-face) "]")
"Lighter spec used by the default `envrc-lighter' when envrc is inactive."
:type 'sexp)

(defcustom envrc-on-lighter '(" envrc[" (:propertize "on" face envrc-mode-line-on-face) "]")
"Lighter spec used by the default `envrc-lighter' when envrc is on."
:type 'sexp)

(defcustom envrc-error-lighter '(" envrc[" (:propertize "error" face envrc-mode-line-error-face) "]")
"Lighter spec used by the default `envrc-lighter' when envrc has errored."
:type 'sexp)
(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.
The status is one of the symbols on, error, or none). This variable may also be
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-command-map
(let ((map (make-sparse-keymap)))
Expand Down Expand Up @@ -139,7 +135,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 Down Expand Up @@ -189,14 +185,24 @@ One of \\='(none on error).")
If set, this will override `tramp-remote-path' via connection
local variables.")

;;; 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."
`( " 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)))
"]"))

(defun envrc--lighter ()
"Return a colourised version of `envrc--status' for use in the mode line."
(pcase envrc--status
(`on envrc-on-lighter)
(`error envrc-error-lighter)
(`none envrc-none-lighter)))
;;; Internals

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