-
Notifications
You must be signed in to change notification settings - Fork 0
/
ac-anything.el
executable file
·143 lines (118 loc) · 4.48 KB
/
ac-anything.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
;;; ac-anything.el --- Auto Complete with Anything
;; $Id: ac-anything.el,v 1.6 2009/11/11 17:13:11 rubikitch Exp $
;; Copyright (C) 2009 rubikitch
;; Author: rubikitch <rubikitch@ruby-lang.org>
;; Keywords: convenience
;; URL: http://www.emacswiki.org/cgi-bin/wiki/download/ac-anything.el
;; 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 Anything. It enables us to narrow candidates
;; with anything interface. If you have anything-match-plugin.el,
;; candidates can be narrowed many times.
;;; Commands:
;;
;; Below are complete command list:
;;
;; `ac-complete-with-anything'
;; Select auto-complete candidates by `anything'.
;;
;;; Customizable Options:
;;
;; Below are customizable option list:
;;
;;; Requirements:
;; http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
;; http://www.emacswiki.org/cgi-bin/wiki/download/auto-complete.el
;; http://www.emacswiki.org/cgi-bin/wiki/download/anything-match-plugin.el (optional)
;;; Installation:
;; Add below code in your ~/.emacs
;;
;; (require 'ac-anything)
;; (define-key ac-complete-mode-map (kbd "C-:") 'ac-complete-with-anything)
;; That's all.
;;; History:
;; $Log: ac-anything.el,v $
;; Revision 1.6 2009/11/11 17:13:11 rubikitch
;; Use pulldown.el if available
;;
;; Revision 1.5 2009/11/11 17:08:16 rubikitch
;; Replace ac-prefix with (anything-attr 'ac-prefix)
;;
;; Revision 1.4 2009/04/18 21:08:49 rubikitch
;; Remove attribute `ac-point'
;;
;; Revision 1.3 2009/04/18 21:03:51 rubikitch
;; * Auto Document
;; * Use anything-show-completion.el if available
;;
;; Revision 1.2 2009/02/09 21:24:44 rubikitch
;; *** empty log message ***
;;
;; Revision 1.1 2009/02/09 21:09:16 rubikitch
;; Initial revision
;;
;;; Code:
(defvar ac-anything-version "$Id: ac-anything.el,v 1.6 2009/11/11 17:13:11 rubikitch Exp $")
(require 'anything)
(require 'anything-match-plugin nil t)
(require 'auto-complete)
(require 'pulldown nil t) ;for latest version of auto-complete
(when (require 'anything-show-completion nil t)
(use-anything-show-completion 'ac-complete-with-anything
'(length (anything-attr 'ac-prefix))))
(defun ac-complete-with-anything ()
"Select auto-complete candidates by `anything'.
It is useful to narrow candidates."
(interactive)
(when ac-completing
(anything 'anything-c-source-auto-complete-candidates nil nil nil nil
"*anything auto-complete*")))
(defun anything-c-auto-complete-init ()
(anything-attrset 'ac-candidates ac-candidates)
(anything-attrset 'menu-width
(if (fboundp 'pulldown-width)
(pulldown-width ac-menu)
(ac-menu-width ac-menu)))
(anything-attrset 'ac-prefix ac-prefix)
(ac-abort))
(defun anything-c-auto-complete-action (string)
(delete-backward-char (length (anything-attr 'ac-prefix)))
(insert string)
(prog1 (let ((action (ac-get-candidate-property 'action string)))
(if action (funcall action)))
;; for GC
(anything-attrset 'ac-candidates nil)))
(defun anything-c-auto-complete-candidates ()
(loop for x in (anything-attr 'ac-candidates) collect
(cons
(anything-aif (ac-get-candidate-property 'action x)
(format "%s%s <%s>"
x
;; padding
(make-string (- (anything-attr 'menu-width) (length x)) ? )
;; action function name
it)
x)
x)))
(defvar anything-c-source-auto-complete-candidates
'((name . "Auto Complete")
(init . anything-c-auto-complete-init)
(candidates . anything-c-auto-complete-candidates)
(action . anything-c-auto-complete-action)
(ac-candidates)
(menu-width)))
(provide 'ac-anything)
;; How to save (DO NOT REMOVE!!)
;; (emacswiki-post "ac-anything.el")
;;; ac-anything.el ends here