;;; -*- lexical-binding: t -*-

(require 'syd/base)
(require 'syd/handle)
(require 'syd/popups)

(use-package nix-mode
  ;; :mode "\\.nix\\'"
  :init
  (add-to-list 'auto-mode-alist
               (cons (rx "/flake.lock'")
                     (if (fboundp 'json-mode)
                         'json-mode
                       'js-mode)))
  :config
  ;; (set-repl-handler! '(nix-mode nix-ts-mode) #'syd-nix-open-nix-repl)

  ;; Inform Smartparens and Evil-surround of Nix's alternative string syntax.
  (with-eval-after-load 'smartparens
    (sp-local-pair '(nix-mode nix-ts-mode) "''" "''"))
  (syd-add-hook '(nix-mode-hook nix-ts-mode-hook)
    (defun syd-nix--configure-evil-surround-h ()
      (with-eval-after-load 'evil-surround
        (push '(?Q . ("''" . "''"))
              evil-surround-pairs-alist)))))

(use-package nix-ts-mode
  :config
  ;; (add-to-list 'major-mode-remap-alist `(nix-mode . nix-ts-mode))
  (syd-remap-mode-to-ts 'nix-mode))

(with-eval-after-load 'project
  (add-to-list 'project-vc-extra-root-markers "flake.nix"))

(provide 'syd/nix)
