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

Mode-line-indicator only in python buffers #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 17 additions & 3 deletions pyvenv.el
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ This is usually the base name of `pyvenv-virtual-env'.")

(defvar pyvenv-mode-line-indicator '(pyvenv-virtual-env-name
("[" pyvenv-virtual-env-name "] "))
"How `pyvenv-mode' will indicate the current environment in the mode line.")
"How `pyvenv-mode' will indicate the current environment in the mode line.
Takes effect when `pyvenv-mode-show-indicator' is non-nil.")

;; Internal code.

Expand Down Expand Up @@ -352,6 +353,19 @@ configured."
["Restart Python Processes" pyvenv-restart-python
:help "Restart all Python processes to use the current environment"]))

(defvar-local pyvenv-mode-show-indicator nil
"Whether to show `pyvenv-mode-line-indicator' in this buffer.
By default set in `python-mode' and `inferior-python-mode' buffers.
To show in all buffers, use (setq-default pyvenv-mode-show-indicator t).")

(defun pyvenv-show-mode-line-indicator ()
"Enable showing `pyvenv-mode-line-indicator' in this buffer."
(setq-local pyvenv-mode-show-indicator t))

(add-hook 'python-mode-hook #'pyvenv-show-mode-line-indicator)
(add-hook 'python-ts-mode-hook #'pyvenv-show-mode-line-indicator)
(add-hook 'inferior-python-mode-hook #'pyvenv-show-mode-line-indicator)

;;;###autoload
(define-minor-mode pyvenv-mode
"Global minor mode for pyvenv.
Expand All @@ -361,10 +375,10 @@ Will show the current virtualenv in the mode line, and respect a
:global t
(cond
(pyvenv-mode
(add-to-list 'mode-line-misc-info '(pyvenv-mode pyvenv-mode-line-indicator))
(add-to-list 'mode-line-misc-info '(pyvenv-mode-show-indicator pyvenv-mode-line-indicator))
(add-hook 'hack-local-variables-hook #'pyvenv-track-virtualenv))
((not pyvenv-mode)
(setq mode-line-misc-info (delete '(pyvenv-mode pyvenv-mode-line-indicator)
(setq mode-line-misc-info (delete '(pyvenv-mode-show-indicator pyvenv-mode-line-indicator)
mode-line-misc-info))
(remove-hook 'hack-local-variables-hook #'pyvenv-track-virtualenv))))

Expand Down