This is part of the Emacs Starter Kit.
pip install virtualenvwrapper
ln -s ~/.emacs.d/.python-environments/default/ ~/.virtualenvs/emacs
source ~/.emacs.d/.python-environments/default/bin/activate
pip3 install --upgrade isort pyflakes flake8 pylint pychecked
Replace the Python mode that comes with Emacs by the Python mode supplied by the Python distribution itself.
(require 'python-mode)
(require 'auto-virtualenv)
(require 'virtualenvwrapper)
;; Activate on changing buffers
(add-hook 'window-configuration-change-hook 'auto-virtualenv-set-virtualenv)
;; Activate on focus in
(add-hook 'focus-in-hook 'auto-virtualenv-set-virtualenv)
(require 'pyvenv)
(pyvenv-workon "int")
(pyvenv-activate "~/.virtualenvs/emacs3")
(defun custom-python-mode-hook ()
'(lambda ()
(smartparens-global-mode 1)
(require 'smartparens-config)
(show-smartparens-global-mode +1)
(setq flycheck-checker 'python-pylint))
)
(add-hook 'python-mode-hook
'(lambda ()
(run-coding-hook)
(global-eldoc-mode -1)
(custom-python-mode-hook)
(my-personal-code-style 4)
(flycheck-mode t)
(auto-virtualenv-set-virtualenv)
(setq-default py-smart-indentation t)
(setq-default py-jump-on-exception nil)
(setq indent-line-function (quote insert-tab))))
(require 'jedi)
(require 'jedi-direx)
;; Hook up to autocomplete
(add-to-list 'ac-sources 'ac-source-jedi-direct)
;; Don't let tooltip show up automatically
(setq jedi:get-in-function-call-delay 10000000)
;; Start completion at method dot
(setq jedi:complete-on-dot t)
(add-hook 'python-mode-hook
'(lambda ()
'jedi:setup ;; Enable Jedi setup on mode start
'jedi-config:setup-server-args ;; Buffer-specific server options
'jedi-config:setup-keys ;; Use custom keybinds
))
(require 'py-isort)
(add-hook 'before-save-hook 'py-isort-before-save)
(eval-after-load 'python-mode '(progn
(let ((m python-mode-map))
(define-key m (kbd "C-s-e") 'py-end-of-def-or-class)
(define-key m (kbd "C-s-b") 'py-beginning-of-def-or-class)
(define-key m (kbd "C-s-l") 'py-shift-region-left)
(define-key m (kbd "C-s-r") 'py-shift-region-right)
(define-key m (kbd "C-.") 'jedi:goto-definition)
(define-key m (kbd "C-,") 'jedi:goto-definition-pop-marker)
(define-key m (kbd "C-?") 'jedi:show-doc)
(define-key m (kbd "M-/") 'jedi:get-in-function-call)
(define-key m (kbd "C-s-d") 'jedi-direx:pop-to-buffer))))
(add-hook 'python-mode-hook
(lambda ()
(push '(">=" . ?≥) prettify-symbols-alist)
(push '("<=" . ?≤) prettify-symbols-alist)
(push '("!=" . ?≠) prettify-symbols-alist)
(push '("def" . ?ƒ) prettify-symbols-alist)
(push '("sum" . ?∑) prettify-symbols-alist)
(push '("await" . ?⌛) prettify-symbols-alist)
(push '("lambda" . ?λ) prettify-symbols-alist)))
(message "------ Starter Kit Python loaded ------")