# How to make custom REPL completion?

**URL:** <https://discourse.julialang.org/t/how-to-make-custom-repl-completion/86673>\
**Category:** General Usage\
**Tags:** question, repl, completion\
**Created:** [September 2, 2022, 4:56am UTC](https://discourse.julialang.org/t/how-to-make-custom-repl-completion/86673 "2022-09-02T04:56:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![GHTaarn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ghtaarn/32/216007_2.png) [@GHTaarn](https://discourse.julialang.org/u/GHTaarn)\
**Post date:** [September 2, 2022, 4:56am UTC](https://discourse.julialang.org/t/how-to-make-custom-repl-completion/86673/1 "2022-09-02T04:56:44Z")

</div>

I would like to create a REPL with customised completion behaviour. Is there a tutorial, API documentations or similar about this somewhere?

---

<div class="post-metadata">

**Author:** ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)\
**Post date:** [September 2, 2022, 7:50am UTC](https://discourse.julialang.org/t/how-to-make-custom-repl-completion/86673/2 "2022-09-02T07:50:12Z")

</div>

A while ago I wanted to have case insensitive completions in the REPL, so I also went to look for how to do this. I could not find any real API for it, so the way I went about it was just to overwrite the existing methods with new ones that had the behaviour I was after. Not a very nice solution, but I got it to do pretty much what I wanted and I used it for a while. Not sure if it still works though with more recent julia versions, since internal things might change and I have not made sure it still aligns with the code I copied back then.

But if you are interested to see how I did that you can always have a look and maybe get some inspiration

> **[GitHub - albheim/CaseInsensitiveCompletions.jl](https://github.com/albheim/CaseInsensitiveCompletions.jl)**
>
> Contribute to albheim/CaseInsensitiveCompletions.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [September 2, 2022, 8:05am UTC](https://discourse.julialang.org/t/how-to-make-custom-repl-completion/86673/3 "2022-09-02T08:05:19Z")

</div>

Have you come across [FuzzyCompletions.jl](https://github.com/JunoLab/FuzzyCompletions.jl) already?

---

<div class="post-metadata">

**Author:** ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)\
**Post date:** [September 2, 2022, 9:04am UTC](https://discourse.julialang.org/t/how-to-make-custom-repl-completion/86673/4 "2022-09-02T09:04:02Z")

</div>

That looks much nicer that what I hacked together. Will give it a try 👍

---

<div class="post-metadata">

**Author:** ![Fliks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fliks/32/2494_2.png) [@Fliks](https://discourse.julialang.org/u/Fliks)\
**Post date:** [September 2, 2022, 12:48pm UTC](https://discourse.julialang.org/t/how-to-make-custom-repl-completion/86673/5 "2022-09-02T12:48:15Z")

</div>

There is also an open issue to provide a better API to customize the REPL completions:  
[https://github.com/JuliaLang/julia/issues/44287](https://github.com/JuliaLang/julia/issues/44287)

But I am not sure, whether anybody is currently working on that.

---

<div class="post-metadata">

**Author:** ![GHTaarn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ghtaarn/32/216007_2.png) [@GHTaarn](https://discourse.julialang.org/u/GHTaarn)\
**Post date:** [September 2, 2022, 2:51pm UTC](https://discourse.julialang.org/t/how-to-make-custom-repl-completion/86673/6 "2022-09-02T14:51:22Z")

</div>

Maybe I needed something less complex than other people, but for simple cases I eventually worked my way to:

```julia
using ReplMaker 
import REPL
import REPL.LineEdit.complete_line
import REPL.LineEdit.CompletionProvider

struct GenericCompletionProvider <: CompletionProvider
    f::Function
end

function complete_line(x::GenericCompletionProvider, s)
    firstpart = String(s.input_buffer.data[1:s.input_buffer.ptr-1])
    return ([x.f(firstpart)], firstpart, true)
end

initrepl(println; mode_name=:upper, completion_provider=GenericCompletionProvider(uppercase))

```

If anyone sees any flaws in this, please point them out.
