├── README.md
└── ac-inf-ruby.el
/README.md:
--------------------------------------------------------------------------------
1 | [](http://melpa.org/#/ac-inf-ruby)
2 | [](http://stable.melpa.org/#/ac-inf-ruby)
3 |
4 | inf-ruby completion source for Emacs auto-complete package
5 | ==========================================================
6 |
7 | This plugin provides an [auto-complete](http://cx4a.org/software/auto-complete/)
8 | completion source for use in [inf-ruby](https://github.com/nonsequitur/inf-ruby) buffers.
9 |
10 | Installation
11 | =============
12 |
13 | First, ensure `auto-complete` and `inf-ruby` are installed: I recommend
14 | using packages from [MELPA][melpa].
15 |
16 | You'll need both `auto-complete` and `inf-ruby` to be enabled and
17 | working, so please consult the corresponding documentation is you have
18 | any trouble with this.
19 |
20 | Next, install `ac-inf-rub`. If you choose not to use the convenient
21 | package in [MELPA][melpa], you'll need to add the directory containing
22 | `ac-inf-ruby.el` to your `load-path`, and then `(require
23 | 'ac-inf-ruby)`.
24 |
25 | `ac-inf-ruby` provides an `inf-ruby`-specific completion source,
26 | so `auto-complete` needs to be told to use them when `inf-ruby-mode` is
27 | active. To do this, put the following code in your emacs init file to
28 |
29 | ```el
30 | (eval-after-load 'auto-complete
31 | '(add-to-list 'ac-modes 'inf-ruby-mode))
32 | (add-hook 'inf-ruby-mode-hook 'ac-inf-ruby-enable)
33 | ```
34 |
35 | If you want to trigger `auto-complete` using TAB in `inf-ruby` buffers, you
36 | should bind it directly:
37 |
38 | ```el
39 | (eval-after-load 'inf-ruby '
40 | '(define-key inf-ruby-mode-map (kbd "TAB") 'auto-complete))
41 | ```
42 |
43 | Usage
44 | =====
45 |
46 | `ac-inf-ruby` should now automatically be enabled in new `inf-ruby` sessions.
47 |
48 | Simply trigger auto-completion, and completion candidates supplied by
49 | `inf-ruby` should be displayed, with the "r" symbol on the right hand side of the
50 | completion pop-up.
51 |
52 | [melpa]: http://melpa.org
53 |
54 | Acknowledgements
55 | ================
56 |
57 | `ac-inf-ruby` was written by [Steve Purcell](https://github.com/purcell).
58 |
59 |
60 |
61 | [💝 Support this project and my other Open Source work via Patreon](https://www.patreon.com/sanityinc)
62 |
63 | [💼 LinkedIn profile](https://uk.linkedin.com/in/stevepurcell)
64 |
65 | [✍ sanityinc.com](http://www.sanityinc.com/)
66 |
--------------------------------------------------------------------------------
/ac-inf-ruby.el:
--------------------------------------------------------------------------------
1 | ;;; ac-inf-ruby.el --- Enable auto-complete in inf-ruby sessions
2 |
3 | ;; Copyright (C) 2013 Steve Purcell
4 |
5 | ;; Author: Steve Purcell
6 | ;; Keywords: languages, tools
7 | ;; Version: DEV
8 | ;; Package-Requires: ((inf-ruby "2.3.2") (auto-complete "1.4"))
9 |
10 | ;; This program is free software; you can redistribute it and/or modify
11 | ;; it under the terms of the GNU General Public License as published by
12 | ;; the Free Software Foundation, either version 3 of the License, or
13 | ;; (at your option) any later version.
14 |
15 | ;; This program is distributed in the hope that it will be useful,
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | ;; GNU General Public License for more details.
19 |
20 | ;; You should have received a copy of the GNU General Public License
21 | ;; along with this program. If not, see .
22 |
23 | ;;; Commentary:
24 |
25 | ;; Provides an `auto-complete' source for use in `inf-ruby-mode' buffers,
26 | ;; which ties directly into the accurate inf-ruby completions mechanism.
27 |
28 | ;; Enable using:
29 |
30 | ;; (require 'ac-inf-ruby) ;; when not installed via package.el
31 | ;; (eval-after-load 'auto-complete
32 | ;; '(add-to-list 'ac-modes 'inf-ruby-mode))
33 | ;; (add-hook 'inf-ruby-mode-hook 'ac-inf-ruby-enable)
34 |
35 | ;; Optionally bind auto-complete to TAB in inf-ruby buffers:
36 | ;; (eval-after-load 'inf-ruby '
37 | ;; '(define-key inf-ruby-mode-map (kbd "TAB") 'auto-complete))
38 |
39 | ;;; Code:
40 |
41 | (require 'inf-ruby)
42 | (require 'auto-complete)
43 |
44 | (defun ac-inf-ruby-candidates ()
45 | "Return completion candidates for `ac-prefix'."
46 | (inf-ruby-completions ac-prefix))
47 |
48 | (defun ac-inf-ruby-prefix ()
49 | "Return starting position of completion prefix."
50 | (and inf-ruby-at-top-level-prompt-p
51 | (car (inf-ruby-completion-bounds-of-expr-at-point))))
52 |
53 | (defun ac-inf-ruby-available ()
54 | "Return t if inf-ruby completions are available, otherwise nil."
55 | (eq 'inf-ruby-mode major-mode))
56 |
57 | (defvar ac-source-inf-ruby
58 | '((available . ac-inf-ruby-available)
59 | (candidates . ac-inf-ruby-candidates)
60 | (symbol . "r")
61 | (prefix . ac-inf-ruby-prefix))
62 | "Auto-complete source for `inf-ruby-mode'.")
63 |
64 | ;;;###autoload
65 | (defun ac-inf-ruby-enable ()
66 | "Add `ac-source-inf-ruby' to `ac-sources' for this buffer."
67 | (make-local-variable 'ac-sources)
68 | (add-to-list 'ac-sources 'ac-source-inf-ruby))
69 |
70 |
71 | (provide 'ac-inf-ruby)
72 |
73 | ;; Local Variables:
74 | ;; indent-tabs-mode: nil
75 | ;; End:
76 |
77 | ;;; ac-inf-ruby.el ends here
78 |
--------------------------------------------------------------------------------