Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Emacs 29 tree sitter mode #89

Open
amusingimpala75 opened this issue Jul 31, 2023 · 4 comments
Open

[Request] Emacs 29 tree sitter mode #89

amusingimpala75 opened this issue Jul 31, 2023 · 4 comments

Comments

@amusingimpala75
Copy link

With Emacs 29.1 being released, Tree Sitter support is now natively in Emacs. However, to use it there needs to be a dedicated major mode extending the base mode. In this case there would need to be a zig-ts-mode. Would that be possible?

@wisonye
Copy link

wisonye commented Aug 17, 2023

With Emacs 29.1 being released, Tree Sitter support is now natively in Emacs. However, to use it there needs to be a dedicated major mode extending the base mode. In this case there would need to be a zig-ts-mode. Would that be possible?

Same issue here, I install the following language grammar libraries:

  ;;
  ;; Configuration for downloading and installing
  ;; tree-sitter language grammars.
  ;;
  (setq treesit-language-source-alist
    '((c "https://github.com/tree-sitter/tree-sitter-c")
      (cpp "https://github.com/tree-sitter/tree-sitter-cpp")
      (zig "https://github.com/maxxnino/tree-sitter-zig")
  )

  ;;
  ;; remap the non-treesitter mode to treesitter mode
  ;;
  (setq major-mode-remap-alist
   '((c-mode . c-ts-mode)
     (cpp-mode . cpp-ts-mode)
     (zig-mode . zig-ts-mode)
    )
  )

Then I saw 812K Aug 17 19:10 libtree-sitter-zig.so* in my ~/.config/emacs/tree-sitter/ folder.

And run (treesit-language-available-p 'zig) return t means install successfully.

Also, I installed zig-mode:

  (use-package zig-mode
    :hook (zig-mode . lsp-deferred)
    :hook (zig-ts-mode . lsp-deferred)
  )

But when I open zig project, there is NO zig-ts-mode there (only got zig-mode)....:(

@nanzhong
Copy link

nanzhong commented Jan 3, 2024

This was also something I was interested in. I took a stab at doing this in my fork on the tree-sitter branch https://github.com/nanzhong/zig-mode/tree/tree-sitter.

On a high level, it refactors the current zig-mode into a generic zig-base-mode and a concrete zig-mode, while introducing a tree-sitter enabled zig-ts-mode that also derives from zig-base-mode. The main purpose of zig-base-mode is to make it possible to share common configuration between the concrete major modes.

At its current state it only makes use of tree-sitter for syntax highlighting, but I plan to work on indentation next, and imenu integration after that.

If this is an appropriate direction, I'd be happy to make a PR once I have tree-sitter based indentation working.

@nanzhong
Copy link

nanzhong commented Jan 4, 2024

I've got an initial version of tree-sitter based indentation working and I've created a PR for feedback and review.

@Doomwhite
Copy link

I've got an initial version of tree-sitter based indentation working and I've created a PR for feedback and review.

I tried using your branch with eglot/lsp-mode, but I can't seem to make it work with zig-ts-mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants