From e6d62ff12211b536ee5f68e57ed5d8c0456780cb Mon Sep 17 00:00:00 2001 From: Ravi R Kiran Date: Mon, 30 Dec 2013 21:14:29 -0800 Subject: Python support diff --git a/.gitmodules b/.gitmodules index 9ed3ca4..bad26cf 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,12 @@ [submodule "site-lisp/mu"] path = site-lisp/mu url = https://github.com/djcb/mu.git +[submodule "site-lisp/jedi"] + path = site-lisp/jedi + url = https://github.com/davidhalter/jedi.git +[submodule "site-lisp/python-epc"] + path = site-lisp/python-epc + url = https://github.com/tkf/python-epc.git +[submodule "site-lisp/sexpdata"] + path = site-lisp/sexpdata + url = https://github.com/tkf/sexpdata.git diff --git a/init.el b/init.el index 2e3d2eb..9fea42f 100644 --- a/init.el +++ b/init.el @@ -98,6 +98,7 @@ (require 'ravi-init-insertion) (require 'ravi-init-navigation) (require 'ravi-init-cpp) +(require 'ravi-init-python) ;; Temporary key-bindings (bind-key "" 'ido-find-file) 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: +;; 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 . + +;;; 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) + diff --git a/site-lisp/jedi b/site-lisp/jedi new file mode 160000 index 0000000..78f1ae5 --- /dev/null +++ b/site-lisp/jedi @@ -0,0 +1 @@ +Subproject commit 78f1ae5e7163bda737433f1d551b3180cf03e1d1 diff --git a/site-lisp/python-epc b/site-lisp/python-epc new file mode 160000 index 0000000..04387c0 --- /dev/null +++ b/site-lisp/python-epc @@ -0,0 +1 @@ +Subproject commit 04387c0c24098565c156e7de4442306dfdd78a69 diff --git a/site-lisp/sexpdata b/site-lisp/sexpdata new file mode 160000 index 0000000..edbe8dd --- /dev/null +++ b/site-lisp/sexpdata @@ -0,0 +1 @@ +Subproject commit edbe8dd15e1fe406693ec28cc13ec711052d3788 -- cgit v0.10.1