;;; python.el --- initializes Python modes -*- lexical-binding: t; -*- ;;; Commentary: ;;; Code: (require 'lsp-pylsp) (defun user--python-format-before-save () "Python cleanup and format before save buffer." (lsp-format-buffer) (delete-trailing-whitespace)) (defun user--python-mode-hook () "Python mode hook." ;; lsp python customization (lsp-register-custom-settings '(("pylsp.plugins.pyls_mypy.enabled" t t) ("pylsp.plugins.flake8.maxLineLength" 100) ("pylsp.plugins.yapf.enabled" t t) ("pylsp.plugins.pylint.enabled" t t))) ;; Enable virtualenv support. (when(feature-p 'pyvenv) (pyvenv-mode t)) (when(feature-p 'anaconda-mode) (anaconda-mode t)) ;; Enable smart parenthesis handling. (user/smartparens-enable) ;; Separate camel-case into separate words (subword-mode t) ;; ElDoc shows function documentation as you type (eldoc-mode t)) (use-package python :if (executable-find "python") :defer :mode ("SCon\(struct\|script\)$" . python-mode) :interpreter ("python[0-9.]*" . python-mode) :hook (python-mode-hook . lsp) (python-mode-hook . user--python-mode-hook) (python-mode-hook . (lambda () (add-hook 'before-save-hook #'user--python-format-before-save nil t))) :config (validate-setq ;; Don't try to guess the indentation. python-indent-guess-indent-offset nil) (with-executable 'ipython3 (validate-setq ;; Set IPython as default interpreter. python-shell-interpreter "ipython3" python-shell-interpreter-args "" python-shell-prompt-regexp "In \\[[0-9]+\\]: " python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: " python-shell-completion-setup-code "from IPython.core.completerlib import module_completion" python-shell-completion-string-code "';'.join(get_ipython().Completer.all_completions('''%s'''))\n")) (with-executable 'bpython (defun user/bpython-term() "Launch or switch to a `bpython' buffer." (interactive) (if (not (get-buffer "*bpython*")) (progn (ansi-term "bpython" "bpython")) (switch-to-buffer "*bpython*")))) ;; (Packages) ;; ;; https://github.com/pythonic-emacs/anaconda-mode ;; Code navigation, documentation lookup and completion for Python. (use-package anaconda-mode) ;; https://github.com/tsgates/pylookup ;; Emacs mode for searching python documents with convenience (use-package pylookup :disabled :quelpa(pylookup :fetcher github :repo "tsgates/pylookup")) ;; https://github.com/syl20bnr/nose.el ;; This gives a bunch of functions that handle running nosetests on a particular buffer or part of a buffer. (use-package nose :disabled) ;; https://github.com/tkf/emacs-python-environment ;; Python virtualenv API for Emacs Lisp (use-package python-environment :disabled :config (validate-setq ;; Locate of Python environment store. python-environment-directory(path-join *user-cache-directory* "python-environment"))) ;; https://github.com/pwalsh/pipenv.el ;; A Pipenv porcelain inside Emacs. (use-package pipenv :disabled :if (executable-find "pipenv") :hook(python-mode-hook . pipenv-mode)) ;; https://github.com/msherry/flycheck-pycheckers ;; Multiple syntax checker for Python in Emacs, using Flycheck (use-package flycheck-pycheckers :disabled :after flycheck :hook (flycheck-mode-hook . flycheck-pycheckers-setup) :config (setq flycheck-pycheckers-checkers (remove 'mypy2 flycheck-pycheckers-checkers)) ) ;; https://github.com/chocoelho/flycheck-prospector ;; flycheck support for prospector (use-package flycheck-prospector :disabled :if (executable-find "prospector") :hook(flycheck-mode-hook . flycheck-prospector-setup)) ;; https://github.com/jgosmann/pylint-venv ;; Make pylint respect virtualenvs. (use-package pyvenv :ensure t :config (pyvenv-mode 1)) ;; https://github.com/emacsorphanage/helm-pydoc ;; helm-pydoc.el is pydoc helm interface (use-package helm-pydoc :pin "MELPA")) (provide 'modes/python) ;;; python.el ends here