-
Notifications
You must be signed in to change notification settings - Fork 0
/
lang-python.el
66 lines (56 loc) · 1.95 KB
/
lang-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
;; -*- lexical-binding: t; -*-
;;; package --- python configs
;;; Commentary:
;;; Contains my python configs
;;; Code:
(use-package python
:defer t
:mode ("\\.py" . python-mode)
:config
(use-package elpy
:init
(add-to-list 'auto-mode-alist '("\\.py$" . python-mode))
:config
(setq elpy-rpc-backend "jedi")
;; (add-hook 'python-mode-hook 'py-autopep8-enable-on-save)
;;flycheck-python-flake8-executable "/usr/local/bin/flake8"
:bind (:map elpy-mode-map
("M-." . elpy-goto-definition)
("M-," . pop-tag-mark)))
(elpy-enable))
(use-package pip-requirements
:config
(add-hook 'pip-requirements-mode-hook #'pip-requirements-auto-complete-setup))
(use-package py-autopep8)
(use-package pyenv-mode
:if
(executable-find "pyenv")
:init
(add-to-list 'exec-path "~/.pyenv/shims")
(setenv "WORKON_HOME" "~/.pyenv/versions/")
:config
(pyenv-mode)
:bind
("C-x p e" . pyenv-activate-current-project))
(defun pyenv-init()
(setq global-pyenv (replace-regexp-in-string "\n" "" (shell-command-to-string "pyenv global")))
(message (concat "Setting pyenv version to " global-pyenv))
(pyenv-mode-set global-pyenv)
(defvar pyenv-current-version nil global-pyenv))
(defun pyenv-activate-current-project ()
"Automatically activates pyenv version if .python-version file exists."
(interactive)
(f-traverse-upwards
(lambda (path)
(message path)
(let ((pyenv-version-path (f-expand ".python-version" path)))
(if (f-exists? pyenv-version-path)
(progn
(setq pyenv-current-version (s-trim (f-read-text pyenv-version-path 'utf-8)))
(pyenv-mode-set pyenv-current-version)
(pyvenv-workon pyenv-current-version)
(message (concat "Setting virtualenv to " pyenv-current-version))))))))
(add-hook 'after-init-hook 'pyenv-init)
;; (add-hook 'projectile-after-switch-project-hook 'pyenv-activate-current-project)
(provide 'lang-python)
;;; base-python.el ends here