From 65dd7b39676122d3e8fc6c16cf3ca6bc894515c0 Mon Sep 17 00:00:00 2001 From: Madeleine Sydney Date: Wed, 15 Jan 2025 00:38:01 -0700 Subject: [PATCH] feat: Add Smartparens --- README.org | 2 + users/crumb/programs/emacs/init.el | 1 + .../programs/emacs/modules/syd-smartparens.el | 55 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 users/crumb/programs/emacs/modules/syd-smartparens.el diff --git a/README.org b/README.org index eb8a53f..6f838d0 100755 --- a/README.org +++ b/README.org @@ -135,6 +135,8 @@ As with the rest of the config, these are largely adapted from Doom's ([cite:@li - ~syd-«NAME»-initialise~, where ~modules/«NAME» ∈ modules/*.el~ :: Instead of using top-level side-effects, (bar e.g. ~use-package~ invocations) should be wrapped in this kind of initialisation procedure. +- ~«NAME»-h~ :: Procedure defined specifically to be added to a hook. + * Tasks ** Begin setting up doomless Emacs diff --git a/users/crumb/programs/emacs/init.el b/users/crumb/programs/emacs/init.el index 7dfb9a8..88f4043 100644 --- a/users/crumb/programs/emacs/init.el +++ b/users/crumb/programs/emacs/init.el @@ -17,4 +17,5 @@ (require 'syd-display-startup-time) (require 'syd-evil) (require 'syd-keybinds) +(require 'syd-smartparens) (require 'syd-ui) diff --git a/users/crumb/programs/emacs/modules/syd-smartparens.el b/users/crumb/programs/emacs/modules/syd-smartparens.el new file mode 100644 index 0000000..827187d --- /dev/null +++ b/users/crumb/programs/emacs/modules/syd-smartparens.el @@ -0,0 +1,55 @@ +;;; syd-smartparens.el -*- lexical-binding: t; -*- + +;; Smartparens, most importantly to me, automatically closes opened delimiters. +;; It additionally offers a lot of Paredit-like functionality, but we do not yet +;; use any of it. +;; FIXME: If the first buffer visited is the eval minibuffer, smartparens is not +;; activated. +(use-package smartparens + :hook (on-first-buffer . smartparens-global-mode) + :custom + ;; Overlays are too distracting and not terribly helpful. show-parens does + ;; this for us already (and is faster), so... + ((sp-highlight-pair-overlay nil) + (sp-highlight-wrap-overlay nil) + (sp-highlight-wrap-tag-overlay nil) + + ;; The default is 100. because smartparen's scans are relatively expensive + ;; (especially with large pair lists for some modes), we reduce it, as a + ;; better compromise between performance and accuracy. + (sp-max-prefix-length 25) + + ;; No pair has any business being longer than 4 characters; if they must, set + ;; it buffer-locally. It's less work for smartparens. + (sp-max-pair-length 4)) + :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 +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))) + + (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 +`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) + + ;; You're likely writing lisp in the minibuffer, therefore, disable these + ;; quote pairs, which lisps doesn't use for strings: + (sp-local-pair '(minibuffer-mode minibuffer-inactive-mode) "'" nil :actions nil) + (sp-local-pair '(minibuffer-mode minibuffer-inactive-mode) "`" nil :actions nil)) + +(provide 'syd-smartparens)