From a8943c5d67ab506fe8f2de847fe0bacabdcf4225 Mon Sep 17 00:00:00 2001 From: Madeleine Sydney Date: Tue, 4 Mar 2025 03:10:59 -0700 Subject: [PATCH] feat(emacs): Support Nix's ''big quotes'' --- .../emacs/modules/lang/syd-lang-nix.el | 11 +++++++- .../programs/emacs/modules/syd-smartparens.el | 27 +++++++++---------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/users/crumb/programs/emacs/modules/lang/syd-lang-nix.el b/users/crumb/programs/emacs/modules/lang/syd-lang-nix.el index 9bc1408..4698c6a 100644 --- a/users/crumb/programs/emacs/modules/lang/syd-lang-nix.el +++ b/users/crumb/programs/emacs/modules/lang/syd-lang-nix.el @@ -26,6 +26,15 @@ (set-popup-rule! (rx bol "*nixos-options-doc*" eol) :ttl 0 :quit t) (set-repl-handler! 'nix-mode #'syd-nix-open-nix-repl) (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) diff --git a/users/crumb/programs/emacs/modules/syd-smartparens.el b/users/crumb/programs/emacs/modules/syd-smartparens.el index cd9cb2c..8ec2d02 100755 --- a/users/crumb/programs/emacs/modules/syd-smartparens.el +++ b/users/crumb/programs/emacs/modules/syd-smartparens.el @@ -25,29 +25,26 @@ ;; it buffer-locally. It's less work for smartparens. (sp-max-pair-length 4)) :config - ;; load default config + ;; Load default config. (require 'smartparens-config) ;; Silence some harmless but annoying echo-area spam (dolist (key '(:unmatched-expression :no-matching-tag)) (setf (alist-get key sp-message-alist) nil)) - (defun syd-init-smartparens-in-eval-expression-h () - "Enable `smartparens-mode' in the minibuffer for `eval-expression'. This + (syd-add-hook 'eval-expression-minibuffer-setup-hook + (defun syd-init-smartparens-in-eval-expression-h () + "Enable `smartparens-mode' in the minibuffer for `eval-expression'. This includes everything that calls `read--expression', e.g. `edebug-eval-expression' -Only enable it if `smartparens-global-mode' is on." - (when smartparens-global-mode - (smartparens-mode 1))) +It is only enabled it if `smartparens-global-mode' is on." + (when smartparens-global-mode + (smartparens-mode 1)))) - (add-hook 'eval-expression-minibuffer-setup-hook - #'syd-init-smartparens-in-eval-expression-h) - - (defun syd-init-smartparens-in-minibuffer-maybe-h () - "Enable `smartparens' for non-`eval-expression' commands. Only enable + (syd-add-hook 'minibuffer-setup-hook + (defun syd-init-smartparens-in-minibuffer-maybe-h () + "Enable `smartparens' for non-`eval-expression' commands. Only enable `smartparens-mode' if `smartparens-global-mode' is on." - (when (and smartparens-global-mode (memq this-command '(evil-ex))) - (smartparens-mode 1))) - - (add-hook 'minibuffer-setup-hook #'syd-init-smartparens-in-minibuffer-maybe-h) + (when (and smartparens-global-mode (memq this-command '(evil-ex))) + (smartparens-mode 1)))) ;; You're likely writing lisp in the minibuffer, therefore, disable these ;; quote pairs, which lisps doesn't use for strings: