Repository navigation
Expand file tree
/
Copy pathinit-python.el
More file actions
44 lines (34 loc) · 1.51 KB
/
Copy pathinit-python.el
File metadata and controls
44 lines (34 loc) · 1.51 KB
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
;;; init-python.el --- Python editing -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:
;; I use nix + direnv instead of virtualenv/pyenv/pyvenv, and it is an
;; approach which extends to other languages too. I recorded a
;; screencast about this: https://www.youtube.com/watch?v=TbIHRHy7_JM
(setq auto-mode-alist
(append '(("SConstruct\\'" . python-mode)
("SConscript\\'" . python-mode))
auto-mode-alist))
(setq python-shell-interpreter "python3")
(require-package 'pip-requirements)
(when (maybe-require-package 'anaconda-mode)
(with-eval-after-load 'python
;; Anaconda doesn't work on remote servers without some work, so
;; by default we enable it only when working locally.
(add-hook 'python-mode-hook
(lambda () (unless (file-remote-p default-directory)
(anaconda-mode 1))))
(add-hook 'anaconda-mode-hook
(lambda ()
(anaconda-eldoc-mode (if anaconda-mode 1 0)))))
(with-eval-after-load 'anaconda-mode
(define-key anaconda-mode-map (kbd "M-?") nil))
(when (maybe-require-package 'company-anaconda)
(with-eval-after-load 'company
(with-eval-after-load 'python
(add-to-list 'company-backends 'company-anaconda)))))
(when (maybe-require-package 'toml-mode)
(add-to-list 'auto-mode-alist '("poetry\\.lock\\'" . toml-mode)))
(when (maybe-require-package 'reformatter)
(reformatter-define black :program "black" :args '("-")))
(provide 'init-python)
;;; init-python.el ends here