-
Notifications
You must be signed in to change notification settings - Fork 150
/
epy-completion.el
79 lines (65 loc) · 2.45 KB
/
epy-completion.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
;;; epy-completion.el --- A few common completion tricks
;; Pairing parentheses
;; All languages:
(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)
;; Just python
(add-hook 'python-mode-hook
(lambda ()
(define-key python-mode-map "'" 'skeleton-pair-insert-maybe)))
;; Live completion with auto-complete
;; (see http://cx4a.org/software/auto-complete/)
(require 'auto-complete-config nil t)
(add-to-list 'ac-dictionary-directories (concat epy-install-dir "elpa-to-submit/auto-complete/dict/"))
;; Do What I Mean mode
(setq ac-dwim t)
(ac-config-default)
;; custom keybindings to use tab, enter and up and down arrows
(define-key ac-complete-mode-map "\t" 'ac-expand)
(define-key ac-complete-mode-map "\r" 'ac-complete)
(define-key ac-complete-mode-map "\M-n" 'ac-next)
(define-key ac-complete-mode-map "\M-p" 'ac-previous)
;; Disabling Yasnippet completion
(when epy-load-yasnippet-p
(defun epy-snips-from-table (table)
(with-no-warnings
(let ((hashtab (ac-yasnippet-table-hash table))
(parent (ac-yasnippet-table-parent table))
candidates)
(maphash (lambda (key value)
(push key candidates))
hashtab)
(identity candidates))))
(defun epy-get-all-snips ()
(require 'yasnippet) ;; FIXME: find a way to conditionally load it
(let (candidates)
(maphash
(lambda (kk vv) (push (epy-snips-from-table vv) candidates)) yas/tables)
(apply 'append candidates))))
;;(setq ac-ignores (concatenate 'list ac-ignores (epy-get-all-snips)))
;; ropemacs Integration with auto-completion
(defun ac-ropemacs-candidates ()
(mapcar (lambda (completion)
(concat ac-prefix completion))
(rope-completions)))
(ac-define-source nropemacs
'((candidates . ac-ropemacs-candidates)
(symbol . "p")))
(ac-define-source nropemacs-dot
'((candidates . ac-ropemacs-candidates)
(symbol . "p")
(prefix . c-dot)
(requires . 0)))
(defun ac-nropemacs-setup ()
(setq ac-sources (append '(ac-source-nropemacs
ac-source-nropemacs-dot) ac-sources)))
(defun ac-python-mode-setup ()
(when epy-load-yasnippet-p
(add-to-list 'ac-sources 'ac-source-yasnippet)))
(add-hook 'python-mode-hook 'ac-python-mode-setup)
(add-hook 'rope-open-project-hook 'ac-nropemacs-setup)
(provide 'epy-completion)
;;; epy-completion.el ends here