-
Notifications
You must be signed in to change notification settings - Fork 1
/
auto-complete-settings.el
212 lines (186 loc) · 6.92 KB
/
auto-complete-settings.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
(add-to-list 'load-path (concat emacs-path "extension/auto-complete"))
(require 'auto-complete-config)
(require 'auto-complete+)
;; After do this, isearch any string, M-: (match-data) always
;; return the list whose elements is integer
(global-auto-complete-mode 1)
;; 不让回车的时候执行`ac-complete', 因为当你输入完一个
;; 单词的时候, 很有可能补全菜单还在, 这时候你要回车的话,
;; 必须要干掉补全菜单, 很麻烦, 用C-m来执行`ac-complete'
(eal-define-keys
'ac-complete-mode-map
`(("<return>" nil)
("RET" nil)
("C-m" ac-complete)))
(defun auto-complete-settings ()
"Settings for `auto-complete'."
(add-to-list 'ac-dictionary-directories (concat emacs-path "extension/auto-complete/ac-dict"))
(setq ac-auto-show-menu t
ac-auto-start t
ac-dwim t
ac-candidate-limit ac-menu-height
ac-quick-help-delay .5
ac-disable-faces nil)
(set-default 'ac-sources
'(;;ac-source-semantic-raw
ac-source-yasnippet
ac-source-dictionary
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-same-mode-buffers
ac-source-imenu
ac-source-files-in-current-dir
ac-source-filename))
(setq ac-modes ac+-modes)
(defun ac-start-use-sources (sources)
(interactive)
(let ((ac-sources sources))
(call-interactively 'ac-start))))
(eval-after-load "auto-complete"
'(auto-complete-settings))
(defun ac-settings-4-cc ()
"`auto-complete' settings for `cc-mode'."
(dolist (command `(c-electric-backspace
c-electric-backspace-kill))
(add-to-list 'ac-trigger-commands-on-completing command)))
(eval-after-load "cc-mode"
'(ac-settings-4-cc))
(defun ac-settings-4-autopair ()
"`auto-complete' settings for `autopair'."
(defun ac-trigger-command-p (command)
"Return non-nil if `this-command' is a trigger command."
(or
(and
(symbolp command)
(or (memq command ac-trigger-commands)
(string-match "self-insert-command" (symbol-name command))
(string-match "electric" (symbol-name command))
(let* ((autopair-emulation-alist nil)
(key (this-single-command-keys))
(beyond-autopair (or (key-binding key)
(and (setq key (lookup-key local-function-key-map key))
(key-binding key)))))
(or
(memq beyond-autopair ac-trigger-commands)
(and ac-completing
(memq beyond-autopair ac-trigger-commands-on-completing)))))))))
(eval-after-load "autopair"
'(ac-settings-4-autopair))
(defun ac-settings-4-lisp ()
"Auto complete settings for lisp mode."
(setq ac-omni-completion-sources '(("\\<featurep\s+'" ac+-source-elisp-features)
("\\<require\s+'" ac+-source-elisp-features)
("\\<load\s+\"" ac-source-emacs-lisp-features)))
(ac+-apply-source-elisp-faces)
(setq ac-sources
'(ac-source-features
ac-source-functions
ac-source-yasnippet
ac-source-variables
ac-source-symbols
ac-source-dictionary
ac-source-abbrev
ac-source-words-in-buffer
ac-source-files-in-current-dir
ac-source-filename
ac-source-words-in-same-mode-buffers)))
(defun ac-settings-4-java ()
(setq ac-omni-completion-sources (list (cons "\\." '(ac-source-semantic))
(cons "->" '(ac-source-semantic))))
(setq ac-sources
'(;;ac-source-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-same-mode-buffers
ac-source-files-in-current-dir
ac-source-filename)))
(defun ac-settings-4-c ()
(setq ac-sources
'(ac-source-yasnippet
ac-source-dictionary
;; ac-source-semantic
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-same-mode-buffers
ac-source-files-in-current-dir
ac-source-filename)))
(defun ac-settings-4-cpp ()
(setq ac-sources
'(ac-source-yasnippet
ac-source-dictionary
;; ac-source-semantic
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-same-mode-buffers
ac-source-files-in-current-dir
ac-source-filename)))
(defun ac-settings-4-text ()
(setq ac-sources
'(ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-same-mode-buffers
ac-source-imenu)))
(defun ac-settings-4-eshell ()
(setq ac-sources
'(ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-same-mode-buffers
ac-source-files-in-current-dir
ac-source-filename
ac-source-symbols
ac-source-imenu)))
(defun ac-settings-4-ruby ()
(require 'rcodetools-settings)
(setq ac-omni-completion-sources
(list (cons "\\." '(ac-source-rcodetools))
(cons "::" '(ac-source-rcodetools)))))
(defun ac-settings-4-html ()
(setq ac-sources
'(ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-same-mode-buffers
ac-source-files-in-current-dir
ac-source-filename)))
(defun ac-settings-4-tcl ()
(setq ac-sources
'(ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-same-mode-buffers
ac-source-files-in-current-dir
ac-source-filename)))
(defun ac-settings-4-awk ()
(setq ac-sources
'(ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-same-mode-buffers
ac-source-files-in-current-dir
ac-source-filename)))
(am-add-hooks
`(lisp-mode-hook emacs-lisp-mode-hook lisp-interaction-mode-hook
svn-log-edit-mode-hook change-log-mode-hook)
'ac-settings-4-lisp)
(apply-args-list-to-fun
(lambda (hook fun)
(am-add-hooks hook fun))
`(('java-mode-hook 'ac-settings-4-java)
('c-mode-hook 'ac-settings-4-c)
('c++-mode-hook 'ac-settings-4-cpp)
('text-mode-hook 'ac-settings-4-text)
('eshell-mode-hook 'ac-settings-4-eshell)
('ruby-mode-hook 'ac-settings-4-ruby)
('html-mode-hook 'ac-settings-4-html)
('awk-mode-hook 'ac-settings-4-awk)
('tcl-mode-hook 'ac-settings-4-tcl)))
(eal-eval-by-modes
ac-modes
(lambda (mode)
(let ((mode-name (symbol-name mode)))
(when (and (intern-soft mode-name) (intern-soft (concat mode-name "-map")))
(define-key (symbol-value (am-intern mode-name "-map")) (kbd "C-c a") 'ac-start)))))
(provide 'auto-complete-settings)