-
Notifications
You must be signed in to change notification settings - Fork 0
/
anything-rcodetools.el
151 lines (133 loc) · 4.71 KB
/
anything-rcodetools.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
;;; anything-rcodetools.el --- accurate Ruby method completion with anything
;; $Id: anything-rcodetools.el,v 1.13 2009/04/20 16:25:37 rubikitch Exp $
;;; Copyright (c) 2007 rubikitch
;; Author: rubikitch <[email protected]>
;; URL: http://www.emacswiki.org/cgi-bin/wiki/download/anything-rcodetools.el
;;; Use and distribution subject to the terms of the Ruby license.
;;; Commentary:
;; (0) You need rcodetools, anything.el and FastRI. Note that you do not have to
;; configure anything.el if you use anything.el for this package.
;; (1) You need to add to .emacs:
;; (require 'anything)
;; (require 'anything-rcodetools)
;; ;; Command to get all RI entries.
;; (setq rct-get-all-methods-command "PAGER=cat fri -l")
;; ;; See docs
;; (define-key anything-map "\C-z" 'anything-execute-persistent-action)
;;; Commands:
;;
;; Below are complete command list:
;;
;;
;;; Customizable Options:
;;
;; Below are customizable option list:
;;
;;; History:
;; $Log: anything-rcodetools.el,v $
;; Revision 1.13 2009/04/20 16:25:37 rubikitch
;; Set anything-samewindow to nil
;;
;; Revision 1.12 2009/04/18 10:12:02 rubikitch
;; Adjust to change of `use-anything-show-completion'
;;
;; Revision 1.11 2009/04/17 20:21:47 rubikitch
;; * require anything
;; * require anything-show-completion.el if available
;;
;; Revision 1.10 2009/04/17 20:11:03 rubikitch
;; removed old code
;;
;; Revision 1.9 2009/04/17 20:07:52 rubikitch
;; * use --completion-emacs-anything option
;; * New implementation of `anything-c-source-complete-ruby-all'
;;
;; Revision 1.8 2009/04/15 10:25:25 rubikitch
;; Set `anything-execute-action-at-once-if-one' t
;;
;; Revision 1.7 2009/04/15 10:24:23 rubikitch
;; regexp bug fix
;;
;; Revision 1.6 2008/01/14 17:59:34 rubikitch
;; * uniform format (anything-c-source-complete-ruby, anything-c-source-complete-ruby-all)
;; * rename command: anything-c-ri -> anything-rct-ri
;;
;; Revision 1.5 2008/01/13 17:54:04 rubikitch
;; anything-current-buffer advice.
;;
;; Revision 1.4 2008/01/08 14:47:34 rubikitch
;; Added (require 'rcodetools).
;; Revised commentary.
;;
;; Revision 1.3 2008/01/04 09:32:29 rubikitch
;; *** empty log message ***
;;
;; Revision 1.2 2008/01/04 09:21:23 rubikitch
;; fixed typo
;;
;; Revision 1.1 2008/01/04 09:21:05 rubikitch
;; Initial revision
;;
;;; Code:
(require 'anything)
(require 'rcodetools)
(when (require 'anything-show-completion nil t)
(use-anything-show-completion 'rct-complete-symbol--anything
'(length pattern)))
(defun anything-rct-ri (meth)
(ri (get-text-property 0 'desc meth)))
(defun anything-rct-complete (meth)
(save-excursion
(set-buffer anything-current-buffer)
(search-backward pattern)
(delete-char (length pattern)))
(insert meth))
(setq rct-complete-symbol-function 'rct-complete-symbol--anything)
(defvar anything-c-source-complete-ruby
'((name . "Ruby Method Completion")
(candidates . rct-method-completion-table)
(init
. (lambda ()
(condition-case x
(rct-exec-and-eval rct-complete-command-name "--completion-emacs-anything")
((error) (setq rct-method-completion-table nil)))))
(action
("Completion" . anything-rct-complete)
("RI" . anything-rct-ri))
(volatile)
(persistent-action . anything-rct-ri)))
(defvar rct-get-all-methods-command "PAGER=cat fri -l")
(defvar anything-c-source-complete-ruby-all
'((name . "Ruby Method Completion (ALL)")
(init
. (lambda ()
(unless (anything-candidate-buffer)
(with-current-buffer (anything-candidate-buffer 'global)
(call-process-shell-command rct-get-all-methods-command nil t)
(goto-char 1)
(while (re-search-forward "^.+[:#.]\\([^:#.]+\\)$" nil t)
(replace-match "\\1\t[\\&]"))))))
(candidates-in-buffer
. (lambda ()
(let ((anything-pattern (format "^%s.*%s" (regexp-quote pattern) anything-pattern)))
(anything-candidates-in-buffer))))
(display-to-real
. (lambda (line)
(if (string-match "\t\\[\\(.+\\)\\]$" line)
(propertize (substring line 0 (match-beginning 0))
'desc (match-string 1 line))
line)))
(action
("Completion" . anything-rct-complete)
("RI" . anything-rct-ri))
(persistent-action . anything-rct-ri)))
(defun rct-complete-symbol--anything ()
(interactive)
(let ((anything-execute-action-at-once-if-one t)
anything-samewindow)
(anything '(anything-c-source-complete-ruby
anything-c-source-complete-ruby-all))))
(provide 'anything-rcodetools)
;; How to save (DO NOT REMOVE!!)
;; (emacswiki-post "anything-rcodetools.el")
;;; install-elisp.el ends here