xuchunyang

xuchunyang

How to get code completion in IEx programmatically?

Hi all,

I’m new to Elixir. I’m trying to use IEx in Emacs. Right now the code completion isn’t supported, and I don’t know how to get the completion from Elixir/IEx programmatically, I tried IEx.Autocomplete.expand "String." but it doesn’t work (I expect it to return a list of completions so I can use it from Emacs.):

iex(11)> IEx.Autocomplete.expand "String."
** (FunctionClauseError) no function clause matching in IEx.Autocomplete.expand/2

    The following arguments were given to IEx.Autocomplete.expand/2:

        # 1
        "String."

        # 2
        IEx.Server

    Attempted function clauses (showing 2 out of 2):

        def expand([], server)
        def expand([h | t] = expr, server)

    (iex) lib/iex/autocomplete.ex:6: IEx.Autocomplete.expand/2

Emacs setup:

(define-derived-mode inferior-elixir-mode comint-mode "Inferior Elixir"
  "Major mode for Elixir inferior process."
  (setq comint-prompt-regexp (rx bol (or "iex" "...") "(" (1+ num) ") ")))

(defun run-elixir ()
  (interactive)
  (with-current-buffer (make-comint-in-buffer "Elixir" "*Elixir*" "iex" nil)
    (inferior-elixir-mode)
    (display-buffer (current-buffer))))

Most Liked

axelson

axelson

Scenic Core Team

I think you mean this post: Emacs lsp-mode (language server) + elixir-ls anyone?

And this emacs configuration: Emacs - Elixir Setup Configuration Wiki

It does have some support for autocomplete as well as some other features.

axelson

axelson

Scenic Core Team

I also wanted to note that IEx.Autocomplete is labeled with @moduledoc false which means that it is a private api that shouldn’t be relied upon. It also looks like the functions in IEx.Autocomplete are using a bunch of private modules/functions as well. So I think you may need to raise an issue on the Elixir github to ask for programmatic access to autocomplete.

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

We're in Beta

About us Mission Statement