feat(emacs): Support Nix's ''big quotes''

This commit is contained in:
Madeleine Sydney
2025-03-04 03:10:59 -07:00
parent 04a23ded90
commit a8943c5d67
2 changed files with 22 additions and 16 deletions

View File

@@ -26,6 +26,15 @@
(set-popup-rule! (rx bol "*nixos-options-doc*" eol) :ttl 0 :quit t) (set-popup-rule! (rx bol "*nixos-options-doc*" eol) :ttl 0 :quit t)
(set-repl-handler! 'nix-mode #'syd-nix-open-nix-repl) (set-repl-handler! 'nix-mode #'syd-nix-open-nix-repl)
(dolist (c '(?- ?_)) (dolist (c '(?- ?_))
(modify-syntax-entry c "w" nix-mode-syntax-table))) (modify-syntax-entry c "w" nix-mode-syntax-table))
;; Inform Smartparens and Evil-surround of Nix's alternative string syntax.
(with-eval-after-load 'smartparens
(sp-local-pair 'nix-mode "''" "''"))
(syd-add-hook 'nix-mode-hook
(defun syd-nix--configure-evil-surround-h ()
(with-eval-after-load 'evil-surround
(push '(?Q . ("''" . "''"))
evil-surround-pairs-alist)))))
(provide 'syd-lang-nix) (provide 'syd-lang-nix)

View File

@@ -25,29 +25,26 @@
;; it buffer-locally. It's less work for smartparens. ;; it buffer-locally. It's less work for smartparens.
(sp-max-pair-length 4)) (sp-max-pair-length 4))
:config :config
;; load default config ;; Load default config.
(require 'smartparens-config) (require 'smartparens-config)
;; Silence some harmless but annoying echo-area spam ;; Silence some harmless but annoying echo-area spam
(dolist (key '(:unmatched-expression :no-matching-tag)) (dolist (key '(:unmatched-expression :no-matching-tag))
(setf (alist-get key sp-message-alist) nil)) (setf (alist-get key sp-message-alist) nil))
(syd-add-hook 'eval-expression-minibuffer-setup-hook
(defun syd-init-smartparens-in-eval-expression-h () (defun syd-init-smartparens-in-eval-expression-h ()
"Enable `smartparens-mode' in the minibuffer for `eval-expression'. This "Enable `smartparens-mode' in the minibuffer for `eval-expression'. This
includes everything that calls `read--expression', e.g. `edebug-eval-expression' includes everything that calls `read--expression', e.g. `edebug-eval-expression'
Only enable it if `smartparens-global-mode' is on." It is only enabled it if `smartparens-global-mode' is on."
(when smartparens-global-mode (when smartparens-global-mode
(smartparens-mode 1))) (smartparens-mode 1))))
(add-hook 'eval-expression-minibuffer-setup-hook
#'syd-init-smartparens-in-eval-expression-h)
(syd-add-hook 'minibuffer-setup-hook
(defun syd-init-smartparens-in-minibuffer-maybe-h () (defun syd-init-smartparens-in-minibuffer-maybe-h ()
"Enable `smartparens' for non-`eval-expression' commands. Only enable "Enable `smartparens' for non-`eval-expression' commands. Only enable
`smartparens-mode' if `smartparens-global-mode' is on." `smartparens-mode' if `smartparens-global-mode' is on."
(when (and smartparens-global-mode (memq this-command '(evil-ex))) (when (and smartparens-global-mode (memq this-command '(evil-ex)))
(smartparens-mode 1))) (smartparens-mode 1))))
(add-hook 'minibuffer-setup-hook #'syd-init-smartparens-in-minibuffer-maybe-h)
;; You're likely writing lisp in the minibuffer, therefore, disable these ;; You're likely writing lisp in the minibuffer, therefore, disable these
;; quote pairs, which lisps doesn't use for strings: ;; quote pairs, which lisps doesn't use for strings: