|
;;; package --- Emacs configuration for Python developement |
|
;;; Commentary: |
|
|
|
;;; Code: |
|
|
|
;; Disable a couple of menus and startup message |
|
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1)) |
|
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1)) |
|
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1)) |
|
(setq inhibit-startup-message t) |
|
|
|
(require 'package) |
|
|
|
(add-to-list 'package-archives |
|
'("marmalade" . "http://marmalade-repo.org/packages/") t) |
|
(add-to-list 'package-archives |
|
'("melpa" . "http://melpa.milkbox.net/packages/") t) |
|
(package-initialize) |
|
|
|
(when (not package-archive-contents) |
|
(package-refresh-contents)) |
|
|
|
;; Add in your own as you wish: |
|
(defvar my-packages '(ack-and-a-half |
|
ample-zen-theme |
|
auto-complete |
|
flymake |
|
flymake-cursor |
|
flymake-python-pyflakes |
|
git-gutter |
|
jedi |
|
magit |
|
projectile |
|
pyflakes |
|
pylint |
|
pymacs |
|
rainbow-delimiters |
|
smartparens |
|
starter-kit |
|
starter-kit-bindings |
|
starter-kit-lisp |
|
virtualenv |
|
whitespace-cleanup-mode) |
|
"A list of packages to ensure are installed at launch.") |
|
|
|
(dolist (p my-packages) |
|
(when (not (package-installed-p p)) |
|
(package-install p))) |
|
|
|
;; Theme selection |
|
(load-theme 'ample-zen t) |
|
|
|
;; setup flymake |
|
(require 'flymake-python-pyflakes) |
|
(require 'flymake-cursor) |
|
(setq flymake-python-pyflakes-executable "flake8") |
|
|
|
;; Handles whitespace, tabs, etc |
|
(setq-default show-trailing-whitespace t) |
|
|
|
;; Projectile for git management |
|
(projectile-global-mode) |
|
(defalias 'ack 'ack-and-a-half) |
|
;; Enable git-gutter |
|
(global-git-gutter-mode t) |
|
|
|
|
|
;; auto-complete |
|
(autoload 'ac-config-default "auto-complete-config") |
|
(ac-config-default) |
|
|
|
(eval-after-load "auto-complete" |
|
'(add-to-list 'ac-modes `python-mode)) |
|
|
|
;; ;; Jedi settings |
|
(require 'jedi) |
|
;; Make sure to run pip install jedi epc |
|
|
|
(add-hook 'python-mode-hook |
|
(lambda () |
|
(jedi:setup) |
|
(jedi:ac-setup) |
|
(local-set-key "\C-cd" 'jedi:show-doc) |
|
(local-set-key (kbd "M-SPC") 'jedi:complete) |
|
(local-set-key (kbd "M-.") 'jedi:goto-definition))) |
|
|
|
;;; Smart parens |
|
(smartparens-global-mode t) |
|
|
|
;;; Python stuff |
|
(add-hook 'python-mode-hook |
|
(lambda () |
|
(require 'virtualenv) |
|
(flymake-python-pyflakes-load) |
|
(rainbow-delimiters-mode) |
|
(auto-complete-mode) |
|
(whitespace-mode) |
|
;; Automatic pairing of delimeters |
|
(define-key python-mode-map "\"" 'electric-pair) |
|
(define-key python-mode-map "\'" 'electric-pair) |
|
(define-key python-mode-map "(" 'electric-pair) |
|
(define-key python-mode-map "[" 'electric-pair) |
|
(define-key python-mode-map "{" 'electric-pair) |
|
(define-key python-mode-map "\C-m" 'newline-and-indent))) |
|
|
|
(defun electric-pair () |
|
"Insert character pair without surounding spaces" |
|
(interactive) |
|
(let (parens-require-spaces) |
|
(insert-pair))) |
|
|
|
;; Rope and Pymacs |
|
;; Install Pymacs by downloading the latest source code: |
|
;; https://github.com/pinard/Pymacs/tarball/v0.2 |
|
;; Then, after untaring the source code: |
|
;; cd to the source code directory |
|
;; make |
|
;; mkdir ~/.emacs.d/vendor/pymacs |
|
;; cp ~/share/emacs/lisp/pymacs.el ~/.emacs.d/vendor/pymacs/pymacs.el |
|
;; emacs -batch -eval '(byte-compile-file "~/.emacs.d/vendor/pymacs/pymacs.el")' |
|
;; pip install https://github.com/pinard/Pymacs/tarball/v0.2 |
|
;; pip install http://bitbucket.org/agr/ropemacs/get/tip.tar.gz |
|
(require 'pymacs) |
|
(autoload 'pymacs-apply "pymacs") |
|
(autoload 'pymacs-call "pymacs") |
|
(autoload 'pymacs-eval "pymacs" nil t) |
|
(autoload 'pymacs-exec "pymacs" nil t) |
|
(autoload 'pymacs-load "pymacs" nil t) |
|
(pymacs-load "ropemacs" "rope-") |
|
(setq ropemacs-enable-autoimport t) |
|
|
|
;; Default tab and indentation behavior |
|
(setq-default indent-tabs-mode nil) |
|
(setq-default tab-width 4) |
|
|
|
(defun python-add-breakpoint () |
|
"Add a break point" |
|
(interactive) |
|
(newline-and-indent) |
|
(insert "import epdb; epdb.st()") |
|
(hightlight-lines-matching-regexp "^[]*import epdb; epdb.st()")) |
|
(global-set-key (kbd "C-c C-b") 'python-add-breakpoint) |
|
|
|
(defun datestamp () |
|
(interactive) |
|
(call-process "date" nil t)) |
|
|
|
(global-set-key (kbd "<f6>") 'datestamp) |
|
(global-set-key "\C-xg" 'magit-status) |
|
|
|
;; Handles sourcing ZSH |
|
(let ((path (shell-command-to-string ". ~/.zshrc; echo -n $PATH"))) |
|
(setenv "PATH" path) |
|
(setq exec-path |
|
(append |
|
(split-string-and-unquote path ":") |
|
exec-path))) |
|
(custom-set-variables |
|
;; custom-set-variables was added by Custom. |
|
;; If you edit it by hand, you could mess it up, so be careful. |
|
;; Your init file should contain only one such instance. |
|
;; If there is more than one, they won't work right. |
|
'(safe-local-variable-values (quote ((encoding . utf-8) (whitespace-line-column . 80) (lexical-binding . t))))) |
|
(custom-set-faces |
|
;; custom-set-faces was added by Custom. |
|
;; If you edit it by hand, you could mess it up, so be careful. |
|
;; Your init file should contain only one such instance. |
|
;; If there is more than one, they won't work right. |
|
) |