forked from gabrielelanaro/emacs-for-python
-
Notifications
You must be signed in to change notification settings - Fork 1
/
epy-init.el
141 lines (115 loc) · 3.74 KB
/
epy-init.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
131
132
133
134
135
136
137
138
139
140
141
;; This file initializate all the extensions contained in this package
;; Trick to get the filename of the installation directory
(defconst epy-install-dir
(file-name-directory (or load-file-name
(when (boundp 'bytecomp-filename) bytecomp-filename)
buffer-file-name))
"Installation directory of emacs-for-python"
)
;;
;; Adjust load path to add the following paths
;; yasnippet/
;; plugins/
;; auto-complete
(add-to-list 'load-path
(concat epy-install-dir "yasnippet"))
(add-to-list 'load-path
(concat epy-install-dir "plugins"))
(add-to-list 'load-path
(concat epy-install-dir "auto-complete"))
(add-to-list 'load-path
(concat epy-install-dir "flymake"))
;;============
;; Extensions
;;============
;; Yasnippet
(require 'yasnippet)
(yas/initialize)
(yas/load-directory (concat epy-install-dir "yasnippet/snippets"))
(setq yas/prompt-functions '(yas/ido-prompt yas/dropdown-prompt))
;; Auto-completion
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories
(concat epy-install-dir "auto-complete/ac-dict"))
(ac-config-default)
(define-key ac-mode-map (kbd "M-TAB") 'auto-complete)
;; Rope, this one is more contrived, we have to check if we have
;; pymacs.
;; First adding to python path custom rope extensions
(setenv "PYTHONPATH"
(concat
(getenv "PYTHONPATH") ":"
(concat epy-install-dir "rope-dist")))
(when (require 'pymacs)
(setq pymacs-load-path
(list
(concat epy-install-dir "rope-dist/ropemacs/")))
(pymacs-load "ropemacs" "rope-")
(load (concat epy-install-dir "completion/ac-ropemacs-config.el"))
;; Pretty custom, I've patched ropemode and ropemacs to add this
;; hook.
;;
;; There is also a custom hook to find if there is a project and if
;; there is activate it. In this way the project is automatically opened.
(add-hook 'rope-open-project-hook 'ac-nropemacs-setup)
(setq ropemacs-guess-project t)
(setq ropemacs-enable-autoimport t)
(setq ropemacs-codeassist-maxfixes 3) ;; Stops from erroring if
;; there's a syntax err
;; 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 "..")))
)))
)
;; ibuffer by default
(global-set-key (kbd "C-x C-b") 'ibuffer)
;; Ido mode with fuzzy matching
(require 'ido)
(ido-mode t)
(setq ido-enable-flex-matching t) ;; enable fuzzy matching
;; Parentheses Pairing
(setq skeleton-pair t)
(global-set-key "(" 'skeleton-pair-insert-maybe)
(global-set-key "[" 'skeleton-pair-insert-maybe)
(global-set-key "{" 'skeleton-pair-insert-maybe)
(global-set-key "\"" 'skeleton-pair-insert-maybe)
;; Open Next Line
(require 'open-next-line)
;; Eshell tweaks
;; Visual commands like ipython
(add-hook
'eshell-mode-hook
(lambda ()
(setq
eshell-visual-commands
(append
'("mutt"
"vim"
"screen"
"lftp"
"ipython"
"telnet"
"ssh")
eshell-visual-commands))))
;; Virtualenv commands
(require 'virtualenv)
;; Flymake for python configuration
(require 'python-flymake)
(require 'smart-operator)
;;=====================
;; Keybindings Section
;;=====================
;; Copy-Cut-Paste from clipboard with Super-C Super-X Super-V
(global-set-key (kbd "s-x") 'clipboard-kill-region) ;;cut
(global-set-key (kbd "s-c") 'clipboard-kill-ring-save) ;;copy
(global-set-key (kbd "s-v") 'clipboard-yank) ;;paste
;; calc-mode more comfortable
(global-set-key (kbd "M-c") 'calc-dispatch)
; Ctrl+tab mapped to Alt+tab
(define-key function-key-map [(control tab)] [?\M-\t])
(provide 'epy-init)