2015-01-14 04:12:56 +00:00
|
|
|
;;; packages.el --- Python Layer packages File for Spacemacs
|
|
|
|
;;
|
|
|
|
;; Copyright (c) 2012-2014 Sylvain Benner
|
|
|
|
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
|
|
|
|
;;
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
2014-11-10 04:54:10 +00:00
|
|
|
(defvar python-packages
|
|
|
|
'(
|
|
|
|
anaconda-mode
|
|
|
|
ac-anaconda
|
|
|
|
company-anaconda
|
|
|
|
eldoc
|
2014-12-09 03:19:55 +00:00
|
|
|
evil-jumper
|
2014-11-10 04:54:10 +00:00
|
|
|
flycheck
|
2014-12-14 05:19:20 +00:00
|
|
|
hy-mode
|
2015-01-30 15:30:10 +00:00
|
|
|
pony-mode
|
|
|
|
pyenv-mode
|
2014-11-10 04:54:10 +00:00
|
|
|
pyvenv
|
|
|
|
python
|
2014-12-09 17:08:30 +00:00
|
|
|
semantic
|
2014-12-12 03:16:09 +00:00
|
|
|
smartparens
|
2015-01-22 16:22:19 +00:00
|
|
|
cython-mode
|
2014-11-10 04:54:10 +00:00
|
|
|
)
|
|
|
|
"List of all packages to install and/or initialize. Built-in packages
|
|
|
|
which require an initialization must be listed explicitly in the list.")
|
|
|
|
|
2014-12-09 03:19:55 +00:00
|
|
|
(defun python/init-ac-anaconda ()
|
|
|
|
(use-package ac-anaconda
|
|
|
|
:if (boundp 'ac-sources)
|
|
|
|
:defer t
|
2015-02-03 17:53:00 +00:00
|
|
|
:init (add-hook 'python-mode-hook 'ac-anaconda-setup)
|
|
|
|
:config
|
|
|
|
(progn
|
|
|
|
(add-to-list 'evil-emacs-state-modes 'anaconda-nav-mode)
|
|
|
|
(spacemacs/activate-evil-leader-for-map 'anaconda-nav-mode-map)
|
|
|
|
(spacemacs|evilify anaconda-nav-mode-map
|
|
|
|
(kbd "H") 'previous-error
|
|
|
|
(kbd "J") 'anaconda-nav-next-module
|
|
|
|
(kbd "K") 'anaconda-nav-previous-module
|
|
|
|
(kbd "L") 'next-error))))
|
2014-12-09 03:19:55 +00:00
|
|
|
|
|
|
|
(defun python/init-anaconda-mode ()
|
|
|
|
(use-package anaconda-mode
|
|
|
|
:defer t
|
|
|
|
:init (add-hook 'python-mode-hook 'anaconda-mode)
|
|
|
|
:config
|
|
|
|
(progn
|
|
|
|
(evil-leader/set-key-for-mode 'python-mode
|
2014-12-22 03:52:57 +00:00
|
|
|
"mhd" 'anaconda-mode-view-doc
|
2015-01-21 03:32:13 +00:00
|
|
|
"mgg" 'anaconda-mode-goto)
|
2014-12-09 03:19:55 +00:00
|
|
|
(spacemacs|hide-lighter anaconda-mode))))
|
|
|
|
|
|
|
|
(defun python/init-company-anaconda ()
|
|
|
|
(use-package company-anaconda
|
|
|
|
:if (boundp 'company-backends)
|
|
|
|
:defer t
|
2014-12-11 15:20:50 +00:00
|
|
|
:init (add-to-list 'company-backends 'company-anaconda)))
|
2014-12-09 03:19:55 +00:00
|
|
|
|
2015-01-22 16:22:19 +00:00
|
|
|
(defun python/init-cython-mode ()
|
|
|
|
(use-package cython-mode
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(evil-leader/set-key-for-mode 'cython-mode
|
|
|
|
"mhd" 'anaconda-mode-view-doc
|
|
|
|
"mgg" 'anaconda-mode-goto)
|
|
|
|
)))
|
|
|
|
|
2014-12-09 03:19:55 +00:00
|
|
|
(defun python/init-eldoc ()
|
2014-12-23 03:05:03 +00:00
|
|
|
(add-hook 'python-mode-hook 'eldoc-mode))
|
2014-12-09 03:19:55 +00:00
|
|
|
|
|
|
|
(defun python/init-evil-jumper ()
|
|
|
|
(defadvice anaconda-mode-goto (before python/anaconda-mode-goto activate)
|
|
|
|
(evil-jumper--push)))
|
|
|
|
|
2015-01-30 15:30:10 +00:00
|
|
|
(defun python/init-pony-mode ()
|
|
|
|
(use-package pony-mode
|
|
|
|
:defer t
|
|
|
|
:init (progn
|
|
|
|
(evil-leader/set-key-for-mode 'python-mode
|
2015-01-31 03:28:47 +00:00
|
|
|
; d*j*ango f*a*bric
|
|
|
|
"mjaf" 'pony-fabric
|
|
|
|
"mjad" 'pony-fabric-deploy
|
|
|
|
; d*j*ango *f*iles
|
|
|
|
"mjfs" 'pony-goto-settings
|
|
|
|
"mjfc" 'pony-setting
|
|
|
|
"mjft" 'pony-goto-template
|
|
|
|
"mjfr" 'pony-resolve
|
|
|
|
; d*j*ango *i*nteractive
|
|
|
|
"mjid" 'pony-db-shell
|
|
|
|
"mjis" 'pony-shell
|
|
|
|
; d*j*ango *m*anage
|
|
|
|
; not including one-off management commands like "flush" and
|
|
|
|
; "startapp" even though they're implemented in pony-mode,
|
|
|
|
; because this is much handier
|
|
|
|
"mjm" 'pony-manage
|
2015-01-30 15:30:10 +00:00
|
|
|
; d*j*ango *r*unserver
|
|
|
|
"mjrd" 'pony-stopserver
|
|
|
|
"mjro" 'pony-browser
|
2015-01-31 03:28:47 +00:00
|
|
|
"mjrr" 'pony-restart-server
|
|
|
|
"mjru" 'pony-runserver
|
|
|
|
"mjrt" 'pony-temp-server
|
2015-01-30 15:30:10 +00:00
|
|
|
; d*j*ango *s*outh/*s*yncdb
|
|
|
|
"mjsc" 'pony-south-convert
|
|
|
|
"mjsh" 'pony-south-schemamigration
|
2015-01-31 03:28:47 +00:00
|
|
|
"mjsi" 'pony-south-initial
|
2015-01-30 15:30:10 +00:00
|
|
|
"mjsm" 'pony-south-migrate
|
2015-01-31 03:28:47 +00:00
|
|
|
"mjss" 'pony-syncdb
|
2015-01-30 15:30:10 +00:00
|
|
|
; d*j*ango *t*est
|
|
|
|
"mjtd" 'pony-test-down
|
2015-01-31 03:28:47 +00:00
|
|
|
"mjte" 'pony-test-goto-err
|
|
|
|
"mjto" 'pony-test-open
|
|
|
|
"mjtt" 'pony-test
|
|
|
|
"mjtu" 'pony-test-up))))
|
2015-01-30 15:30:10 +00:00
|
|
|
|
|
|
|
(defun python/init-pyenv-mode ()
|
|
|
|
(use-package pyenv-mode
|
|
|
|
:defer t
|
|
|
|
:init (progn
|
|
|
|
(evil-leader/set-key-for-mode 'python-mode
|
2015-01-31 03:28:47 +00:00
|
|
|
"mvs" 'pyenv-mode-set
|
|
|
|
"mvu" 'pyenv-mode-unset))))
|
2015-01-30 15:30:10 +00:00
|
|
|
|
2014-12-10 16:30:48 +00:00
|
|
|
(defun python/init-pyvenv ()
|
|
|
|
(use-package pyvenv
|
2014-12-09 03:19:55 +00:00
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(evil-leader/set-key-for-mode 'python-mode
|
2015-01-31 03:28:47 +00:00
|
|
|
"mV" 'pyvenv-workon)))
|
2014-12-09 03:19:55 +00:00
|
|
|
|
2014-11-10 04:54:10 +00:00
|
|
|
(defun python/init-python ()
|
|
|
|
(use-package python
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
2014-12-09 03:19:55 +00:00
|
|
|
(defun python-default ()
|
|
|
|
(setq mode-name "Python"
|
|
|
|
tab-width 4
|
|
|
|
;; auto-indent on colon doesn't work well with if statement
|
|
|
|
electric-indent-chars (delq ?: electric-indent-chars))
|
|
|
|
(annotate-pdb)
|
|
|
|
(spacemacs/highlight-TODO-words)
|
|
|
|
;; make C-j work the same way as RET
|
|
|
|
(local-set-key (kbd "C-j") 'newline-and-indent))
|
|
|
|
|
2014-11-10 04:54:10 +00:00
|
|
|
(defun python-setup-shell ()
|
|
|
|
(if (executable-find "ipython")
|
|
|
|
(setq python-shell-interpreter "ipython"
|
|
|
|
;; python-shell-interpreter-args (if (system-is-mac)
|
|
|
|
;; "--gui=osx --matplotlib=osx --colors=Linux"
|
|
|
|
;; (if (system-is-linux)
|
|
|
|
;; "--gui=wx --matplotlib=wx --colors=Linux"))
|
|
|
|
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-module-string-code "';'.join(module_completion('''%s'''))\n"
|
|
|
|
python-shell-completion-string-code "';'.join(get_ipython().Completer.all_completions('''%s'''))\n")
|
|
|
|
(setq python-shell-interpreter "python")))
|
|
|
|
|
2014-12-09 03:19:55 +00:00
|
|
|
(add-all-to-hook 'python-mode-hook
|
|
|
|
'python-default
|
|
|
|
'python-setup-shell))
|
2014-11-10 04:54:10 +00:00
|
|
|
:config
|
|
|
|
(progn
|
|
|
|
;; add support for `ahs-range-beginning-of-defun' for python-mode
|
|
|
|
(eval-after-load 'auto-highlight-symbol
|
|
|
|
'(add-to-list 'ahs-plugin-bod-modes 'python-mode))
|
2014-12-09 03:19:55 +00:00
|
|
|
|
|
|
|
(defun python-shell-send-buffer-switch ()
|
|
|
|
"Send buffer content to shell and switch to it in insert mode."
|
|
|
|
(interactive)
|
|
|
|
(python-shell-send-buffer)
|
|
|
|
(python-shell-switch-to-shell)
|
|
|
|
(evil-insert-state))
|
|
|
|
|
|
|
|
(defun python-shell-send-defun-switch ()
|
|
|
|
"Send function content to shell and switch to it in insert mode."
|
|
|
|
(interactive)
|
|
|
|
(python-shell-send-defun nil)
|
|
|
|
(python-shell-switch-to-shell)
|
|
|
|
(evil-insert-state))
|
|
|
|
|
|
|
|
(defun python-shell-send-region-switch ()
|
|
|
|
"Send region content to shell and switch to it in insert mode."
|
|
|
|
(interactive "r")
|
|
|
|
(python-shell-send-region start end)
|
|
|
|
(python-shell-switch-to-shell)
|
|
|
|
(evil-insert-state))
|
|
|
|
|
|
|
|
(defun python-start-or-switch-repl ()
|
|
|
|
"Start and/or switch to the REPL."
|
|
|
|
(interactive)
|
|
|
|
(python-shell-switch-to-shell)
|
|
|
|
(evil-insert-state))
|
|
|
|
|
2014-11-10 04:54:10 +00:00
|
|
|
(evil-leader/set-key-for-mode 'python-mode
|
2014-12-10 04:37:16 +00:00
|
|
|
"mB" 'python-shell-send-buffer-switch
|
|
|
|
"mb" 'python-shell-send-buffer
|
2015-01-14 15:12:09 +00:00
|
|
|
"mdb" 'python-toggle-breakpoint
|
2014-12-10 04:37:16 +00:00
|
|
|
"mF" 'python-shell-send-defun-switch
|
|
|
|
"mf" 'python-shell-send-defun
|
2014-12-09 03:19:55 +00:00
|
|
|
"mi" 'python-start-or-switch-repl
|
2014-12-10 04:37:16 +00:00
|
|
|
"mR" 'python-shell-send-region-switch
|
|
|
|
"mr" 'python-shell-send-region)
|
2014-11-10 04:54:10 +00:00
|
|
|
|
|
|
|
(define-key inferior-python-mode-map (kbd "C-j") 'comint-next-input)
|
|
|
|
(define-key inferior-python-mode-map (kbd "C-k") 'comint-previous-input))))
|
|
|
|
|
|
|
|
(defun python/init-flycheck ()
|
2014-11-29 06:20:50 +00:00
|
|
|
(add-hook 'python-mode-hook 'flycheck-mode))
|
2014-12-09 17:08:30 +00:00
|
|
|
|
2014-12-14 05:19:20 +00:00
|
|
|
(defun spacemacs/init-hy-mode ()
|
|
|
|
(use-package hy-mode
|
|
|
|
:defer t))
|
|
|
|
|
2014-12-09 17:08:30 +00:00
|
|
|
(defun python/init-semantic ()
|
2014-12-10 04:27:28 +00:00
|
|
|
;; required to correctly load semantic mode
|
|
|
|
;; using the python-mode-hook triggers an error about a deleted buffer.
|
|
|
|
(eval-after-load 'python '(semantic-mode 1)))
|
2014-12-12 03:16:09 +00:00
|
|
|
|
|
|
|
(defun python/init-smartparens ()
|
|
|
|
(defadvice python-indent-dedent-line-backspace
|
|
|
|
(around python/sp-backward-delete-char activate)
|
|
|
|
(let ((pythonp (or (not smartparens-strict-mode)
|
|
|
|
(char-equal (char-before) ?\s))))
|
|
|
|
(if pythonp
|
|
|
|
ad-do-it
|
|
|
|
(call-interactively 'sp-backward-delete-char)))))
|