forked from ran9er/init.emacs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path12_auto-complete.el
247 lines (217 loc) · 8.35 KB
/
12_auto-complete.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
;; -*- encoding: utf-8-unix; -*-
;---------------------auto complete-------------------
(add-to-list 'load-path
(expand-file-name "auto-complete/" *init-dir*))
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
(ac-config-default)
;; Show 0.8 second later
(setq ac-auto-show-menu 0.8)
;; 20 lines
(setq ac-menu-height 20)
;; Examples
(set-face-background 'ac-candidate-face "lightgray")
(set-face-underline 'ac-candidate-face "darkgray")
(set-face-background 'ac-selection-face "steelblue")
(add-hook 'c++-mode (lambda () (add-to-list 'ac-sources 'ac-source-semantic)))
;; Complete member name by C-c . for C++ mode.
;(add-hook 'c++-mode-hook
; (lambda ()
; (local-set-key (kbd "C-c .") 'ac-complete-semantic)))
;; Complete file name by C-c /
;(global-set-key (kbd "C-c /") 'ac-complete-filename)
(defun semantic-and-gtags-complete ()
(interactive)
(auto-complete '(ac-source-semantic ac-source-gtags)))
(defun auto-complete-settings ()
"Settings for `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', 因为当你输入完一个
;; 单词的时候, 很有可能补全菜单还在, 这时候你要回车的话,
;; 必须要干掉补全菜单, 很麻烦, 用M-j来执行`ac-complete'
(define-key ac-complete-mode-map "<return>" 'nil)
(define-key ac-complete-mode-map "RET" 'nil)
(define-key ac-complete-mode-map "M-j" 'ac-complete)
(define-key ac-complete-mode-map "<C-return>" 'ac-complete)
(define-key ac-complete-mode-map "\C-n" 'ac-next)
(define-key ac-complete-mode-map "\C-p" 'ac-previous)
(setq ac-dwim t)
(setq ac-candidate-max ac-candidate-menu-height)
(set-default 'ac-sources
'(ac-source-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-imenu
ac-source-files-in-current-dir
ac-source-filename))
;(setq ac-modes ac+-modes)
(dolist (command `(backward-delete-char-untabify delete-backward-char))
(add-to-list 'ac-trigger-commands command))
(defun ac-start-use-sources (sources)
(interactive)
(let ((ac-sources sources))
(call-interactively 'ac-start)))
(defvar ac-trigger-edit-commands
`(self-insert-command
delete-backward-char
backward-delete-char
backward-delete-char-untabify)
"*Trigger edit commands that specify whether `auto-complete' should start or not when `ac-completing'."))
(eval-after-load "auto-complete"
'(auto-complete-settings))
(eval-after-load "cc-mode"
'(progn
(dolist (command `(c-electric-backspace
c-electric-backspace-kill))
(add-to-list 'ac-trigger-commands command)
(add-to-list 'ac-trigger-edit-commands command))))
(eval-after-load "autopair"
'(progn
(dolist (command `(autopair-insert-or-skip-quote
autopair-backspace
autopair-extra-skip-close-maybe))
(add-to-list 'ac-trigger-commands command))
(defun ac-trigger-command-p ()
"Return non-nil if `this-command' is a trigger command."
(or
(and
(memq this-command ac-trigger-commands)
(let* ((autopair-emulation-alist nil)
(key (this-single-command-keys))
(beyond-autopair (or (key-binding key)
(key-binding (lookup-key local-function-key-map key)))))
(memq beyond-autopair ac-trigger-edit-commands)))
(and ac-completing
(memq this-command ac-trigger-edit-commands))))))
(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-yasnippet
ac-source-symbols
;; ac-source-semantic
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
;; ac-source-imenu
ac-source-files-in-current-dir
ac-source-filename)))
(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-all-buffer
ac-source-files-in-current-dir
ac-source-filename)))
(defun ac-settings-4-c ()
(setq ac-omni-completion-sources (list (cons "\\." '(ac-source-semantic))
(cons "->" '(ac-source-semantic))))
(setq ac-sources
'(ac-source-yasnippet
ac-source-c-keywords
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-files-in-current-dir
ac-source-filename)))
(defun ac-settings-4-cpp ()
(setq ac-omni-completion-sources
(list (cons "\\." '(ac-source-semantic))
(cons "->" '(ac-source-semantic))))
(setq ac-sources
'(ac-source-yasnippet
ac-source-c++-keywords
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-files-in-current-dir
ac-source-filename)))
(defun ac-settings-4-text ()
(setq ac-sources
'(;;ac-source-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-imenu)))
;; (defun ac-settings-4-eshell ()
;; (setq ac-sources
;; '(;;ac-source-semantic
;; ;; ac-source-yasnippet
;; ac-source-files-in-current-dir
;; ac-source-filename
;; ac-source-abbrev
;; ac-source-words-in-buffer
;; ac-source-words-in-all-buffer
;; 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-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-files-in-current-dir
ac-source-filename)))
(defun ac-settings-4-tcl ()
(setq ac-sources
'(;;ac-source-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-files-in-current-dir
ac-source-filename)))
(defun ac-settings-4-awk ()
(setq ac-sources
'(;;ac-source-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
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)
;; ('java-mode-hook 'ac-settings-4-java)
;; ('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)
(require 'auto-complete-settings)