feat: Add Smartparens

This commit is contained in:
Madeleine Sydney
2025-01-15 00:38:01 -07:00
parent 569c630917
commit 65dd7b3967
3 changed files with 58 additions and 0 deletions

View File

@@ -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

View File

@@ -17,4 +17,5 @@
(require 'syd-display-startup-time)
(require 'syd-evil)
(require 'syd-keybinds)
(require 'syd-smartparens)
(require 'syd-ui)

View File

@@ -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)