           python-shell-completion-string-code
           "';'.join(get_ipython().Completer.all_completions('''%s'''))\n"))
 
-  ;; Python version in modeline
-  (defun +python|update-version (&rest _)
-    (setq +python-version (run-hook-with-args-until-success '+python-version-functions))
-    (dolist (buffer (doom-buffers-in-mode 'python-mode (buffer-list)))
-      (with-current-buffer buffer
-        (+python|add-version-to-modeline +python-version))))
-  (defalias '+python*update-version #'+python|update-version)
+  ;; TODO Remove condition once :ui modeline replaces :ui doom-modeline
+  (when (featurep! :ui modeline)
+    (def-modeline-segment! +python-major-mode
+      (propertize (format-mode-line +python-mode-line-indicator)
+                  'face (if (active) 'doom-modeline-buffer-major-mode)))
 
-  (defun +python|add-version-to-modeline (&optional version)
-    "Add version string to the major mode in the modeline."
-    (setq mode-name
-          (if-let* ((result (or version (+python|update-version))))
-              (format "Python %s" result)
-            "Python")))
-  (add-hook 'python-mode-hook #'+python|add-version-to-modeline))
+    (defun +python|add-version-to-modeline ()
+      "Add python/pipenv version string to the major mode in the modeline."
+      (when-let* ((target (memq '+modeline-major-mode mode-line-format-right)))
+        (setcar target '+python-major-mode)))
+    (add-hook 'python-mode-hook #'+python|add-version-to-modeline)
+
+    (defun +python|update-version (&rest _)
+      (setq +python-version (+python-version)))
+    (+python|update-version)
+    (add-hook 'python-mode-hook #'+python|update-version)))
 
 
 (def-package! anaconda-mode

;;; lang/python/config.el -*- lexical-binding: t; -*-

(defvar +python-version-functions '(+python-version)
  "A list of functions to retrieve a version or environment string from. The
first to return non-nil will have its result appended to the python-mode
`mode-name' and displayed in the mode-line.")


;;

  (defun +python-current-pyvenv () pyvenv-virtual-env-name)
  (add-hook 'pyvenv-post-activate-hooks #'+python|update-version)
  (add-hook 'pyvenv-post-deactivate-hooks #'+python|update-version)
  (add-to-list '+python-mode-line-indicator '(pyvenv-virtual-env-name (" venv:" pyvenv-virtual-env-name)) 'append)
  (add-to-list '+python-version-functions #'+python-current-pyvenv nil #'eq))


