Adopt seagle0128/doom-modeline for :ui modeline

And remove obsolete :ui doom-modeline module.

Relevant to: #136, #921
This commit is contained in:
Henrik Lissner 2019-03-01 15:12:27 -05:00
parent 868bd15abe
commit 8832737671
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
17 changed files with 90 additions and 1944 deletions

View file

@ -1,8 +1,5 @@
;;; lang/python/autoload/python.el -*- lexical-binding: t; -*-
(defvar +python-version-cache (make-hash-table :test 'equal)
"TODO")
;;;###autoload
(defun +python/open-repl ()
"Open the Python REPL."
@ -38,53 +35,3 @@
(let ((python-shell-interpreter "jupyter")
(python-shell-interpreter-args (format "console %s" (string-join +python-jupyter-repl-args " "))))
(+python/open-repl)))
(defun +python--extract-version (prefix str)
(when str
(format "%s%s" prefix (cadr (split-string str " ")))))
;;;###autoload
(defun +python-version ()
"Return the currently installed version of python on your system or active in
the current pipenv.
This is not necessarily aware of env management tools like virtualenv, pyenv or
pipenv, unless those tools have modified the PATH that Emacs picked up when you
started it."
(condition-case _
(if-let* ((proot (and (fboundp 'pipenv-project-p)
(pipenv-project-p))))
(let* ((default-directory proot)
(v (car (process-lines "pipenv" "run" "python" "--version"))))
(puthash proot
(+python--extract-version "Pipenv " v)
+python-version-cache))
(puthash (or (doom-project-root) default-directory)
(+python--extract-version
"Python "
(car (process-lines python-shell-interpreter "--version")))
+python-version-cache))
(error "Python")))
;;
;; Hooks
;;;###autoload
(defun +python|update-version (&rest _)
"Update `+python--version' by consulting `+python-version' function."
(setq +python--version
(or (gethash (or (and (fboundp 'pipenv-project-p)
(pipenv-project-p))
(doom-project-root)
default-directory)
+python-version-cache)
(+python-version))))
;;;###autoload
(defun +python|update-version-in-all-buffers (&rest _)
"Update `+python-version' in all buffers in `python-mode'."
(dolist (buffer (doom-buffers-in-mode 'python-mode))
(setq +python-version-cache (clrhash +python-version-cache))
(with-current-buffer buffer
(+python|update-version))))

View file

@ -11,9 +11,6 @@ called.")
"CLI arguments to initialize 'jupiter console %s' with when
`+python/open-ipython-repl' is called.")
(defvar-local +python--version nil
"The python version in the current buffer.")
;;
;; Packages
@ -55,14 +52,7 @@ called.")
sp-point-after-word-p
sp-point-before-same-p))
(setq-hook! 'python-mode-hook tab-width python-indent-offset)
;; Add python/pipenv version string to the major mode in the modeline
(defun +python|init-mode-line ()
(setq mode-name +python-mode-line-indicator))
(add-hook 'python-mode-hook #'+python|init-mode-line)
(add-hook 'python-mode-hook #'+python|update-version))
(setq-hook! 'python-mode-hook tab-width python-indent-offset))
(def-package! anaconda-mode
@ -152,9 +142,9 @@ called.")
(format "PIPENV_MAX_DEPTH=9999 %s run %%c %%o %%s %%a" bin)
"%c %o %s %a")))
(:description . "Run Python script")))
(advice-add #'pipenv-activate :after-while #'+python|update-version-in-all-buffers)
(advice-add #'pipenv-deactivate :after-while #'+python|update-version-in-all-buffers))
(when (featurep! :ui modeline)
(advice-add #'pipenv-activate :after-while #'+modeline|update-env-in-all-windows)
(advice-add #'pipenv-deactivate :after-while #'+modeline|update-env-in-all-windows)))
(def-package! pyenv-mode
@ -164,8 +154,9 @@ called.")
(pyenv-mode +1)
(when (executable-find "pyenv")
(add-to-list 'exec-path (expand-file-name "shims" (or (getenv "PYENV_ROOT") "~/.pyenv"))))
(advice-add #'pyenv-mode-set :after #'+python|update-version-in-all-buffers)
(advice-add #'pyenv-mode-unset :after #'+python|update-version-in-all-buffers))
(when (featurep! :ui modeline)
(advice-add #'pyenv-mode-set :after #'+modeline|update-env-in-all-windows)
(advice-add #'pyenv-mode-unset :after #'+modeline|update-env-in-all-windows)))
(def-package! pyvenv
@ -173,9 +164,10 @@ called.")
:after python
:config
(defun +python-current-pyvenv () pyvenv-virtual-env-name)
(add-hook 'pyvenv-post-activate-hooks #'+python|update-version-in-all-buffers)
(add-hook 'pyvenv-post-deactivate-hooks #'+python|update-version-in-all-buffers)
(add-to-list '+python-mode-line-indicator
(when (featurep! :ui modeline)
(add-hook 'pyvenv-post-activate-hooks #'+modeline|update-env-in-all-windows)
(add-hook 'pyvenv-post-deactivate-hooks #'+modeline|update-env-in-all-windows))
(add-to-list 'global-mode-string
'(pyvenv-virtual-env-name (" venv:" pyvenv-virtual-env-name))
'append))
@ -214,8 +206,9 @@ called.")
(conda-env-initialize-interactive-shells)
(after! eshell (conda-env-initialize-eshell))
(add-hook 'conda-postactivate-hook #'+python|update-version-in-all-buffers)
(add-hook 'conda-postdeactivate-hook #'+python|update-version-in-all-buffers)
(add-to-list '+python-mode-line-indicator
(when (featurep! :ui modeline)
(add-hook 'conda-postactivate-hook #'+modeline|update-env-in-all-windows)
(add-hook 'conda-postdeactivate-hook #'+modeline|update-env-in-all-windows))
(add-to-list 'global-mode-string
'(conda-env-current-name (" conda:" conda-env-current-name))
'append))