# Help testing Julia tree-sitter mode in Emacs

**URL:** https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819
**Category:** Tooling
**Created:** [January 11, 2023, 7:06pm UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819 "2023-01-11T19:06:15Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [January 11, 2023, 7:06pm UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/1 "2023-01-11T19:06:15Z")

</div>

Hi!

I, together with @Elrod, @non-Jedi, and @Tamas_Papp, are developing a new Julia major mode for Emacs powered by tree-sitter, using the already available Julia grammar here: [GitHub - tree-sitter/tree-sitter-julia: Julia grammar for Tree-sitter](https://github.com/tree-sitter/tree-sitter-julia)

It will improve things, allowing us to fix old bugs that a regex-based parser will never be capable of.

The basic functionality is already implemented. We now need more people to try it out and report bugs or bad behavior (there should be many!).

We are discussing the implementation here: [use tree-sitter · Issue #174 · JuliaEditorSupport/julia-emacs · GitHub](https://github.com/JuliaEditorSupport/julia-emacs/issues/174)

And the package can be obtained here: [GitHub - ronisbr/julia-ts-mode: Experimental Emacs Julia major mode using tree-sitter](https://github.com/ronisbr/julia-ts-mode)

Notice that it requires Emacs 29, which has native tree-sitter support.

---

<div class="post-metadata">

### Author: ![non-Jedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-jedi/32/3645_2.png) [@non-Jedi](https://discourse.julialang.org/u/non-Jedi)
#### Post date: [January 12, 2023, 3:09pm UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/2 "2023-01-12T15:09:25Z")

</div>

This is a very cool effort which has the potential to solve a large number of long-standing bugs in `julia-mode` as well as providing features that the mode hasn’t even attempted like structural navigation (although I don’t think this is setup yet). I encourage anyone who’s remotely interested to give it a try. Huge props to @Ronis_BR for pushing this forward and rapidly working out kinks as well as to the several people who’ve written the tree-sitter-julia grammar (@savq, @maxbrunsfeld, @pfitzseb, [as well as several others](https://github.com/tree-sitter/tree-sitter-julia/commits/master) who don’t appear to have discourse accounts)!

(I will note in passing that @Ronis_BR is giving me far too much credit here; my contribution has been the programming equivalent of backseat driving)

---

<div class="post-metadata">

### Author: ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)
#### Post date: [January 13, 2023, 11:15am UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/3 "2023-01-13T11:15:02Z")

</div>

> [@non-Jedi](#):
>
> my contribution has been the programming equivalent of backseat driving

And mine was merely sitting in the backseat, going along for the ride. Great work!  
I think the Julia experience in emacs is excellent thanks to your work!

As an example I [enjoyed recently](https://app.codecov.io/gh/chriselrod/RecursiveTupleMath.jl), a little bit of code (and a few dependencies like `TestEnv.jl`):

```elisp
(use-package cov)
(defun maybe-cov-mode ()
  "activate cov-mode if the project root contains a coverage file
  currently, the recognized coverage filenames are:
    coverage-final.json
    coverage-lcov.info file"
  (if (or (file-exists-p (expand-file-name "coverage-final.json" (project-root (project-current))))
          (file-exists-p (expand-file-name "coverage-lcov.info" (project-root (project-current)))))
      (cov-mode)))
(add-hook 'prog-mode-hook #'maybe-cov-mode)
(defun project-abs-path ()
  (expand-file-name (project-root (project-current))))
(defun julia-runtest()
  (let* ((julia-project (project-abs-path))
         (lcov-file (concat julia-project "coverage-lcov.info")))
    (setq-local
     cov-lcov-file-name lcov-file
     compile-command
     (concat "julia --startup=no --history-file=no "
             " --project=" julia-project
             " --code-coverage=@" julia-project "src "
             " --code-coverage=" lcov-file " -tauto "
             " -e'import TestEnv; TestEnv.activate(); "
             " include(\"test/runtests.jl\")'"))))

```

allow me to run a package’s test suite with a keybinding (`C-x p c` – the standard compile-project keybinding), and then get the code coverage to display on the left fringe next to the code, so I can immediately see what is and isn’t covered.

All the standard IDE features like jump to definition and linting work well. If anyone is on the fence about giving emacs a try, I’d say it is well worth it in the long run.

---

<div class="post-metadata">

### Author: ![nandoconde](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nandoconde/32/19497_2.png) [@nandoconde](https://discourse.julialang.org/u/nandoconde)
#### Post date: [January 13, 2023, 1:08pm UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/4 "2023-01-13T13:08:44Z")

</div>

When the release comes, it’d be good to add it officially to [Tree-sitter｜Introduction](https://tree-sitter.github.io/tree-sitter/)

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [January 13, 2023, 2:50pm UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/5 "2023-01-13T14:50:50Z")

</div>

I think we could add it already. The Julia parser ([GitHub - tree-sitter/tree-sitter-julia: Julia grammar for Tree-sitter](https://github.com/tree-sitter/tree-sitter-julia)) is in very good shape! There is some rough edges, but they are minor. In fact, I think that the current state of the Julia grammar is already much better than we had in the regex-based approach in both Vim and Emacs.

---

<div class="post-metadata">

### Author: ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)
#### Post date: [January 14, 2023, 3:22am UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/6 "2023-01-14T03:22:51Z")

</div>

> [@Ronis\_BR](#):
>
> Notice that it requires Emacs 29, which has native tree-sitter support.

Emacs v29 has not even been released yet. Is your mode really not usable with the version of tree-sitter available from Melpa for ordinary Emacs users?

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [January 14, 2023, 4:45am UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/7 "2023-01-14T04:45:08Z")

</div>

Hi @Ralph_Smith !

Unfortunately, no. The implementations seem very different from each other.

---

<div class="post-metadata">

### Author: ![joeldahne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joeldahne/32/45861_2.png) [@joeldahne](https://discourse.julialang.org/u/joeldahne)
#### Post date: [January 14, 2023, 3:37pm UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/8 "2023-01-14T15:37:56Z")

</div>

This looks great!

Unfortunately I’m still on Emacs 28, otherwise I would try it out directly. When I do make the switch I’ll take a closer look at it!

---

<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 14, 2023, 4:23pm UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/9 "2023-01-14T16:23:08Z")

</div>

Thanks for mentioning me, but I didn’t contribute a much (yet). I think this will solve most of our parsing problems though in julia-mode.

---

<div class="post-metadata">

### Author: ![DOT](https://avatars.discourse-cdn.com/v4/letter/d/dc4da7/32.png) [@DOT](https://discourse.julialang.org/u/DOT)
#### Post date: [January 14, 2023, 4:27pm UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/10 "2023-01-14T16:27:04Z")

</div>

Unfortunately, I cannot switch to pre-release Emacs 29, but I’d like to say: Thanks for making Julia work great with Emacs!!

Emacs may be the Mick Jagger of software, but – it rocks! 😀

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [January 14, 2023, 4:54pm UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/11 "2023-01-14T16:54:09Z")

</div>

> [@DOT](#):
>
> Emacs may be the Mick Jagger of software, but – it rocks! 😀

LOL! 🙂 Indeed, I was using Neovim until mid-2022 I think? I switched to Neovim from Emacs because from the user point of view, Emacs development seems stalled, whereas Neovim was advancing very fast.

I could not be more wrong. Emacs 29 is just an incredible work! Tree-sitter, native compilation, LSP, etc.

* * *

By the way, for those how want to see how the new mode looks like, here is a picture with all highlighting (this is not the default):

 ![Captura de Tela 2023-01-14 às 13.52.36](https://global.discourse-cdn.com/julialang/original/3X/2/1/21225616f90c063f1015d3fa325fbcd591969d63.png)

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [January 15, 2023, 6:20pm UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/12 "2023-01-15T18:20:20Z")

</div>

Have considered submitting it to [MELPA](https://melpa.org)? That’d make installation for users much easier, it could be easily automated with [`use-package`](https://github.com/jwiegley/use-package) for example.

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [January 15, 2023, 9:42pm UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/13 "2023-01-15T21:42:15Z")

</div>

Hi @giordano !

I am still not sure if this should be a separate package or if we should merge with Julia-mode. Ideas?

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [January 15, 2023, 9:49pm UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/14 "2023-01-15T21:49:53Z")

</div>

It can be a separate package for the time being, when it matures enough it can be merged into the “standard” `julia-mode` and removed from MELPA (they aren’t picky like the General registry about removal of packages). I don’t see any reasons for not having your package in MELPA right now, it’d only make adoption easier.

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [January 15, 2023, 10:17pm UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/15 "2023-01-15T22:17:12Z")

</div>

I finally tried it. A couple of quick comments:

- C-x n d (`narrow-to-defun`) works properly! It’s very broken in the standard `julia-mode` for functions spanning over more than a few lines. I presume it’s because scanning for the function boundaries fails, but I never had similar problems with long functions in any other language modes, I’m glad this works with this tree-sitter-based mode
- one-line function definitions like `f() = nothing` aren’t found by `imenu` (this is also shared with standard `julia-mode`).

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [January 16, 2023, 12:45am UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/16 "2023-01-16T00:45:11Z")

</div>

Ok! I will register it then 🙂

Thanks for the feedback. I will investigate why that function does not show in imenu.

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [January 16, 2023, 1:25pm UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/17 "2023-01-16T13:25:42Z")

</div>

> [@giordano](#):
>
> one-line function definitions like `f() = nothing` aren’t found by `imenu` (this is also shared with standard `julia-mode`).

It should be working now, can you please test? The problem was that the tree-sitter grammar differentiates a “normal” function definition from a short function definition.

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [January 16, 2023, 1:34pm UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/18 "2023-01-16T13:34:11Z")

</div>

It seems to work now, thanks!

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [January 23, 2023, 5:13pm UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/19 "2023-01-23T17:13:08Z")

</div>

And we are on MELPA now 🙂

---

<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: [February 1, 2023, 10:57am UTC](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819/20 "2023-02-01T10:57:25Z")

</div>

Tree-sitter will give us

> **[Combobulate: Structured Movement and Editing with Tree-Sitter](https://www.masteringemacs.org/article/combobulate-structured-movement-editing-treesitter)**
>
> Combobulate is a package that adds advanced structured editing and movement to many programming modes in Emacs. Here's how it works, and how it can enrich your editing experience in Emacs.

[Next page](https://discourse.julialang.org/t/help-testing-julia-tree-sitter-mode-in-emacs/92819.md?page=2)
