2015-01-14 04:12:56 +00:00
|
|
|
;;; packages.el --- Python Layer packages File for Spacemacs
|
|
|
|
;;
|
2016-01-12 02:40:54 +00:00
|
|
|
;; Copyright (c) 2012-2016 Sylvain Benner & Contributors
|
2015-01-14 04:12:56 +00:00
|
|
|
;;
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
2015-04-19 03:40:24 +00:00
|
|
|
(setq python-packages
|
2014-11-10 04:54:10 +00:00
|
|
|
'(
|
|
|
|
anaconda-mode
|
2015-04-09 03:57:22 +00:00
|
|
|
company
|
2016-05-30 02:39:21 +00:00
|
|
|
(company-anaconda :toggle (configuration-layer/package-usedp 'company))
|
2015-04-09 03:57:22 +00:00
|
|
|
cython-mode
|
2014-11-10 04:54:10 +00:00
|
|
|
eldoc
|
2015-09-21 00:56:37 +00:00
|
|
|
evil-matchit
|
2014-11-10 04:54:10 +00:00
|
|
|
flycheck
|
2016-04-05 04:08:34 +00:00
|
|
|
ggtags
|
2015-07-24 02:20:25 +00:00
|
|
|
helm-cscope
|
2016-04-05 04:08:34 +00:00
|
|
|
helm-gtags
|
2016-05-30 02:39:21 +00:00
|
|
|
(helm-pydoc :toggle (configuration-layer/package-usedp 'helm))
|
2014-12-14 05:19:20 +00:00
|
|
|
hy-mode
|
2015-10-29 08:42:37 +00:00
|
|
|
live-py-mode
|
2016-04-05 20:41:05 +00:00
|
|
|
(nose :location local)
|
|
|
|
org
|
2015-04-25 03:54:39 +00:00
|
|
|
pip-requirements
|
2015-11-07 08:28:26 +00:00
|
|
|
py-isort
|
2015-01-30 15:30:10 +00:00
|
|
|
pyenv-mode
|
2016-01-18 03:06:04 +00:00
|
|
|
(pylookup :location local)
|
2015-06-08 03:59:23 +00:00
|
|
|
pytest
|
2016-03-26 07:24:35 +00:00
|
|
|
(python :location built-in)
|
2015-06-08 03:59:23 +00:00
|
|
|
pyvenv
|
2014-12-09 17:08:30 +00:00
|
|
|
semantic
|
2014-12-12 03:16:09 +00:00
|
|
|
smartparens
|
2015-04-15 22:57:31 +00:00
|
|
|
stickyfunc-enhance
|
2015-07-24 02:20:25 +00:00
|
|
|
xcscope
|
2016-07-10 20:00:38 +00:00
|
|
|
yapfify
|
2015-04-19 03:40:24 +00:00
|
|
|
))
|
2014-11-10 04:54:10 +00:00
|
|
|
|
2014-12-09 03:19:55 +00:00
|
|
|
(defun python/init-anaconda-mode ()
|
|
|
|
(use-package anaconda-mode
|
|
|
|
:defer t
|
2015-09-22 23:28:53 +00:00
|
|
|
:init
|
|
|
|
(progn
|
2015-09-23 06:58:48 +00:00
|
|
|
(setq anaconda-mode-installation-directory
|
|
|
|
(concat spacemacs-cache-directory "anaconda-mode"))
|
2016-08-13 13:43:37 +00:00
|
|
|
(add-hook 'python-mode-hook 'anaconda-mode)
|
2016-09-04 16:24:43 +00:00
|
|
|
(add-to-list 'spacemacs-jump-handlers-python-mode
|
2016-09-01 17:30:37 +00:00
|
|
|
'(anaconda-mode-find-definitions :async t)))
|
2014-12-09 03:19:55 +00:00
|
|
|
:config
|
|
|
|
(progn
|
2015-11-18 00:38:05 +00:00
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'python-mode
|
2015-11-22 17:45:12 +00:00
|
|
|
"hh" 'anaconda-mode-show-doc
|
|
|
|
"ga" 'anaconda-mode-find-assignments
|
2015-11-25 09:21:44 +00:00
|
|
|
"gb" 'anaconda-mode-go-back
|
2015-11-22 17:45:12 +00:00
|
|
|
"gu" 'anaconda-mode-find-references)
|
2015-11-21 10:07:14 +00:00
|
|
|
(evilified-state-evilify anaconda-mode-view-mode anaconda-mode-view-mode-map
|
|
|
|
(kbd "q") 'quit-window)
|
2016-02-15 19:15:29 +00:00
|
|
|
(spacemacs|hide-lighter anaconda-mode)
|
|
|
|
|
|
|
|
(defadvice anaconda-mode-goto (before python/anaconda-mode-goto activate)
|
2016-02-17 14:46:51 +00:00
|
|
|
(evil--jumps-push)))))
|
2014-12-09 03:19:55 +00:00
|
|
|
|
2016-05-30 02:39:21 +00:00
|
|
|
(defun python/post-init-company ()
|
|
|
|
(spacemacs|add-company-hook python-mode)
|
|
|
|
(spacemacs|add-company-hook inferior-python-mode)
|
|
|
|
(push '(company-files company-capf) company-backends-inferior-python-mode)
|
|
|
|
(add-hook 'inferior-python-mode-hook (lambda ()
|
|
|
|
(setq-local company-minimum-prefix-length 0)
|
|
|
|
(setq-local company-idle-delay 0.5))))
|
2016-01-18 03:06:04 +00:00
|
|
|
|
2016-05-30 02:39:21 +00:00
|
|
|
(defun python/init-company-anaconda ()
|
|
|
|
(use-package company-anaconda
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(push 'company-anaconda company-backends-python-mode)))
|
2016-01-18 03:06:04 +00:00
|
|
|
|
2015-01-22 16:22:19 +00:00
|
|
|
(defun python/init-cython-mode ()
|
|
|
|
(use-package cython-mode
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
2015-11-18 00:38:05 +00:00
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'cython-mode
|
|
|
|
"hh" 'anaconda-mode-view-doc
|
|
|
|
"gu" 'anaconda-mode-usages))))
|
2015-01-22 16:22:19 +00:00
|
|
|
|
2015-08-09 03:35:16 +00:00
|
|
|
(defun python/post-init-eldoc ()
|
2016-02-16 15:27:11 +00:00
|
|
|
(defun spacemacs//init-eldoc-python-mode ()
|
|
|
|
(eldoc-mode)
|
|
|
|
(when (configuration-layer/package-usedp 'anaconda-mode)
|
|
|
|
(anaconda-eldoc-mode)))
|
|
|
|
(add-hook 'python-mode-hook 'spacemacs//init-eldoc-python-mode))
|
2014-12-09 03:19:55 +00:00
|
|
|
|
2016-01-18 03:06:04 +00:00
|
|
|
(defun python/post-init-evil-matchit ()
|
|
|
|
(add-hook `python-mode-hook `turn-on-evil-matchit-mode))
|
|
|
|
|
|
|
|
(defun python/post-init-flycheck ()
|
2016-01-27 20:08:25 +00:00
|
|
|
(spacemacs/add-flycheck-hook 'python-mode))
|
2016-01-18 03:06:04 +00:00
|
|
|
|
2016-05-30 02:39:21 +00:00
|
|
|
(defun python/pre-init-helm-cscope ()
|
|
|
|
(spacemacs|use-package-add-hook xcscope
|
|
|
|
:post-init
|
|
|
|
(spacemacs/setup-helm-cscope 'python-mode)))
|
2016-01-18 03:06:04 +00:00
|
|
|
|
2016-04-05 04:08:34 +00:00
|
|
|
(defun python/post-init-helm-gtags ()
|
|
|
|
(spacemacs/helm-gtags-define-keys-for-mode 'python-mode))
|
|
|
|
|
|
|
|
(defun python/post-init-ggtags ()
|
2016-08-15 19:24:44 +00:00
|
|
|
(add-hook 'python-mode-local-vars-hook #'spacemacs/ggtags-mode-enable))
|
2016-04-05 04:08:34 +00:00
|
|
|
|
2016-05-30 02:39:21 +00:00
|
|
|
(defun python/init-helm-pydoc ()
|
|
|
|
(use-package helm-pydoc
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'python-mode "hd" 'helm-pydoc)))
|
2016-01-18 03:06:04 +00:00
|
|
|
|
|
|
|
(defun python/init-hy-mode ()
|
|
|
|
(use-package hy-mode
|
2016-06-17 23:40:49 +00:00
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(let ((hy-path (executable-find "hy")))
|
|
|
|
(when hy-path
|
|
|
|
(setq hy-mode-inferior-lisp-command (concat hy-path " --spy"))
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'hy-mode
|
|
|
|
"si" 'inferior-lisp
|
|
|
|
"sb" 'lisp-load-file
|
|
|
|
"sB" 'switch-to-lisp
|
|
|
|
"se" 'lisp-eval-last-sexp
|
|
|
|
"sf" 'lisp-eval-defun
|
|
|
|
"sF" 'lisp-eval-defun-and-go
|
|
|
|
"sr" 'lisp-eval-region
|
2016-07-05 04:07:54 +00:00
|
|
|
"sR" 'lisp-eval-region-and-go))))))
|
2016-01-18 03:06:04 +00:00
|
|
|
|
2015-10-29 08:42:37 +00:00
|
|
|
(defun python/init-live-py-mode ()
|
|
|
|
(use-package live-py-mode
|
|
|
|
:defer t
|
|
|
|
:commands live-py-mode
|
|
|
|
:init
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'python-mode
|
2016-01-31 20:47:32 +00:00
|
|
|
"l" 'live-py-mode)))
|
2015-10-29 08:42:37 +00:00
|
|
|
|
2016-01-18 03:06:04 +00:00
|
|
|
(defun python/init-nose ()
|
|
|
|
(use-package nose
|
|
|
|
:commands (nosetests-one
|
|
|
|
nosetests-pdb-one
|
|
|
|
nosetests-all
|
|
|
|
nosetests-pdb-all
|
|
|
|
nosetests-module
|
|
|
|
nosetests-pdb-module
|
|
|
|
nosetests-suite
|
|
|
|
nosetests-pdb-suite)
|
2016-10-20 11:18:05 +00:00
|
|
|
:init (spacemacs//bind-python-testing-keys)
|
2016-01-18 03:06:04 +00:00
|
|
|
:config
|
|
|
|
(progn
|
|
|
|
(add-to-list 'nose-project-root-files "setup.cfg")
|
|
|
|
(setq nose-use-verbose nil))))
|
|
|
|
|
2016-04-05 20:41:05 +00:00
|
|
|
(defun python/pre-init-org ()
|
|
|
|
(spacemacs|use-package-add-hook org
|
|
|
|
:post-config (add-to-list 'org-babel-load-languages '(python . t))))
|
|
|
|
|
2015-04-25 03:54:39 +00:00
|
|
|
(defun python/init-pip-requirements ()
|
|
|
|
(use-package pip-requirements
|
2015-04-25 05:37:18 +00:00
|
|
|
:defer t
|
2015-04-25 03:54:39 +00:00
|
|
|
:init
|
2015-04-25 05:37:18 +00:00
|
|
|
(progn
|
|
|
|
;; company support
|
2015-04-30 03:54:30 +00:00
|
|
|
(push 'company-capf company-backends-pip-requirements-mode)
|
2015-04-25 03:54:39 +00:00
|
|
|
(spacemacs|add-company-hook pip-requirements-mode))))
|
|
|
|
|
2015-11-07 08:28:26 +00:00
|
|
|
(defun python/init-py-isort ()
|
|
|
|
(use-package py-isort
|
|
|
|
:defer t
|
2016-08-21 15:49:20 +00:00
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(add-hook 'before-save-hook 'spacemacs//python-sort-imports)
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'python-mode
|
|
|
|
"rI" 'py-isort-buffer))))
|
2015-11-07 08:28:26 +00:00
|
|
|
|
2015-01-30 15:30:10 +00:00
|
|
|
(defun python/init-pyenv-mode ()
|
|
|
|
(use-package pyenv-mode
|
2016-01-24 13:42:59 +00:00
|
|
|
:if (executable-find "pyenv")
|
2015-12-07 12:58:36 +00:00
|
|
|
:commands (pyenv-mode-versions)
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(pcase python-auto-set-local-pyenv-version
|
|
|
|
(`on-visit
|
2016-07-05 04:07:54 +00:00
|
|
|
(spacemacs/add-to-hooks 'spacemacs//pyenv-mode-set-local-version
|
|
|
|
'(python-mode-hook
|
|
|
|
hy-mode-hook)))
|
2015-12-07 12:58:36 +00:00
|
|
|
(`on-project-switch
|
2016-06-06 01:53:14 +00:00
|
|
|
(add-hook 'projectile-after-switch-project-hook
|
|
|
|
'spacemacs//pyenv-mode-set-local-version)))
|
2016-07-18 19:40:40 +00:00
|
|
|
;; setup shell correctly on environment switch
|
|
|
|
(dolist (func '(pyenv-mode-set pyenv-mode-unset))
|
|
|
|
(advice-add func :after 'spacemacs/python-setup-shell))
|
2015-12-07 12:58:36 +00:00
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'python-mode
|
2016-01-09 03:37:35 +00:00
|
|
|
"vu" 'pyenv-mode-unset
|
|
|
|
"vs" 'pyenv-mode-set))))
|
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
|
2016-06-17 23:40:49 +00:00
|
|
|
(progn
|
2016-10-25 17:25:57 +00:00
|
|
|
(pcase python-auto-set-local-pyvenv-virtualenv
|
|
|
|
(`on-visit
|
|
|
|
(spacemacs/add-to-hooks 'spacemacs//pyvenv-mode-set-local-virtualenv
|
|
|
|
'(python-mode-hook
|
|
|
|
hy-mode-hook)))
|
|
|
|
(`on-project-switch
|
|
|
|
(add-hook 'projectile-after-switch-project-hook
|
|
|
|
'spacemacs//pyvenv-mode-set-local-virtualenv)))
|
2016-07-05 04:07:54 +00:00
|
|
|
(dolist (mode '(python-mode hy-mode))
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode mode
|
|
|
|
"Va" 'pyvenv-activate
|
|
|
|
"Vd" 'pyvenv-deactivate
|
2016-07-18 19:40:40 +00:00
|
|
|
"Vw" 'pyvenv-workon))
|
|
|
|
;; setup shell correctly on environment switch
|
|
|
|
(dolist (func '(pyvenv-activate pyvenv-deactivate pyvenv-workon))
|
|
|
|
(advice-add func :after 'spacemacs/python-setup-shell)))))
|
2014-12-09 03:19:55 +00:00
|
|
|
|
2016-01-18 03:06:04 +00:00
|
|
|
(defun python/init-pylookup ()
|
|
|
|
(use-package pylookup
|
|
|
|
:commands (pylookup-lookup pylookup-update pylookup-update-all)
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(evilified-state-evilify pylookup-mode pylookup-mode-map)
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'python-mode
|
2016-02-25 05:17:48 +00:00
|
|
|
"hH" 'pylookup-lookup))
|
2016-01-18 03:06:04 +00:00
|
|
|
:config
|
|
|
|
(progn
|
|
|
|
(let ((dir (configuration-layer/get-layer-local-dir 'python)))
|
|
|
|
(setq pylookup-dir (concat dir "pylookup/")
|
|
|
|
pylookup-program (concat pylookup-dir "pylookup.py")
|
2016-03-01 06:34:34 +00:00
|
|
|
pylookup-db-file (concat pylookup-dir "pylookup.db")))
|
|
|
|
(setq pylookup-completing-read 'completing-read))))
|
2016-01-18 03:06:04 +00:00
|
|
|
|
2015-06-04 09:09:56 +00:00
|
|
|
(defun python/init-pytest ()
|
|
|
|
(use-package pytest
|
|
|
|
:commands (pytest-one
|
|
|
|
pytest-pdb-one
|
|
|
|
pytest-all
|
|
|
|
pytest-pdb-all
|
|
|
|
pytest-module
|
|
|
|
pytest-pdb-module)
|
2016-06-06 01:53:14 +00:00
|
|
|
:init (spacemacs//bind-python-testing-keys)
|
2015-06-08 03:59:23 +00:00
|
|
|
:config (add-to-list 'pytest-project-root-files "setup.cfg")))
|
2015-06-04 09:09:56 +00:00
|
|
|
|
2014-11-10 04:54:10 +00:00
|
|
|
(defun python/init-python ()
|
|
|
|
(use-package python
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
2016-01-26 16:31:15 +00:00
|
|
|
(spacemacs/register-repl 'python 'python-start-or-switch-repl "python")
|
|
|
|
|
2014-12-09 03:19:55 +00:00
|
|
|
(defun python-default ()
|
|
|
|
(setq mode-name "Python"
|
2016-10-11 18:01:01 +00:00
|
|
|
tab-width python-tab-width
|
2015-11-03 13:05:12 +00:00
|
|
|
fill-column python-fill-column)
|
|
|
|
(when (version< emacs-version "24.5")
|
|
|
|
;; auto-indent on colon doesn't work well with if statement
|
|
|
|
;; should be fixed in 24.5 and above
|
|
|
|
(setq electric-indent-chars (delq ?: electric-indent-chars)))
|
2016-04-08 09:42:19 +00:00
|
|
|
(setq-local comment-inline-offset 2)
|
2016-06-06 01:53:14 +00:00
|
|
|
(spacemacs/python-annotate-pdb)
|
2014-12-09 03:19:55 +00:00
|
|
|
;; 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
|
|
|
|
2015-06-02 11:21:34 +00:00
|
|
|
(defun inferior-python-setup-hook ()
|
|
|
|
(setq indent-tabs-mode t))
|
|
|
|
|
|
|
|
(add-hook 'inferior-python-mode-hook #'inferior-python-setup-hook)
|
2016-05-06 07:05:57 +00:00
|
|
|
(add-hook 'python-mode-hook #'python-default)
|
2016-07-18 19:40:40 +00:00
|
|
|
;; call `spacemacs/python-setup-shell' once, don't put it in a hook (see issue #5988)
|
|
|
|
(spacemacs/python-setup-shell))
|
2014-11-10 04:54:10 +00:00
|
|
|
:config
|
|
|
|
(progn
|
|
|
|
;; add support for `ahs-range-beginning-of-defun' for python-mode
|
2015-09-29 05:07:57 +00:00
|
|
|
(with-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)
|
Use evil in holy-mode
Motivation
While disabling Evil in holy-mode makes its implementation shorter and
sounds elegant on the paper, in practice it puts a big burden on the
configuration parts which need to know if Evil is enable or not. This is
a bad separation of concerns and the bunch of fixes that we were forced
to do in the past weeks shows this issue. Those fixes were about
removing the knowledge of the activation of Evil by implementing new
dispatching functions to be used by layers, this is cumbersome and makes
Spacemacs layer configuration more subtle which is not good. There was
additional bad consequences of the removal of Evil state like the
impossibility to use Evil lisp state or iedit states, or we would have
been forced to implement a temporary activation of Evil which is
awkward.
Instead I reintroduce Evil as the central piece of Spacemacs design thus
Evil is now re-enabled in holy-mode. It provides the abstraction we need
to isolate editing styles and be able to grow the Spacemacs
configuration coverage sanely. Layers don't need to check whether the
holy mode is active or not and they don't need to know if Evil is
available (it is always available). We also don't need to write
additional dispatching functions, this is the job of Evil, and I think
it provides everything for this. Ideally configuration layer should be
implemented with only Evil in mind and the holy-mode (and hybrid-mode)
should magically make it work for Emacs style users, for instance we can
freely use `evil-insert-state` anywhere in the code without any guard.
Evil is now even more part of Spacemacs, we can really say that
Spacemacs is Emacs+Evil which is now an indivisible pair. Spacemacs
needed this stable API to continue on the right track.
While these changes should be rather transparent to the user, I'm sorry
for this experimental period, I failed to see all the implications of
such a change, I was just excited about the possibility to make Evil
optional. The reality is that Spacemacs has to embrace it and keep its
strong position on being Emacs+Evil at the core.
Implementation
- insert, motion and normal states are forced to emacs state using an
advice on `evil-insert-state`, `evil-motion-state` and
`evil-normal-state` respectively. These functions can be used freely in
the layer configuration.
- A new general hook `spacemacs-editing-style-hook` allow to hook any
code that need to be configured based on the editing style. Functions
hooked to this hook takes the current style as parameter, this
basically generalize the hook used to setup hjkl navigation bindings.
- ESC has been removed from the emacs state map.
- Revert unneeded changes
- Revert "evil: enter insert-state only from normal-state"
commit bdd702dfbe302206bbc989c7a0832daba087a781.
- Revert "avoid being evil in deft with emacs editing style"
commit f3a16f49ed27cc8cf05f23f93b006d6e04235381.
Additional changes
All editing style packages have been moved to a layer called
`spacemacs-editing-styles`
Notes
I did not have time to attack hybrid mode, I should be able to do it
later.
2016-03-13 23:41:18 +00:00
|
|
|
(evil-insert-state))
|
2014-12-09 03:19:55 +00:00
|
|
|
|
|
|
|
(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)
|
Use evil in holy-mode
Motivation
While disabling Evil in holy-mode makes its implementation shorter and
sounds elegant on the paper, in practice it puts a big burden on the
configuration parts which need to know if Evil is enable or not. This is
a bad separation of concerns and the bunch of fixes that we were forced
to do in the past weeks shows this issue. Those fixes were about
removing the knowledge of the activation of Evil by implementing new
dispatching functions to be used by layers, this is cumbersome and makes
Spacemacs layer configuration more subtle which is not good. There was
additional bad consequences of the removal of Evil state like the
impossibility to use Evil lisp state or iedit states, or we would have
been forced to implement a temporary activation of Evil which is
awkward.
Instead I reintroduce Evil as the central piece of Spacemacs design thus
Evil is now re-enabled in holy-mode. It provides the abstraction we need
to isolate editing styles and be able to grow the Spacemacs
configuration coverage sanely. Layers don't need to check whether the
holy mode is active or not and they don't need to know if Evil is
available (it is always available). We also don't need to write
additional dispatching functions, this is the job of Evil, and I think
it provides everything for this. Ideally configuration layer should be
implemented with only Evil in mind and the holy-mode (and hybrid-mode)
should magically make it work for Emacs style users, for instance we can
freely use `evil-insert-state` anywhere in the code without any guard.
Evil is now even more part of Spacemacs, we can really say that
Spacemacs is Emacs+Evil which is now an indivisible pair. Spacemacs
needed this stable API to continue on the right track.
While these changes should be rather transparent to the user, I'm sorry
for this experimental period, I failed to see all the implications of
such a change, I was just excited about the possibility to make Evil
optional. The reality is that Spacemacs has to embrace it and keep its
strong position on being Emacs+Evil at the core.
Implementation
- insert, motion and normal states are forced to emacs state using an
advice on `evil-insert-state`, `evil-motion-state` and
`evil-normal-state` respectively. These functions can be used freely in
the layer configuration.
- A new general hook `spacemacs-editing-style-hook` allow to hook any
code that need to be configured based on the editing style. Functions
hooked to this hook takes the current style as parameter, this
basically generalize the hook used to setup hjkl navigation bindings.
- ESC has been removed from the emacs state map.
- Revert unneeded changes
- Revert "evil: enter insert-state only from normal-state"
commit bdd702dfbe302206bbc989c7a0832daba087a781.
- Revert "avoid being evil in deft with emacs editing style"
commit f3a16f49ed27cc8cf05f23f93b006d6e04235381.
Additional changes
All editing style packages have been moved to a layer called
`spacemacs-editing-styles`
Notes
I did not have time to attack hybrid mode, I should be able to do it
later.
2016-03-13 23:41:18 +00:00
|
|
|
(evil-insert-state))
|
2014-12-09 03:19:55 +00:00
|
|
|
|
2015-02-18 03:00:26 +00:00
|
|
|
(defun python-shell-send-region-switch (start end)
|
2014-12-09 03:19:55 +00:00
|
|
|
"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)
|
Use evil in holy-mode
Motivation
While disabling Evil in holy-mode makes its implementation shorter and
sounds elegant on the paper, in practice it puts a big burden on the
configuration parts which need to know if Evil is enable or not. This is
a bad separation of concerns and the bunch of fixes that we were forced
to do in the past weeks shows this issue. Those fixes were about
removing the knowledge of the activation of Evil by implementing new
dispatching functions to be used by layers, this is cumbersome and makes
Spacemacs layer configuration more subtle which is not good. There was
additional bad consequences of the removal of Evil state like the
impossibility to use Evil lisp state or iedit states, or we would have
been forced to implement a temporary activation of Evil which is
awkward.
Instead I reintroduce Evil as the central piece of Spacemacs design thus
Evil is now re-enabled in holy-mode. It provides the abstraction we need
to isolate editing styles and be able to grow the Spacemacs
configuration coverage sanely. Layers don't need to check whether the
holy mode is active or not and they don't need to know if Evil is
available (it is always available). We also don't need to write
additional dispatching functions, this is the job of Evil, and I think
it provides everything for this. Ideally configuration layer should be
implemented with only Evil in mind and the holy-mode (and hybrid-mode)
should magically make it work for Emacs style users, for instance we can
freely use `evil-insert-state` anywhere in the code without any guard.
Evil is now even more part of Spacemacs, we can really say that
Spacemacs is Emacs+Evil which is now an indivisible pair. Spacemacs
needed this stable API to continue on the right track.
While these changes should be rather transparent to the user, I'm sorry
for this experimental period, I failed to see all the implications of
such a change, I was just excited about the possibility to make Evil
optional. The reality is that Spacemacs has to embrace it and keep its
strong position on being Emacs+Evil at the core.
Implementation
- insert, motion and normal states are forced to emacs state using an
advice on `evil-insert-state`, `evil-motion-state` and
`evil-normal-state` respectively. These functions can be used freely in
the layer configuration.
- A new general hook `spacemacs-editing-style-hook` allow to hook any
code that need to be configured based on the editing style. Functions
hooked to this hook takes the current style as parameter, this
basically generalize the hook used to setup hjkl navigation bindings.
- ESC has been removed from the emacs state map.
- Revert unneeded changes
- Revert "evil: enter insert-state only from normal-state"
commit bdd702dfbe302206bbc989c7a0832daba087a781.
- Revert "avoid being evil in deft with emacs editing style"
commit f3a16f49ed27cc8cf05f23f93b006d6e04235381.
Additional changes
All editing style packages have been moved to a layer called
`spacemacs-editing-styles`
Notes
I did not have time to attack hybrid mode, I should be able to do it
later.
2016-03-13 23:41:18 +00:00
|
|
|
(evil-insert-state))
|
2014-12-09 03:19:55 +00:00
|
|
|
|
|
|
|
(defun python-start-or-switch-repl ()
|
|
|
|
"Start and/or switch to the REPL."
|
|
|
|
(interactive)
|
2016-09-09 18:06:23 +00:00
|
|
|
(let ((shell-process
|
|
|
|
(or (python-shell-get-process)
|
|
|
|
;; `run-python' has different return values and different
|
|
|
|
;; errors in different emacs versions. In 24.4, it throws an
|
|
|
|
;; error when the process didn't start, but in 25.1 it
|
|
|
|
;; doesn't throw an error, so we demote errors here and
|
|
|
|
;; check the process later
|
|
|
|
(with-demoted-errors "Error: %S"
|
|
|
|
;; in Emacs 24.5 and 24.4, `run-python' doesn't return the
|
|
|
|
;; shell process
|
|
|
|
(call-interactively #'run-python)
|
|
|
|
(python-shell-get-process)))))
|
|
|
|
(unless shell-process
|
|
|
|
(error "Failed to start python shell properly"))
|
|
|
|
(pop-to-buffer (process-buffer shell-process))
|
|
|
|
(evil-insert-state)))
|
2014-12-09 03:19:55 +00:00
|
|
|
|
2015-03-14 06:58:11 +00:00
|
|
|
(defun spacemacs/python-execute-file (arg)
|
|
|
|
"Execute a python script in a shell."
|
|
|
|
(interactive "P")
|
|
|
|
;; set compile command to buffer-file-name
|
|
|
|
;; universal argument put compile buffer in comint mode
|
2016-10-11 10:53:41 +00:00
|
|
|
(let ((universal-argument t)
|
|
|
|
(compile-command (format "python %s" (file-name-nondirectory
|
|
|
|
buffer-file-name))))
|
|
|
|
(if arg
|
|
|
|
(call-interactively 'compile)
|
|
|
|
(compile compile-command t)
|
|
|
|
(with-current-buffer (get-buffer "*compilation*")
|
|
|
|
(inferior-python-mode)))))
|
2015-03-14 06:58:11 +00:00
|
|
|
|
|
|
|
(defun spacemacs/python-execute-file-focus (arg)
|
|
|
|
"Execute a python script in a shell and switch to the shell buffer in
|
|
|
|
`insert state'."
|
|
|
|
(interactive "P")
|
|
|
|
(spacemacs/python-execute-file arg)
|
|
|
|
(switch-to-buffer-other-window "*compilation*")
|
2015-03-14 09:41:54 +00:00
|
|
|
(end-of-buffer)
|
Use evil in holy-mode
Motivation
While disabling Evil in holy-mode makes its implementation shorter and
sounds elegant on the paper, in practice it puts a big burden on the
configuration parts which need to know if Evil is enable or not. This is
a bad separation of concerns and the bunch of fixes that we were forced
to do in the past weeks shows this issue. Those fixes were about
removing the knowledge of the activation of Evil by implementing new
dispatching functions to be used by layers, this is cumbersome and makes
Spacemacs layer configuration more subtle which is not good. There was
additional bad consequences of the removal of Evil state like the
impossibility to use Evil lisp state or iedit states, or we would have
been forced to implement a temporary activation of Evil which is
awkward.
Instead I reintroduce Evil as the central piece of Spacemacs design thus
Evil is now re-enabled in holy-mode. It provides the abstraction we need
to isolate editing styles and be able to grow the Spacemacs
configuration coverage sanely. Layers don't need to check whether the
holy mode is active or not and they don't need to know if Evil is
available (it is always available). We also don't need to write
additional dispatching functions, this is the job of Evil, and I think
it provides everything for this. Ideally configuration layer should be
implemented with only Evil in mind and the holy-mode (and hybrid-mode)
should magically make it work for Emacs style users, for instance we can
freely use `evil-insert-state` anywhere in the code without any guard.
Evil is now even more part of Spacemacs, we can really say that
Spacemacs is Emacs+Evil which is now an indivisible pair. Spacemacs
needed this stable API to continue on the right track.
While these changes should be rather transparent to the user, I'm sorry
for this experimental period, I failed to see all the implications of
such a change, I was just excited about the possibility to make Evil
optional. The reality is that Spacemacs has to embrace it and keep its
strong position on being Emacs+Evil at the core.
Implementation
- insert, motion and normal states are forced to emacs state using an
advice on `evil-insert-state`, `evil-motion-state` and
`evil-normal-state` respectively. These functions can be used freely in
the layer configuration.
- A new general hook `spacemacs-editing-style-hook` allow to hook any
code that need to be configured based on the editing style. Functions
hooked to this hook takes the current style as parameter, this
basically generalize the hook used to setup hjkl navigation bindings.
- ESC has been removed from the emacs state map.
- Revert unneeded changes
- Revert "evil: enter insert-state only from normal-state"
commit bdd702dfbe302206bbc989c7a0832daba087a781.
- Revert "avoid being evil in deft with emacs editing style"
commit f3a16f49ed27cc8cf05f23f93b006d6e04235381.
Additional changes
All editing style packages have been moved to a layer called
`spacemacs-editing-styles`
Notes
I did not have time to attack hybrid mode, I should be able to do it
later.
2016-03-13 23:41:18 +00:00
|
|
|
(evil-insert-state))
|
2015-03-14 06:58:11 +00:00
|
|
|
|
2016-10-15 08:34:11 +00:00
|
|
|
;; fix for issue #2569 (https://github.com/syl20bnr/spacemacs/issues/2569)
|
|
|
|
(when (version< emacs-version "25")
|
|
|
|
(advice-add 'wisent-python-default-setup :after
|
|
|
|
#'spacemacs//python-imenu-create-index-use-semantic-maybe))
|
|
|
|
|
2015-10-26 19:45:28 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'python-mode "mc" "execute")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'python-mode "md" "debug")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'python-mode "mh" "help")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'python-mode "mg" "goto")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'python-mode "ms" "send to REPL")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'python-mode "mr" "refactor")
|
2016-01-06 19:48:18 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'python-mode "mv" "pyenv")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'python-mode "mV" "pyvenv")
|
2015-11-18 00:38:05 +00:00
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'python-mode
|
2016-01-26 16:31:15 +00:00
|
|
|
"'" 'python-start-or-switch-repl
|
2015-11-18 00:38:05 +00:00
|
|
|
"cc" 'spacemacs/python-execute-file
|
|
|
|
"cC" 'spacemacs/python-execute-file-focus
|
2016-06-06 01:53:14 +00:00
|
|
|
"db" 'spacemacs/python-toggle-breakpoint
|
|
|
|
"ri" 'spacemacs/python-remove-unused-imports
|
2015-11-18 00:38:05 +00:00
|
|
|
"sB" 'python-shell-send-buffer-switch
|
|
|
|
"sb" 'python-shell-send-buffer
|
|
|
|
"sF" 'python-shell-send-defun-switch
|
|
|
|
"sf" 'python-shell-send-defun
|
|
|
|
"si" 'python-start-or-switch-repl
|
|
|
|
"sR" 'python-shell-send-region-switch
|
|
|
|
"sr" 'python-shell-send-region)
|
2014-11-10 04:54:10 +00:00
|
|
|
|
2015-05-23 17:19:48 +00:00
|
|
|
;; Emacs users won't need these key bindings
|
2015-05-28 03:49:19 +00:00
|
|
|
;; TODO: make these key bindings dynamic given the current style
|
|
|
|
;; Doing it only at init time won't update it if the user switches style
|
|
|
|
;; Also find a way to generalize these bindings.
|
2015-05-23 17:19:48 +00:00
|
|
|
(when (eq dotspacemacs-editing-style 'vim)
|
|
|
|
;; the default in Emacs is M-n
|
|
|
|
(define-key inferior-python-mode-map (kbd "C-j") 'comint-next-input)
|
2016-04-03 04:35:52 +00:00
|
|
|
;; the default in Emacs is M-p and this key binding overrides
|
|
|
|
;; default C-k which prevents Emacs users to kill line
|
2015-05-23 17:19:48 +00:00
|
|
|
(define-key inferior-python-mode-map (kbd "C-k") 'comint-previous-input)
|
|
|
|
;; the default in Emacs is M-r; C-r to search backward old output
|
|
|
|
;; and should not be changed
|
2016-04-03 04:35:52 +00:00
|
|
|
(define-key inferior-python-mode-map
|
|
|
|
(kbd "C-r") 'comint-history-isearch-backward)
|
2015-05-23 17:19:48 +00:00
|
|
|
;; this key binding is for recentering buffer in Emacs
|
|
|
|
;; it would be troublesome if Emacs user
|
|
|
|
;; Vim users can use this key since they have other key
|
2016-04-03 04:35:52 +00:00
|
|
|
(define-key inferior-python-mode-map
|
|
|
|
(kbd "C-l") 'spacemacs/comint-clear-buffer))
|
2015-05-23 17:19:48 +00:00
|
|
|
|
|
|
|
;; add this optional key binding for Emacs user, since it is unbound
|
2016-04-03 04:35:52 +00:00
|
|
|
(define-key inferior-python-mode-map
|
2016-04-16 02:08:35 +00:00
|
|
|
(kbd "C-c M-l") 'spacemacs/comint-clear-buffer))))
|
2014-11-10 04:54:10 +00:00
|
|
|
|
2015-04-23 14:35:04 +00:00
|
|
|
(defun python/post-init-semantic ()
|
2016-04-18 18:45:40 +00:00
|
|
|
(when (configuration-layer/package-usedp 'anaconda-mode)
|
|
|
|
(add-hook 'python-mode-hook
|
|
|
|
'spacemacs//disable-semantic-idle-summary-mode t))
|
2016-07-05 04:07:54 +00:00
|
|
|
(spacemacs/add-to-hook 'python-mode-hook
|
|
|
|
'(semantic-mode
|
2016-10-15 08:34:11 +00:00
|
|
|
spacemacs//python-imenu-create-index-use-semantic-maybe))
|
2016-04-03 04:35:52 +00:00
|
|
|
(defadvice semantic-python-get-system-include-path
|
|
|
|
(around semantic-python-skip-error-advice activate)
|
2015-05-21 14:18:02 +00:00
|
|
|
"Don't cause error when Semantic cannot retrieve include
|
|
|
|
paths for Python then prevent the buffer to be switched. This
|
|
|
|
issue might be fixed in Emacs 25. Until then, we need it here to
|
|
|
|
fix this issue."
|
2016-02-24 15:32:45 +00:00
|
|
|
(condition-case-unless-debug nil
|
2015-05-21 14:18:02 +00:00
|
|
|
ad-do-it
|
|
|
|
(error nil))))
|
2015-04-23 14:35:04 +00:00
|
|
|
|
2016-01-18 03:06:04 +00:00
|
|
|
(defun python/post-init-smartparens ()
|
2016-07-05 04:07:54 +00:00
|
|
|
(spacemacs/add-to-hooks 'smartparens-mode '(inferior-python-mode-hook
|
|
|
|
hy-mode-hook))
|
2016-01-18 03:06:04 +00:00
|
|
|
(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)))))
|
|
|
|
|
2015-04-16 10:43:10 +00:00
|
|
|
(defun python/post-init-stickyfunc-enhance ()
|
|
|
|
(add-hook 'python-mode-hook 'spacemacs/lazy-load-stickyfunc-enhance))
|
2015-07-24 02:20:25 +00:00
|
|
|
|
|
|
|
(defun python/pre-init-xcscope ()
|
|
|
|
(spacemacs|use-package-add-hook xcscope
|
|
|
|
:post-init
|
2016-07-05 04:07:54 +00:00
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'python-mode
|
|
|
|
"gi" 'cscope/run-pycscope)))
|
2016-08-07 14:33:12 +00:00
|
|
|
|
|
|
|
(defun python/init-yapfify ()
|
|
|
|
(use-package yapfify
|
|
|
|
:defer t
|
|
|
|
:init (spacemacs/set-leader-keys-for-major-mode 'python-mode
|
|
|
|
"=" 'yapfify-buffer)
|
|
|
|
:config (when python-enable-yapf-format-on-save
|
|
|
|
(add-hook 'python-mode-hook 'yapf-mode))))
|