Variable: nix-ts-mode--font-lock-settings

nix-ts-mode--font-lock-settings is a variable defined in nix-ts-mode.el.

Value

((#<treesit-compiled-query> t bracket nil nil nix)
 (#<treesit-compiled-query> t comment nil nil nix)
 (#<treesit-compiled-query> t delimiter nil nil nix)
 (#<treesit-compiled-query> t keyword t nil nix)
 (#<treesit-compiled-query> t string t nil nix)
 (#<treesit-compiled-query> t operator nil nil nix)
 (#<treesit-compiled-query> t number nil nil nix)
 (#<treesit-compiled-query> t path nil nil nix)
 (#<treesit-compiled-query> t uri nil nil nix)
 (#<treesit-compiled-query> t parameter nil nil nix)
 (#<treesit-compiled-query> t parameter-atpattern t nil nix)
 (#<treesit-compiled-query> t function-call nil nil nix)
 (#<treesit-compiled-query> t property nil nil nix)
 (#<treesit-compiled-query> t builtin t nil nix)
 (#<treesit-compiled-query> t constant t nil nix)
 (#<treesit-compiled-query> t definition t nil nix)
 (#<treesit-compiled-query> t variable nil nil nix)
 (#<treesit-compiled-query> t paren-base t nil nix)
 (#<treesit-compiled-query> t ellipses nil nil nix)
 (#<treesit-compiled-query> t punctuation nil nil nix)
 (#<treesit-compiled-query> t error t nil nix))

Documentation

Tree-sitter font-lock settings for nix-ts-mode.

Source Code

;; Defined in /nix/store/gfg1ybfpvhh7fr396dh1axr72lcm71n0-emacs-packages-deps/share/emacs/site-lisp/elpa/nix-ts-mode-20260705.1600/nix-ts-mode.el
;; Settings
(defvar nix-ts-mode--font-lock-settings
  (treesit-font-lock-rules
   :language 'nix
   :feature 'bracket
   '(["(" ")" "[" "]" "{" "}"] @font-lock-bracket-face)

   :language 'nix
   :feature 'comment
   '((comment) @font-lock-comment-face)

   :language 'nix
   :feature 'delimiter
   '(["," "." ";"] @font-lock-delimiter-face)

   :language 'nix
   :feature 'keyword
   :override t
   `((let_expression
      (["let" "in"] @font-lock-keyword-face))
     ;; Deprecated let attrset expression (let { body = ...; })
     (let_attrset_expression
      ("let" @font-lock-keyword-face))
     (if_expression
      ["if" "then" "else"] @font-lock-keyword-face)
     (rec_attrset_expression
      ("rec" @font-lock-keyword-face))
     (with_expression
      ("with" @font-lock-keyword-face))
     (inherit
      ("inherit" @font-lock-keyword-face))
     (inherit_from
      ("inherit" @font-lock-keyword-face))
     (assert_expression
      ("assert" @font-lock-keyword-face))
     ;; Special keywords: throw, abort, import
     ((variable_expression name: (identifier) @font-lock-keyword-face)
      (:match
       ,(rx-to-string
         `(seq bol (or "throw" "abort" "import")
           eol))
       @font-lock-keyword-face))

     ;; "or" is technically an operator, but we fontify it as a keyword
     (select_expression
      ("or" @font-lock-keyword-face)))

   :language 'nix
   :feature 'string
   :override t
   `((string_fragment) @font-lock-string-face
     (string_expression
      ("\"" @font-lock-string-face))
     (indented_string_expression
      ("''" @font-lock-string-face))
     ;; Escape sequences in strings
     (escape_sequence) @font-lock-escape-face
     ;; Dollar escape in indented strings (''$)
     (dollar_escape) @font-lock-escape-face
     (interpolation
      (["${" "}"] @font-lock-punctuation-face)))

   :language 'nix
   :feature 'operator
   `((binary_expression operator: _ @font-lock-operator-face)
     (unary_expression operator: _ @font-lock-operator-face)
     ;; has_attr_expression (x ? y to test if attribute exists)
     (has_attr_expression operator: _ @font-lock-operator-face)
     ;; @ and ? operators
     ["@" "?" "="] @font-lock-operator-face)

   :language 'nix
   :feature 'number
   `([(integer_expression) (float_expression)] @font-lock-number-face)

   :language 'nix
   :feature 'path
   `(;; Regular paths
     (path_expression) @font-lock-constant-face
     ;; Home paths (~/)
     (hpath_expression) @font-lock-constant-face
     ;; Store paths (<nixpkgs>)
     (spath_expression) @font-lock-constant-face)

   :language 'nix
   :feature 'uri
   `((uri_expression) @font-lock-string-face)

   :language 'nix
   :feature 'parameter
   `(;; Function parameters in formals ({ x, y, ... })
     (formal name: (identifier) @font-lock-variable-name-face)
     ;; Universal function parameter (x: body) - simple case without destructuring
     (function_expression
      universal: (identifier) @font-lock-variable-name-face)
     ;; @ pattern operator
     (function_expression
      "@" @font-lock-operator-face))

   ;; At-pattern binding needs override to take precedence over universal parameter
   :language 'nix
   :feature 'parameter-atpattern
   :override t
   `(;; @ pattern identifier - forward order: args@{ x, y }
     ;; Use type-face for visual distinction - it's the "base object" containing all params
     (function_expression
      universal: (identifier) @font-lock-type-face
      "@")
     ;; @ pattern identifier - reverse order: { x, y }@opts
     (function_expression
      "@"
      universal: (identifier) @font-lock-type-face))

   :language 'nix
   :feature 'function-call
   `(;; Function calls: highlight function name in apply_expression
     (apply_expression
      function: (variable_expression
                 name: (identifier) @font-lock-function-call-face))
     ;; Function calls with select_expression (builtins.map, lib.mkOption, etc.)
     (apply_expression
      function: (select_expression
                 attrpath: (attrpath
                            (identifier) @font-lock-function-call-face :anchor))))

   :language 'nix
   :feature 'property
   `(;; Base variable in select expressions - use type-face for visual distinction
     ;; (Nix has no type system, so this face is available and visually distinct)
     (select_expression
      expression: (variable_expression
                   name: (identifier) @font-lock-type-face))
     ;; Property access in select expressions - the MEMBERS (obj.property)
     (select_expression
      attrpath: (attrpath
                 (identifier) @font-lock-property-use-face))
     ;; Binding attributes in attrsets (all identifiers in the path)
     (binding_set
      (binding
       attrpath: (attrpath
                  (identifier) @font-lock-property-name-face)))
     ;; Source in inherit_from - use type-face for visual distinction (inherit (SOURCE) attrs)
     (inherit_from
      (variable_expression
       name: (identifier) @font-lock-type-face))
     ;; Inherited attributes FROM a source (inherit (pkgs) hello) - these are properties
     (inherit_from
      attrs: (inherited_attrs
              (identifier) @font-lock-property-use-face)))

   :language 'nix
   :feature 'builtin
   :override t
   `(;; Builtin functions (standalone)
     (variable_expression name: (identifier) @font-lock-builtin-face
                          (:match
                           ,(rx-to-string
                             `(seq bol (or ,@nix-ts--treesit-builtins)
                               eol))
                           @font-lock-builtin-face))
     ;; Builtin functions with builtins prefix (builtins.map, etc.)
     (select_expression
      expression: (variable_expression
                   name: (identifier) @_builtins
                   (:equal @_builtins "builtins"))
      attrpath: (attrpath
                 attr: (identifier) @font-lock-builtin-face)))

   :language 'nix
   :feature 'constant
   :override t
   `(;; Language constants (boolean)
     (variable_expression name: (identifier) @font-lock-constant-face
                          (:match
                           ,(rx-to-string
                             `(seq bol (or ,@nix-ts--treesit-constants "true" "false")
                               eol))
                           @font-lock-constant-face)))

   :language 'nix
   :feature 'definition
   :override t
   `(;; Function definitions (name = x: y;)
     (binding
      attrpath: (attrpath
                 (identifier) @font-lock-function-name-face :anchor)
      expression: (function_expression)))

   :language 'nix
   :feature 'variable
   `(;; General variable references
     (variable_expression
      name: (identifier) @font-lock-variable-use-face)
     ;; Plain inherit (inherit x y z) - these create NEW variable bindings
     (inherit
      attrs: (inherited_attrs
              (identifier) @font-lock-variable-name-face)))

   :language 'nix
   :feature 'paren-base
   :override t
   `(;; Parenthesized base in select - highlight parens with type-face for visual grouping
     ;; This overrides bracket-face to make the base stand out like simple variable bases
     (select_expression
      expression: (parenthesized_expression
                   ["(" ")"] @font-lock-type-face)))

   :language 'nix
   :feature 'ellipses
   `((ellipses) @font-lock-punctuation-face)

   :language 'nix
   :feature 'punctuation
   `((function_expression
      ":" @font-lock-punctuation-face))

   :language 'nix
   :feature 'error
   :override t
   '((ERROR) @font-lock-warning-face))
  "Tree-sitter font-lock settings for `nix-ts-mode'.")