forked from gabrielelanaro/emacs-for-python
-
Notifications
You must be signed in to change notification settings - Fork 1
/
epy-python.el
130 lines (99 loc) · 4.1 KB
/
epy-python.el
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
;; epy-python.el - setup of python stuff
;; fgallina/python.el
(require 'python (concat epy-install-dir "extensions/python.el"))
;; pymacs
(require 'pymacs (concat epy-install-dir "extensions/pymacs.el"))
(defun setup-ropemacs ()
"Setup the ropemacs harness"
(setenv "PYTHONPATH"
(concat
(getenv "PYTHONPATH") path-separator
(concat epy-install-dir "python-libs/")))
(pymacs-load "ropemacs" "rope-")
;; Stops from erroring if there's a syntax err
(setq ropemacs-codeassist-maxfixes 3)
;; Configurations
(setq ropemacs-guess-project t)
(setq ropemacs-enable-autoimport t)
(setq ropemacs-autoimport-modules '("os" "shutil" "sys" "logging"
"django.*"))
;; Adding hook to automatically open a rope project if there is one
;; in the current or in the upper level directory
(add-hook 'python-mode-hook
(lambda ()
(cond ((file-exists-p ".ropeproject")
(rope-open-project default-directory))
((file-exists-p "../.ropeproject")
(rope-open-project (concat default-directory "..")))
)))
)
;; Ipython integration with fgallina/python.el
(defun epy-setup-ipython ()
"Setup ipython integration with python-mode"
(interactive)
(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 ""
python-shell-completion-string-code "';'.join(__IP.complete('''%s'''))\n")
)
;;=========================================================
;; Flymake additions, I have to put this one somwhere else?
;;=========================================================
(defun flymake-create-copy-file ()
"Create a copy local file"
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace)))
(file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(defun flymake-command-parse (cmdline)
"Parses the command line CMDLINE in a format compatible
with flymake, as:(list cmd-name arg-list)
The CMDLINE should be something like:
flymake %f python custom.py %f
%f will be substituted with a temporary copy of the file that is
currently being checked.
"
(let ((cmdline-subst (replace-regexp-in-string "%f" (flymake-create-copy-file) cmdline)))
(setq cmdline-subst (split-string-and-unquote cmdline-subst))
(list (first cmdline-subst) (rest cmdline-subst))
))
(when (load-file (concat epy-install-dir "extensions/flymake-patch.el"))
(setq flymake-info-line-regex
(append flymake-info-line-regex '("unused$" "^redefinition" "used$")))
(load-library "flymake-cursor"))
(defun epy-setup-checker (cmdline)
(add-to-list 'flymake-allowed-file-name-masks
(list "\\.py\\'" (apply-partially 'flymake-command-parse cmdline)))
)
;; Python or python mode?
(eval-after-load 'python
'(progn
;;==================================================
;; Ropemacs Configuration
;;==================================================
(setup-ropemacs)
;;==================================================
;; Virtualenv Commands
;;==================================================
(autoload 'virtualenv-activate "virtualenv"
"Activate a Virtual Environment specified by PATH" t)
(autoload 'virtualenv-workon "virtualenv"
"Activate a Virtual Environment present using virtualenvwrapper" t)
;; Not on all modes, please
(add-hook 'python-mode-hook 'flymake-find-file-hook)
)
)
;; Cython Mode
(autoload 'cython-mode "cython-mode" "Mode for editing Cython source files")
(add-to-list 'auto-mode-alist '("\\.pyx\\'" . cython-mode))
(add-to-list 'auto-mode-alist '("\\.pxd\\'" . cython-mode))
(add-to-list 'auto-mode-alist '("\\.pxi\\'" . cython-mode))
;; Py3 files
(add-to-list 'auto-mode-alist '("\\.py3\\'" . python-mode))
(add-hook 'python-mode-hook '(lambda ()
(define-key python-mode-map "\C-m" 'newline-and-indent)))
(provide 'epy-python)