diff options
Diffstat (limited to 'ravi-init-python.el')
| -rw-r--r-- | ravi-init-python.el | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/ravi-init-python.el b/ravi-init-python.el new file mode 100644 index 0000000..e9d125c --- /dev/null +++ b/ravi-init-python.el @@ -0,0 +1,133 @@ +;;; 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) + :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 "" + 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) + ) + + (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. + (use-package jedi + :config + (progn + (setq jedi:server-args + `("--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"))) + (setq jedi:complete-on-dot t) + (add-hook 'python-mode-hook 'jedi:setup) + ) + :ensure t + :disabled nil + ) + ) + ) + +(provide 'ravi-init-python) + |
