diff options
| author | Ravi R Kiran <aine.marina@gmail.com> | 2015-03-17 04:17:17 (GMT) |
|---|---|---|
| committer | Ravi R Kiran <aine.marina@gmail.com> | 2015-03-17 04:17:17 (GMT) |
| commit | a6e94a30a835ea389fe8fc40df162ff327035ccb (patch) | |
| tree | cf695ab8c77b2c78434b2c6913295641a9287110 /lisp/ravi-init-python.el | |
| parent | b94602dccfa28b997b1fc1f2e0373d997f4b95ce (diff) | |
| download | dotemacs-a6e94a30a835ea389fe8fc40df162ff327035ccb.zip dotemacs-a6e94a30a835ea389fe8fc40df162ff327035ccb.tar.gz dotemacs-a6e94a30a835ea389fe8fc40df162ff327035ccb.tar.bz2 | |
Move main emacs directory out of load path
This follows the official emacs recommendation for lisp code inside
emacs.d.
Diffstat (limited to 'lisp/ravi-init-python.el')
| -rw-r--r-- | lisp/ravi-init-python.el | 166 |
1 files changed, 166 insertions, 0 deletions
diff --git a/lisp/ravi-init-python.el b/lisp/ravi-init-python.el new file mode 100644 index 0000000..6edc232 --- /dev/null +++ b/lisp/ravi-init-python.el @@ -0,0 +1,166 @@ +;;; ravi-init-python.el --- python support + +;; Copyright (C) 2013 + +;; Author: <ravi@nero.lan> +;; Keywords: + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Python programming setup + +;;; Code: + +(use-package python + :mode ("\\.py\\'" . python-mode) + :commands python-shell-switch-to-shell + :config + (progn + + (add-hook 'python-mode-hook 'ravi/python-mode-hook) + (defun ravi/python-mode-hook() + ;; Set ipython as our interpreter + (setq python-shell-interpreter "ipython" + python-shell-interpreter-args "--pylab" + 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" + ) + + ;; For ipython 0.10, uncomment the following: + ;; (setq python-shell-completion-string-code + ;; "';'.join(__IP.complete('''%s'''))\n" + ;; python-shell-completion-module-string-code "" + ;; ) + + ;; I'd really prefer indentation by 2 spaces, but have too much existing + ;; python code with indentation at 4 spaces. + (setq python-indent-offset 4) + ) + + ;; We no longer use smart-tab-mode + ;(add-to-list 'smart-tab-disabled-major-modes 'inferior-python-mode) + + (define-auto-insert "\\.py\\'" 'ravi/auto-insert-py) + (defun ravi/auto-insert-py () + (progn + (insert "#!/usr/bin/env python\n\n") + ) + ) + + (use-package virtualenvwrapper + :config + (progn + (venv-initialize-interactive-shells) + (venv-initialize-eshell) + (setq venv-location (expand-file-name "~/usr/local/venv/")) + ) + + :ensure t + ) + + ;; Use pymacs+ropemacs for code completion plus documentation browsing. + ;; The main issue is that this requires both python-side and emacs-side + ;; support, and hence cannot be installed as a package from MELPA. + (use-package pymacs + :disabled t + :init + (progn + ;; Many bindings provide same functionality as from other packages. + (setq ropemacs-global-prefix nil) + ;(setq ropemancs-local-prefix nil) + ;(setq ropemacs-enable-shortcuts nil) + ) + :config + (progn + (pymacs-load "ropemacs" "rope-") + (bind-key "C-c C-d" 'rope-show-calltip python-mode-map) + + ;; Auto-complete sources; see + ;; http://www.cx4a.org/pub/auto-complete-python.el + (defvar ac-ropemacs-completions-cache nil) + + (defvar ac-source-ropemacs + '((init + . (lambda () + (setq ac-ropemacs-completions-cache + (mapcar + (lambda (completion) + (concat ac-prefix completion)) + (ignore-errors + (rope-completions)))))) + (candidates . (lambda () + (all-completions ac-prefix ac-ropemacs-completions-cache))))) + + (defun ac-ropemacs-setup () + (ac-ropemacs-require) + ;(setq ac-sources (append (list 'ac-source-ropemacs) ac-sources)) + (setq ac-omni-completion-sources '(("\\." ac-source-ropemacs)))) + + (add-hook 'python-mode-hook 'ac-ropemacs-setup) + + ) + ) + + ;; Use jedi.el for code completion plus documentation browsing. + ;; The main issue is that this requires both python-side and emacs-side + ;; support, but the python-side support cannot be installed as a package + ;; from MELPA. Fedora does not provide python-epc as an RPM either. We + ;; work around it by adding sexpdata, jedi and python-epc as git submodules. + (use-package jedi + :config + (progn + (defun ravi/jedi-setup () + (let ((basic-server-args (list + "--sys-path" (ravi/emacs-file "site-lisp/python-epc") + "--sys-path" (ravi/emacs-file "site-lisp/sexpdata") + "--sys-path" (ravi/emacs-file "site-lisp/jedi")) + )) + (set (make-local-variable 'jedi:server-args) + (if (and (boundp 'extra-jedi-args) + (listp extra-jedi-args)) + (append basic-server-args extra-jedi-args) + basic-server-args)) + (jedi:setup))) + + (defun ravi/python-jedi-hook-installer () + (setq jedi:complete-on-dot t) + (add-hook 'hack-local-variables-hook 'ravi/jedi-setup nil t)) + (add-hook 'python-mode-hook 'ravi/python-jedi-hook-installer) + ) + :ensure t + :disabled t ; casualty of removing auto-complete + ) + + (use-package sphinx-doc + :config + (progn + (defun ravi/sphinx-doc-setup () + (sphinx-doc-mode 1)) + (add-hook 'python-mode-hook 'ravi/sphinx-doc-setup) + ) + :diminish t + :ensure t) + ) + ) + +(provide 'ravi-init-python) + |
