-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanything-ruby-methods.el
More file actions
55 lines (46 loc) · 1.67 KB
/
Copy pathanything-ruby-methods.el
File metadata and controls
55 lines (46 loc) · 1.67 KB
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
;;; anything-ruby-methods.el --- anything + what_methods
;;; INSTALLATION:
;;
;; Add the following to your .emacs:
;;
;; (require 'anything-ruby-methods)
;; (define-key ruby-mode-map (kbd "C-c d") 'anything-ruby-methods)
(require 'anything)
(defvar anything-c-source-ruby-methods
'((name . "Methods")
(candidates . anything-ruby-methods-create-what-list)
(action . (lambda (m) (insert (concat "." m))))))
(defun anything-ruby-methods ()
(interactive)
(let* ((input (cond
((transient-region-active-p)
(buffer-substring-no-properties (mark) (point)))
(t
(anything-ruby-methods-line-object))))
(output (read-string (format "'%s' to: " input))))
(anything :sources 'anything-c-source-ruby-methods
:buffer "*anything ruby methods*"
:anything-quit-if-no-candidate t)))
(defun anything-ruby-methods-line-object ()
(let ((current-point (point)))
(save-excursion
(beginning-of-line)
(re-search-forward "\\S-" (point-at-eol))
(buffer-substring-no-properties (1- (point)) current-point))))
(defun anything-ruby-methods-what ()
(shell-command-to-string (format
"ruby -e 'require \"what_methods\"
begin
puts WhatMethods::MethodFinder.find(%s, %s)
rescue
print \"\"
end'"
input output)))
(defun anything-ruby-methods-create-what-list ()
(let ((ruby-methods-output (anything-ruby-methods-what)))
(cond ((= 0 (length ruby-methods-output))
(message "Methods not found.")
'())
(t
(split-string ruby-methods-output "\n")))))
(provide 'anything-ruby-methods)