Skip to content

A tree-sitter based Emacs major-mode for the Scala programming language

License

Notifications You must be signed in to change notification settings

KaranAhlawat/scala-ts-mode

Repository files navigation

scala-ts-mode

Introduction

scala-ts-mode is a tree-sitter based GNU Emacs major mode built on top of the Emacs 29+ treesit library. It provides the following features in a Scala buffer-

  1. efficient font-locking using tree-sitter
  2. imenu integration
  3. indentation support using tree-sitter

The major-mode is mostly complete and in a very usable state currently. Improvements will come as I find bugs, edge cases, more use cases or the upstream grammar evolves.

Requirements

To use the package, the following dependencies are required.

  1. GNU Emacs 29+, built with support for tree-sitter.
  2. tree-sitter grammar for Scala (you can use the treesit-install-language-grammar function for installing it.)

Installation

To install the package, you can use any Emacs package manager of your choice, to pull the package either from MELPA or source. For example, with straight.el, you can do the following -

MELPA

(straight-use-package 'scala-ts-mode)

Source

(straight-use-package '(scala-ts-mode :type git :host github :repo "KaranAhlawat/scala-ts-mode"))

Then, you can simply call scala-ts-mode in a Scala buffer.

Configuration

You may wish to customize treesit-font-lock-level, using M-x customize-variable or by adding a line such as this to your user init file:

(setq treesit-font-lock-level 4)

The default font lock level is 3. At that level, not as many constructs are highlighted as you might like. Increasing it to 4 results in richer highlighting.

Eglot Setup

Some versions of Emacs aren’t set up with an Eglot that knows which LSP server to use for scala-ts-mode. This code can be in init.el before loading Eglot to tell it to use the same function for scala-ts-mode that it does for scala-mode.

(add-to-list 'eglot-server-programs
             `((scala-mode scala-ts-mode)
                . ,(alist-get 'scala-mode eglot-server-programs)))

Contributions

Contributions are welcome! These can be in the form of PRs, Issues, or any other way you can think of. This is my first package, so please don’t hold back :)

License

GPLv3

About

A tree-sitter based Emacs major-mode for the Scala programming language

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published