inf-elixir icon indicating copy to clipboard operation
inf-elixir copied to clipboard

Tab completion should work

Open cdegroot opened this issue 5 years ago • 7 comments

Currently there's a literal tab inserted. I have no clue how either the Emacs or the IEx side work - I'm gonna dig for a bit but will probably never finish so logging this so someone competent hopefully takes a shot :)

Thanks for creating this, it's pretty much exactly what I was looking for! I'm working on making Emacs super nice for Elixir by hooking up something like https://github.com/rustyio/sync and an automated test runner, and an inferior IEx is the starting point I was missing.

(Seems to be a common issue. https://github.com/fsharp/emacs-fsharp-mode/issues/184 for example)

cdegroot avatar Feb 17 '20 01:02 cdegroot

I have just discovered this issue, and here are a couple of ideas.

You could take a look at company-elixir package on how to produce completion candidates for Elixir. It apparently uses iex -S mix command for inspection, so it may be possible to extract some common parts, but I am not sure how difficult it would be.

You also have to integrate it with the comint buffer. nix-repl.el which is shipped as part of nix-mode.el does this well. It's basically defining a function for completion-at-point-functions.

I don't think I am competent enough to tackle the idea promptly, so I will leave this information to here.

akirak avatar Jul 23 '21 05:07 akirak

Right, there's two issues here:

  1. Sourcing the completions
  2. Providing the completions to whatever comint's completion mechanism is

My general inclination for part 1 is to send a tab character to the REPL process, capture its output and parse it.

I think part 2 is something to do with comint-dynamic-complete-functions and comint-preoutput-filter-functions, but this requires further research and testing.

J3RN avatar Jul 23 '21 15:07 J3RN

Of course, this is a very old thing. I think I was using Spacemacs back then, I switched to Doom in the meantime, which has other issues so I tend to stay away from running IEx inside Emacs completely now ;-).

cdegroot avatar Jul 23 '21 19:07 cdegroot

Thanks for your work on inf-elixir!

Might be worth looking at this implementation for iex in shell-mode that was posted to Elixir slack's emacs channel.

Maybe it's worth a discussion with @jasonmj.

walter avatar Jan 08 '24 03:01 walter

Thanks Walter! Happy to chat more about the approach I've taken here, Jonathan. It's still a bit of a work in progress, but the proof of concept shows viability.

jasonmj avatar Jan 08 '24 12:01 jasonmj

Hey folks, thanks for the tip! This approach seems similar to one that I attempted on the tab-completion branch here on GitHub. Mine is quite buggy, I'm sure yours is much better!

TL;DR: I'm thinking of new approaches for Elixir interaction writ large, but if anyone wants to send a PR I will give it a good-faith review :grin:


The general constraints of the "send IEx.Autocomplete.expand(... to the IEx shell and parse the output" approach (e.g. prompt numbers increment each time completion is performed) and also the limitations mentioned in #17 have got me thinking about taking a fresh approach to an Elixir shell in Emacs; moving towards something a bit more like cider for Clojure over a wrapper around a terminal shell (like iex). Cider interfaces with a language/runtime API (nrepl), and while I don't think there's an nrepl equivalent for Elixir (atm), there's been a lot of work in the Livebook project to provide a REPL-like experience in the browser which could be utilized in such a project.

That said, such a project would be a large undertaking and this project will continue separately because it works and is good enough for many people's use cases. If you'd like to enhance this project, I'm happy to accept those contributions, but for the time being I'll be directing my efforts in another direction.

J3RN avatar Jan 10 '24 15:01 J3RN

Yep, the prompt counter increment is a thing... doesn't seem like a dealbreaker to me, but a specific side effect of this approach. Regarding an approach like cider, I'm all for it! I've used cider in the past and really enjoyed it.

jasonmj avatar Jan 10 '24 15:01 jasonmj