# Is there any completion plugin for Emacs?

**URL:** <https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758>\
**Category:** Tooling\
**Tags:** emacs\
**Created:** [September 10, 2018, 8:57am UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758 "2018-09-10T08:57:25Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![sheepduke](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@sheepduke](https://discourse.julialang.org/u/sheepduke)\
**Post date:** [September 10, 2018, 8:57am UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758/1 "2018-09-10T08:57:25Z")

</div>

Hi there,

The Julia REPL is really awesome, quiet comparable to what Common Lisp has.

However the code completion tool is rather weak compared with SLIME.

I wonder if there is any existing (or ongoing) code completion for Emacs users?  
(Company only completes built-in functions that is a little bit weak.)

Any clues? Thanks!

---

<div class="post-metadata">

**Author:** ![zweiglimmergneis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zweiglimmergneis/32/7892_2.png) [@zweiglimmergneis](https://discourse.julialang.org/u/zweiglimmergneis)\
**Post date:** [September 10, 2018, 10:38am UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758/2 "2018-09-10T10:38:32Z")

</div>

Thanks for pointing me to Company. I use `dabbrev-expand` (part of GNU Emacs) with the following key-binding:

```julia
(local-set-key (kbd "S-SPC") 'dabbrev-expand)

```

Emacs expands every word found in the current and also in other buffers according to your customization. I find it very useful.

---

<div class="post-metadata">

**Author:** ![gdkrmr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdkrmr/32/2791_2.png) [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)\
**Post date:** [September 10, 2018, 12:01pm UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758/3 "2018-09-10T12:01:40Z")

</div>

you can use `lsp-julia` with `company`. `lsp-julia` uses `LanguageServer.jl` which is not yet available for julia 0.7/1.0.

[https://github.com/non-Jedi/lsp-julia](https://github.com/non-Jedi/lsp-julia)

---

<div class="post-metadata">

**Author:** ![sheepduke](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@sheepduke](https://discourse.julialang.org/u/sheepduke)\
**Post date:** [September 10, 2018, 12:32pm UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758/4 "2018-09-10T12:32:55Z")

</div>

> [@zweiglimmergneis](#):
>
> I use `dabbrev-expand` (part of GNU Emacs) with the following key-binding:

Well, `company` does work with `dabbrev` source…However it is really far from satisfying.

Considering the quality of Julia’s REPL, it is really a pity not to have a matching completion framework.

By the way, does Julia have completion back-end anyway?  
I think it would be really nice to have a completion back-end that can be used by various completion front-end, so that we have a uniformed completion framework for atom, Emacs, Vim etc etc etc.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [September 10, 2018, 12:50pm UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758/5 "2018-09-10T12:50:42Z")

</div>

> [@sheepduke](#):
>
> I think it would be really nice to have a completion back-end that can be used by various completion front-end, so that we have a uniformed completion framework for atom, Emacs, Vim etc etc etc.

As far as I’m aware, that is what LanguageServer.jl is all about.

---

<div class="post-metadata">

**Author:** ![Andrea\_Pagnani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrea_pagnani/32/3136_2.png) [@Andrea\_Pagnani](https://discourse.julialang.org/u/Andrea_Pagnani)\
**Post date:** [September 10, 2018, 12:55pm UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758/6 "2018-09-10T12:55:03Z")

</div>

> [@zweiglimmergneis](#):
>
> (local-set-key (kbd “S-SPC”) 'dabbrev-expand)

I would already be satisfied to have something that works only for `emacs`. In particular I would really like to bind the completion with `tab`. Unfortunately, to the best of my knowledge and after some negative empirical test, this does not seem to be doable.

Also, periodically I google `emacs completion (\pm julia)` and typically I don’t fill any wiser. The `lsp-julia` using `LanguageServer.jl` seems interesting. Looking forward the 0.7/1.0 compatibility.

However, my ideal solution would be to embed a (possibly minimal) version of autocompletion into [julia-emacs](https://github.com/JuliaEditorSupport/julia-emacs).

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 10, 2018, 1:11pm UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758/7 "2018-09-10T13:11:07Z")

</div>

I have thought about this when writing `julia-repl`, and we discussed this recently [in an issue](https://github.com/tpapp/julia-repl/issues/33). If someone wants to take up the Julia side (having a background process running which one can query about the names in, say, `Main` of the actual inferior process), then I am happy to help with the Emacs part.

---

<div class="post-metadata">

**Author:** ![sheepduke](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@sheepduke](https://discourse.julialang.org/u/sheepduke)\
**Post date:** [September 11, 2018, 3:22am UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758/8 "2018-09-11T03:22:04Z")

</div>

> [@Andrea\_Pagnani](#):
>
> I would already be satisfied to have something that works only for `emacs` . In particular I would really like to bind the completion with `tab` . Unfortunately, to the best of my knowledge and after some negative empirical test, this does not seem to be doable.

Tab completion in Emacs is doable, but a little bit tricky.

You may have a look at function `completion-at-point-functions` that might give you some clues.

I personally wrapped my own completion function as below.

```emacs
  (defun complete-or-indent ()
	"Complete using company-mode or indent current line by checking "
	(interactive)
	(cond
	 ;; When in region, indent the region.
	 ((use-region-p)
	  (indent-region (region-beginning) (region-end)))
	 ;; When yasnippet is active, move to next field.
	 ((yas-active-snippets)
	  (yas-next-field))
	 ;; When it is possible to complete, do it.
	 ((and (string-match-p company-begin-regex (char-to-string (char-before)))
           (call-when-defined 'company-manual-begin))
	  (call-when-defined 'company-complete-common))
	 (t (indent-for-tab-command))))

```

I bind it to `<tab>` key in `company-mode`. Since I am using company and yasnippet, you may modify the code accordingly…

May it be helpful. 😃

---

<div class="post-metadata">

**Author:** ![sheepduke](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@sheepduke](https://discourse.julialang.org/u/sheepduke)\
**Post date:** [September 11, 2018, 3:26am UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758/9 "2018-09-11T03:26:28Z")

</div>

> [@Tamas\_Papp](#):
>
> have thought about this when writing `julia-repl` , and we discussed this recently [in an issue](https://github.com/tpapp/julia-repl/issues/33). If someone wants to take up the Julia side (having a background process running which one can query about the names in, say, `Main` of the actual inferior process), then I am happy to help with the Emacs part.

You may have a look at completion facility of Common Lisp or Clojure, which I think is really powerful.

I always imagine that there would be a similar tool for Julia.

I would like to help, but do not know exactly where to start… 😉

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 11, 2018, 5:50am UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758/10 "2018-09-11T05:50:42Z")

</div>

> [@sheepduke](#):
>
> You may have a look at completion facility of Common Lisp or Clojure, which I think is really powerful.

The question is not about whether this is possible, or how to do it. Replicating SLIME or equivalent is a major undertaking, and as I say in the issue, this is not something I have time for at the moment.

---

<div class="post-metadata">

**Author:** ![Andrea\_Pagnani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrea_pagnani/32/3136_2.png) [@Andrea\_Pagnani](https://discourse.julialang.org/u/Andrea_Pagnani)\
**Post date:** [September 11, 2018, 4:50pm UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758/11 "2018-09-11T16:50:43Z")

</div>

Thank you @sheepduke. I tried your solution but I guess I have a deeper problem with company-mode. Indeed it seems that company mode does not understand. So my first question is how make company-mode understand julia.

For instance if I open a `test.jl` file and I try to complete

`printl`

with `M-x company-complete` it tells me `No completion found`. If I `tab` (after the insertion of your lisp function in my `.emacs` file there is no reaction from emacs side.

Perhaps could you tell me how did you set up company-mode? BTW my Company version is 0.9.6 (from a `M-x company-version).  
Thanks in advance!

A

---

<div class="post-metadata">

**Author:** ![sheepduke](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@sheepduke](https://discourse.julialang.org/u/sheepduke)\
**Post date:** [September 12, 2018, 3:31am UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758/12 "2018-09-12T03:31:55Z")

</div>

> [@Andrea\_Pagnani](#):
>
> Thank you @sheepduke. I tried your solution but I guess I have a deeper problem with company-mode. Indeed it seems that company mode does not understand. So my first question is how make company-mode understand julia.
> 
> For instance if I open a `test.jl` file and I try to complete
> 
> `printl`
> 
> with `M-x company-complete` it tells me `No completion found` . If I `tab` (after the insertion of your lisp function in my `.emacs` file there is no reaction from emacs side.
> 
> Perhaps could you tell me how did you set up company-mode? BTW my Company version is 0.9.6 (from a `M-x company-version).  
> Thanks in advance!

Actually we have talked about two questions:

1. How to (in general) setup company-mode and make it work with indention;
2. How to make company-mode work with Julia.

I actually answered the first question.

For the second question…I do not have completion for `printl` either.

The problem is, currently company-mode just does not know Julia. That is why I started this thread…

---

<div class="post-metadata">

**Author:** ![Andrea\_Pagnani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrea_pagnani/32/3136_2.png) [@Andrea\_Pagnani](https://discourse.julialang.org/u/Andrea_Pagnani)\
**Post date:** [September 12, 2018, 8:24am UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758/13 "2018-09-12T08:24:30Z")

</div>

Thanks again @sheepduke for the clarification on the lack of support on company mode.

---

<div class="post-metadata">

**Author:** ![sheepduke](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@sheepduke](https://discourse.julialang.org/u/sheepduke)\
**Post date:** [September 12, 2018, 8:33am UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758/14 "2018-09-12T08:33:54Z")

</div>

> [@Andrea\_Pagnani](#):
>
> Thanks again @sheepduke for the clarification on the lack of support on company mode.

You are welcome. 😃

I will update this thread and let you know when something new happens in the future.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 29, 2019, 5:51pm UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758/15 "2019-11-29T17:51:57Z")

</div>

Have you guys tried Hippie expand? It works very well for me.

---

<div class="post-metadata">

**Author:** ![robblackwell](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robblackwell/32/2720_2.png) [@robblackwell](https://discourse.julialang.org/u/robblackwell)\
**Post date:** [January 8, 2020, 6:52pm UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758/16 "2020-01-08T18:52:27Z")

</div>

I have been experimenting with Swank.jl ([https://github.com/RobBlackwell/Swank.jl](https://github.com/RobBlackwell/Swank.jl)), a Julia back end for SLIME (the Superior Lisp Interaction Mode for Emacs). It has enough features to be usable(ish), but I’d welcome feedback from other Julia / Lisp / Emacs hackers please.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 9, 2020, 10:15am UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758/17 "2020-01-09T10:15:06Z")

</div>

This is very impressive! Thanks for doing this. Being able to use Swank with Julia would be the best solution IMO, and I would be happy to abandon julia-repl in favor of this.

A couple of minor comments:

1. Please consider wrapping up the Emacs side of the code in a package and making it available on MELPA. It would be easier to get updates that way.

2. I suspect some extra code is needed to make the keybindings you list work, is that correct? Is there a minor mode I am missing?

3. The inability to parse function definition boundaries on the Emacs side has been a long standing issue, see [https://github.com/JuliaEditorSupport/julia-emacs/issues/88](https://github.com/JuliaEditorSupport/julia-emacs/issues/88). A solution would benefit all related packages, and unless SLIME somehow helps with this perhaps the best home for it would be julia-emacs.

I will be following this project with interest and hope to contribute. Again: awesome work!

---

<div class="post-metadata">

**Author:** ![gdkrmr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdkrmr/32/2791_2.png) [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)\
**Post date:** [January 9, 2020, 12:26pm UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758/18 "2020-01-09T12:26:11Z")

</div>

Really interesting, I will have to try it out! Do I understand this right that this is meant as a minor mode to `julia-mode` and replaces `julia-repl` but can be used jointly with other minor modes such as `lsp-mode`?

---

<div class="post-metadata">

**Author:** ![nabokjerring](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@nabokjerring](https://discourse.julialang.org/u/nabokjerring)\
**Post date:** [February 18, 2020, 8:36pm UTC](https://discourse.julialang.org/t/is-there-any-completion-plugin-for-emacs/14758/19 "2020-02-18T20:36:24Z")

</div>

Thank you for creating Swank.jl! I have found that your package gives the most consistent user experience when using Julia in Emacs on Windows, compared to julia-repl and jupyter with IJulia. This may be worth highlighting in the readme of the project.

Looking forward to further developments!
