1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
;;; 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 "--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)
)
(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
(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)
|