-
Notifications
You must be signed in to change notification settings - Fork 8
/
ac-helm.el
117 lines (97 loc) · 3.57 KB
/
ac-helm.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
;;; ac-helm.el --- Helm interface for auto-complete
;; Copyright (C) 2009 rubikitch
;; Copyright (C) 2013 Yasuyuki Oka <[email protected]>
;; Author: rubikitch <[email protected]>
;; Yasuyuki Oka <[email protected]>
;; Maintainer: Yasuyuki Oka <[email protected]>
;; Version: 2.2
;; Package-Requires: ((helm "1.6.3")(auto-complete "1.4.0")(popup "0.5.0") (cl-lib "0.5"))
;; Keywords: completion, convenience, helm
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;; Auto Complete with Helm. It enables us to narrow candidates
;; with helm interface. If you have helm-match-plugin.el,
;; candidates can be narrowed many times.
;; Commands:
;;
;; Below are complete command list:
;;
;; `ac-complete-with-helm'
;; Select auto-complete candidates by `helm'.
;;
;; Customizable Options:
;;
;; Below are customizable option list:
;;
;; Installation:
;; Add the following to your emacs init file:
;;
;; (require 'ac-helm) ;; Not necessary if using ELPA package
;; (global-set-key (kbd "C-:") 'ac-complete-with-helm)
;; (define-key ac-complete-mode-map (kbd "C-:") 'ac-complete-with-helm)
;; That's all.
;;; Code:
(require 'helm)
(require 'helm-multi-match nil t)
(require 'helm-elisp)
(require 'auto-complete)
(require 'cl-lib)
(require 'popup)
;;;###autoload
(defun ac-complete-with-helm ()
"Select `auto-complete' candidates by `helm'.
It is useful to narrow candidates."
(interactive)
(unless ac-completing
(call-interactively 'auto-complete))
(with-helm-show-completion ac-point (point)
(helm :sources 'helm-source-auto-complete-candidates
:buffer "*helm auto-complete*")))
(defun helm-auto-complete-init ()
(helm-attrset 'ac-candidates ac-candidates)
(helm-attrset 'menu-width
(popup-preferred-width ac-candidates))
(helm-attrset 'ac-prefix ac-prefix)
(when (<= (length ac-candidates) 1)
(helm-exit-minibuffer))
(ac-abort))
(defun helm-auto-complete-action (string)
(delete-char (- (length (helm-attr 'ac-prefix))))
(insert string)
(prog1 (let ((action (get-text-property 0 'action string)))
(if action (funcall action)))
;; for GC
(helm-attrset 'ac-candidates nil)))
(defun helm-auto-complete-candidates ()
(cl-loop for x in (helm-attr 'ac-candidates) collect
(cons
(helm-aif (get-text-property 0 'action x)
(format "%s%s <%s>"
x
;; padding
(make-string (- (helm-attr 'menu-width) (length x)) ? )
;; action function name
it)
x)
x)))
(defvar helm-source-auto-complete-candidates
'((name . "Auto Complete")
(init . helm-auto-complete-init)
(candidates . helm-auto-complete-candidates)
(action . helm-auto-complete-action)
(persistent-action . popup-item-show-help)
(ac-candidates)
(menu-width)))
(provide 'ac-helm)
;;; ac-helm.el ends here