# Irb Tab completion problem in Emacs

**URL:** <https://rubytalk.org/t/irb-tab-completion-problem-in-emacs/74400>\
**Category:** ruby-talk\
**Created:** [20 November 2017 16:30 UTC](https://rubytalk.org/t/irb-tab-completion-problem-in-emacs/74400 "2017-11-20T16:30:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicola\_Mingotti](https://avatars.discourse-cdn.com/v4/letter/n/f05b48/32.png) [@Nicola\_Mingotti](https://rubytalk.org/u/Nicola_Mingotti)\
**Post date:** [20 November 2017 16:30 UTC](https://rubytalk.org/t/irb-tab-completion-problem-in-emacs/74400/1 "2017-11-20T16:30:33Z")

</div>

Hi everyone,

I just installed Ruby 2.4.2 from source.  
and I am using Emacs 24.4.1 in Debian 8.9.

If I run irb in xterm, then Tab-completion \*works\*.

If i run irb in an Emacs shell with "M-x shell", then Tab-completion \*does not work\*.

If I run irb in an Emacs shell with "M-x ansi-term", then Tab-completion \*works\*.

I would like to be able to use irb in Emacs "M-x shell" because  
there it is easy to move and copy/paste code.

Do you know how to achieve this ?

I prefer to use an Emacs shell over installing a specialized ".el" just for Ruby.  
Because Emacs + "M-x shell" + "isend-mode" is what I use for all other programming languages  
having a REPL .

Bye  
Nicola

---

<div class="post-metadata">

**Author:** ![Ryan\_Davis1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/ryan_davis1/32/1848_2.png) [@Ryan\_Davis1](https://rubytalk.org/u/Ryan_Davis1)\
**Post date:** [28 November 2017 20:46 UTC](https://rubytalk.org/t/irb-tab-completion-problem-in-emacs/74400/2 "2017-11-28T20:46:45Z")

</div>

> Hi everyone,
> 
> I just installed Ruby 2.4.2 from source.  
> and I am using Emacs 24.4.1 in Debian 8.9.
> 
> If I run irb in xterm, then Tab-completion \*works\*.
> 
> If i run irb in an Emacs shell with "M-x shell", then Tab-completion \*does not work\*.
> 
> If I run irb in an Emacs shell with "M-x ansi-term", then Tab-completion \*works\*.
> 
> I would like to be able to use irb in Emacs "M-x shell" because  
> there it is easy to move and copy/paste code.

This is more of an emacs question than a ruby one… that said, define “works”… Tab is doing what emacs is programmed to do.

Fire up `M-x shell RET`, then run irb. At the prompt, type “C-h k TAB” (describe-key) and you’ll see what it is bound to. For me, that’s:

> TAB (translated from \<tab\>) runs the command completion-at-point  
> (found in shell-mode-map), which is an interactive compiled Lisp  
> function in ‘minibuffer.el’.
> 
> It is bound to TAB, \<menu-bar\> \<completion\> \<complete\>.
> 
> (completion-at-point)
> 
> Perform completion on the text around point.  
> The completion method is determined by ‘completion-at-point-functions’.

which is an emacs function. If you click on the hyperlinked “minibuffer.el” you’ll jump to the source and can poke around… basically, this is running an \*emacs\* completion, rather than sending a tab to irb.

You might want to look into using the `inf-ruby` library. For me, TAB is still bound to the same function, but it is running in inf-ruby-mode instead of shell-mode so it’ll be less intrusive to bind TAB to something raw or specific to inf-ruby.

inf-ruby-mode (the function) has doco that says:

> `TAB' completes the input at point. IRB, Pry and Bond completion is supported.

Looks like you want to look at `inf-ruby-completions` and `inf-ruby-completion-at-point`.

> **···**
>
> > On Nov 20, 2017, at 08:30, Nicola Mingotti \<nmingotti@gmail.com\> wrote:

---

<div class="post-metadata">

**Author:** ![Nicola\_Mingotti](https://avatars.discourse-cdn.com/v4/letter/n/f05b48/32.png) [@Nicola\_Mingotti](https://rubytalk.org/u/Nicola_Mingotti)\
**Post date:** [28 November 2017 22:21 UTC](https://rubytalk.org/t/irb-tab-completion-problem-in-emacs/74400/3 "2017-11-28T22:21:29Z")

</div>

Thank you a lot for the very detailed explanation !

I will do some experiments as soon as i can

Bye  
Nicola

> **···**
>
> On 28/11/2017 21:46, Ryan Davis wrote:
> 
> > > On Nov 20, 2017, at 08:30, Nicola Mingotti \<nmingotti@gmail.com\> wrote:
> > > 
> > > Hi everyone,
> > > 
> > > I just installed Ruby 2.4.2 from source.  
> > > and I am using Emacs 24.4.1 in Debian 8.9.
> > > 
> > > If I run irb in xterm, then Tab-completion \*works\*.
> > > 
> > > If i run irb in an Emacs shell with "M-x shell", then Tab-completion \*does not work\*.
> > > 
> > > If I run irb in an Emacs shell with "M-x ansi-term", then Tab-completion \*works\*.
> > > 
> > > I would like to be able to use irb in Emacs "M-x shell" because  
> > > there it is easy to move and copy/paste code.
> > 
> > This is more of an emacs question than a ruby one… that said, define “works”… Tab is doing what emacs is programmed to do.
> > 
> > Fire up `M-x shell RET`, then run irb. At the prompt, type “C-h k TAB” (describe-key) and you’ll see what it is bound to. For me, that’s:
> > 
> > > TAB (translated from \<tab\>) runs the command completion-at-point  
> > > (found in shell-mode-map), which is an interactive compiled Lisp  
> > > function in ‘minibuffer.el’.
> > > 
> > > It is bound to TAB, \<menu-bar\> \<completion\> \<complete\>.
> > > 
> > > (completion-at-point)
> > > 
> > > Perform completion on the text around point.  
> > > The completion method is determined by ‘completion-at-point-functions’.
> > 
> > which is an emacs function. If you click on the hyperlinked “minibuffer.el” you’ll jump to the source and can poke around… basically, this is running an \*emacs\* completion, rather than sending a tab to irb.
> > 
> > You might want to look into using the `inf-ruby` library. For me, TAB is still bound to the same function, but it is running in inf-ruby-mode instead of shell-mode so it’ll be less intrusive to bind TAB to something raw or specific to inf-ruby.
> > 
> > inf-ruby-mode (the function) has doco that says:
> > 
> > > `TAB' completes the input at point. IRB, Pry and Bond completion is supported.
> > 
> > Looks like you want to look at `inf-ruby-completions` and `inf-ruby-completion-at-point`.
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);
