forked from technomancy/emacs-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 17
/
starter-kit-completion.el
69 lines (57 loc) · 2.18 KB
/
starter-kit-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
;;; starter-kit-completion.el --- A few common completion tricks
(defun ac-eshell-mode-setup ()
(add-to-list 'ac-sources 'ac-source-files-in-current-dir))
;; 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 dotfiles-dir "elpa-to-submit/auto-complete/dict/"))
;; Do What I Mean mode
(setq ac-dwim t)
(ac-config-default)
;; set also the completion for eshell
(add-hook 'eshell-mode-hook 'ac-eshell-mode-setup)
;; 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
(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 ()
(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 ()
(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 'starter-kit-completion)
;;; starter-kit-completion.el ends here