Skip to content

nix-community/nix-ts-mode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nix-ts-mode

https://melpa.org/packages/nix-ts-mode-badge.svg https://stable.melpa.org/packages/nix-ts-mode-badge.svg https://img.shields.io/github/actions/workflow/status/nix-community/nix-ts-mode/trunk.yaml.svg?label=Trunk&event=push&branch=trunk

An Emacs major mode for editing Nix expressions, powered by the built-in tree-sitter support in Emacs 29+ and the community-maintained Nix tree-sitter grammar.

Features:

  • Syntax highlighting for all Nix language constructs
  • Semantic distinctions (variables vs properties, function calls vs definitions)
  • 100% tree-sitter-nix grammar coverage
  • Comprehensive tests

Requirements: Emacs 29+ with tree-sitter support, 30.x includes more improvements.

Usage

nix-ts-mode provides comprehensive syntax highlighting and indentation for Nix files. After installing, enable the mode for Nix files like so:

(require 'nix-ts-mode)
(add-to-list 'auto-mode-alist '("\\.nix\\'" . nix-ts-mode))

Or with use-package:

(use-package nix-ts-mode
 :mode "\\.nix\\'")

Maximum Highlighting

For the best syntax highlighting experience with the widest selection of font-lock faces, set the font-lock level to 4 (maximum):

;; Add to your init.el before loading nix-ts-mode
(setq treesit-font-lock-level 4)

This enables:

  • Fine-grained semantic distinctions (variables vs properties)
  • Function parameter highlighting
  • Punctuation and bracket highlighting
  • Complete visual clarity
  • below is a list of what is included at each level
  • test/highlighting-example.nix can be use to see the effects of the levels.

Level 1 (Essential)

  • comment
  • builtin
  • constant

Level 2 (Literals)

  • string
  • path
  • uri

Level 3 (Semantic)

  • number
  • operator
  • definition
  • function-call
  • keyword

Level 4 (Decorative)

  • parameter
  • property
  • variable
  • bracket
  • delimiter
  • ellipses
  • punctuation
  • **paren-base** (override)
  • **parameter-atpattern** (override)
  • error

About

An Emacs major mode for editing Nix expressions, powered by tree-sitter [maintainer=@remi-gelinas]

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  

Contributors 10

Languages