lang/python: minor refactor & reformatting
This commit is contained in:
parent
39f01450cb
commit
ffb4aa91da
1 changed files with 30 additions and 28 deletions
|
@ -20,6 +20,9 @@ called.")
|
||||||
:init
|
:init
|
||||||
(setq python-environment-directory doom-cache-dir
|
(setq python-environment-directory doom-cache-dir
|
||||||
python-indent-guess-indent-offset-verbose nil)
|
python-indent-guess-indent-offset-verbose nil)
|
||||||
|
|
||||||
|
(when (featurep! +lsp)
|
||||||
|
(add-hook 'python-mode-local-vars-hook #'lsp!))
|
||||||
:config
|
:config
|
||||||
(set-repl-handler! 'python-mode #'+python/open-repl :persist t)
|
(set-repl-handler! 'python-mode #'+python/open-repl :persist t)
|
||||||
(set-docsets! 'python-mode "Python 3" "NumPy" "SciPy")
|
(set-docsets! 'python-mode "Python 3" "NumPy" "SciPy")
|
||||||
|
@ -45,9 +48,6 @@ called.")
|
||||||
;; Stop the spam!
|
;; Stop the spam!
|
||||||
(setq python-indent-guess-indent-offset-verbose nil)
|
(setq python-indent-guess-indent-offset-verbose nil)
|
||||||
|
|
||||||
(when (featurep! +lsp)
|
|
||||||
(add-hook 'python-mode-local-vars-hook #'lsp!))
|
|
||||||
|
|
||||||
;; Default to Python 3. Prefer the versioned Python binaries since some
|
;; Default to Python 3. Prefer the versioned Python binaries since some
|
||||||
;; systems stupidly make the unversioned one point at Python 2.
|
;; systems stupidly make the unversioned one point at Python 2.
|
||||||
(when (and (executable-find "python3")
|
(when (and (executable-find "python3")
|
||||||
|
@ -88,10 +88,17 @@ called.")
|
||||||
|
|
||||||
|
|
||||||
(use-package! anaconda-mode
|
(use-package! anaconda-mode
|
||||||
:after python
|
:defer t
|
||||||
:init
|
:init
|
||||||
(setq anaconda-mode-installation-directory (concat doom-etc-dir "anaconda/")
|
(setq anaconda-mode-installation-directory (concat doom-etc-dir "anaconda/")
|
||||||
anaconda-mode-eldoc-as-single-line t)
|
anaconda-mode-eldoc-as-single-line t)
|
||||||
|
|
||||||
|
(add-hook! 'python-mode-local-vars-hook
|
||||||
|
(defun +python-init-anaconda-mode-maybe-h ()
|
||||||
|
"Enable `anaconda-mode' if `lsp-mode' isn't."
|
||||||
|
(unless (or (bound-and-true-p lsp-mode)
|
||||||
|
(bound-and-true-p lsp--buffer-deferred))
|
||||||
|
(anaconda-mode +1))))
|
||||||
:config
|
:config
|
||||||
(add-hook 'anaconda-mode-hook #'anaconda-eldoc-mode)
|
(add-hook 'anaconda-mode-hook #'anaconda-eldoc-mode)
|
||||||
(set-company-backend! 'anaconda-mode '(company-anaconda))
|
(set-company-backend! 'anaconda-mode '(company-anaconda))
|
||||||
|
@ -101,13 +108,6 @@ called.")
|
||||||
:documentation #'anaconda-mode-show-doc)
|
:documentation #'anaconda-mode-show-doc)
|
||||||
(set-popup-rule! "^\\*anaconda-mode" :select nil)
|
(set-popup-rule! "^\\*anaconda-mode" :select nil)
|
||||||
|
|
||||||
(add-hook! 'python-mode-local-vars-hook :append
|
|
||||||
(defun +python-init-anaconda-mode-maybe-h ()
|
|
||||||
"Enable `anaconda-mode' if `lsp-mode' isn't."
|
|
||||||
(unless (or (bound-and-true-p lsp-mode)
|
|
||||||
(bound-and-true-p lsp--buffer-deferred))
|
|
||||||
(anaconda-mode +1))))
|
|
||||||
|
|
||||||
(defun +python-auto-kill-anaconda-processes-h ()
|
(defun +python-auto-kill-anaconda-processes-h ()
|
||||||
"Kill anaconda processes if this buffer is the last python buffer."
|
"Kill anaconda processes if this buffer is the last python buffer."
|
||||||
(when (and (eq major-mode 'python-mode)
|
(when (and (eq major-mode 'python-mode)
|
||||||
|
@ -115,7 +115,8 @@ called.")
|
||||||
(doom-buffers-in-mode 'python-mode (buffer-list)))))
|
(doom-buffers-in-mode 'python-mode (buffer-list)))))
|
||||||
(anaconda-mode-stop)))
|
(anaconda-mode-stop)))
|
||||||
(add-hook! 'python-mode-hook
|
(add-hook! 'python-mode-hook
|
||||||
(add-hook 'kill-buffer-hook #'+python-auto-kill-anaconda-processes-h nil t))
|
(add-hook 'kill-buffer-hook #'+python-auto-kill-anaconda-processes-h
|
||||||
|
nil 'local))
|
||||||
|
|
||||||
(when (featurep 'evil)
|
(when (featurep 'evil)
|
||||||
(add-hook 'anaconda-mode-hook #'evil-normalize-keymaps))
|
(add-hook 'anaconda-mode-hook #'evil-normalize-keymaps))
|
||||||
|
@ -130,9 +131,10 @@ called.")
|
||||||
|
|
||||||
|
|
||||||
(use-package! pyimport
|
(use-package! pyimport
|
||||||
:after python
|
:defer t
|
||||||
:config
|
:init
|
||||||
(map! :map python-mode-map
|
(map! :after python
|
||||||
|
:map python-mode-map
|
||||||
:localleader
|
:localleader
|
||||||
(:prefix ("i" . "imports")
|
(:prefix ("i" . "imports")
|
||||||
:desc "Insert missing imports" "i" #'pyimport-insert-missing
|
:desc "Insert missing imports" "i" #'pyimport-insert-missing
|
||||||
|
@ -243,19 +245,19 @@ called.")
|
||||||
;; If none of these work for you, `conda-anaconda-home' must be set
|
;; If none of these work for you, `conda-anaconda-home' must be set
|
||||||
;; explicitly. Afterwards, run M-x `conda-env-activate' to switch between
|
;; explicitly. Afterwards, run M-x `conda-env-activate' to switch between
|
||||||
;; environments
|
;; environments
|
||||||
(unless (cl-loop for dir in (list conda-anaconda-home
|
(or (cl-loop for dir in (list conda-anaconda-home
|
||||||
"~/.anaconda"
|
"~/.anaconda"
|
||||||
"~/.miniconda"
|
"~/.miniconda"
|
||||||
"~/.miniconda3"
|
"~/.miniconda3"
|
||||||
"~/miniconda3"
|
"~/miniconda3"
|
||||||
"/usr/bin/anaconda3"
|
"/usr/bin/anaconda3"
|
||||||
"/usr/local/anaconda3"
|
"/usr/local/anaconda3"
|
||||||
"/usr/local/miniconda3"
|
"/usr/local/miniconda3"
|
||||||
"/usr/local/Caskroom/miniconda/base")
|
"/usr/local/Caskroom/miniconda/base")
|
||||||
if (file-directory-p dir)
|
if (file-directory-p dir)
|
||||||
return (setq conda-anaconda-home dir
|
return (setq conda-anaconda-home dir
|
||||||
conda-env-home-directory dir))
|
conda-env-home-directory dir))
|
||||||
(message "Cannot find Anaconda installation"))
|
(message "Cannot find Anaconda installation"))
|
||||||
|
|
||||||
;; integration with term/eshell
|
;; integration with term/eshell
|
||||||
(conda-env-initialize-interactive-shells)
|
(conda-env-initialize-interactive-shells)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue