forked from SystemCrafters/crafted-emacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crafted-python.el
94 lines (71 loc) · 3.32 KB
/
crafted-python.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
;;; crafted-python.el --- python configuration -*- lexical-binding: t; -*-
;; Copyright (C) 2022
;; SPDX-License-Identifier: MIT
;; Author: System Crafters Community
;; Keywords: python
;;; Commentary:
;; Python development environment configuration. Several python
;; packages can be installed with `pip'. Many of these are needed by
;; the Emacs packages used in this configuration.
;; * autopep8 -- automatically formats python code to conform to PEP 8 style guide
;; * black -- uncompromising code formatter
;; * flake8 -- style guide enforcement
;; * importmagic -- automatically add, remove, manage imports
;; * ipython -- interactive python shell
;; * yapf -- formatter for python code
;; Emacs packages to support python development:
;; * anaconda -- code navigation, documentation and completion
;; * blacken -- buffer formatting on save using black
;; (need to pip install black)
;; * eglot -- language server integration
;; (need to pip install pyright)
;; * numpydoc -- python doc templates, uses `yasnippets'
;; * pythonic -- utility packages for running python in different
;; environments (dependency of anaconda)
;; * pyvenv -- virtualenv wrapper
;; Suggested additional keybindings for python-mode
;; (with-eval-after-load "python"
;; (define-key python-mode-map (kbd "C-c C-n") #'numpydoc-generate)
;; (define-key python-mode-map (kbd "C-c e n") #'flymake-goto-next-error)
;; (define-key python-mode-map (kbd "C-c e p") #'flymake-goto-prev-error))
;; Suggested keybindings for pyvenv mode
;; (with-eval-after-load "pyvenv"
;; (define-key pyvenv-mode-map (kbd "C-c p a") #'pyvenv-activate)
;; (define-key pyvenv-mode-map (kbd "C-c p d") #'pyvenv-deactivate)
;; (define-key pyvenv-mode-map (kbd "C-c p w") #'pyvenv-workon))
;;; Code:
(crafted-package-install-package 'anaconda-mode)
(crafted-package-install-package 'blacken)
(crafted-package-install-package 'eglot)
(crafted-package-install-package 'numpydoc)
(crafted-package-install-package 'pyvenv)
;; Hooks
(add-hook 'python-mode-hook #'anaconda-mode)
(add-hook 'python-mode-hook #'blacken-mode)
(add-hook 'python-mode-hook #'eldoc-mode)
(add-hook 'python-mode-hook #'eglot-ensure)
(add-hook 'python-mode-hook #'pyvenv-mode)
(add-hook 'python-mode-hook #'pyvenv-tracking-mode)
;;; anaconda
;; move anaconda python installation directory to
;; `crafted-config-var-directory'
(customize-set-variable
'anaconda-mode-installation-directory
(expand-file-name "anaconda-mode" crafted-config-var-directory))
;; for those who use posframe, use it to show docs
(when (and (crafted-package-installed-p 'posframe)
(featurep 'posframe))
(customize-set-variable 'anaconda-mode-use-posframe-show-doc t))
;;; pyvenv
;; restart python when the virtual environment changes
(add-hook 'pyvenv-post-activate-hooks #'pyvenv-restart-python)
;; default to the commonly used "venv" folder for the virtual
;; environment
(customize-set-variable 'pyvenv-default-virtual-env-name "venv")
;;; python mode
(customize-set-variable 'python-indent-guess-indent-offset-verbose nil)
;;; numpydoc
(customize-set-variable 'numpydoc-insert-examples-block nil)
(customize-set-variable 'numpydoc-template-long nil)
(provide 'crafted-python)
;;; crafted-python.el ends here