forked from gabrielelanaro/emacs-for-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepy-python.el
116 lines (85 loc) · 3.59 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
;; 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 "..")))
)))
)
;;=========================================================
;; 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))
(add-hook 'python-mode-hook '(lambda ()
(define-key python-mode-map "\C-m" 'newline-and-indent)))
(provide 'epy-python)