From 48d546c561f3c780379597de559407a4312e3241 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Wed, 16 Oct 2024 16:56:08 -0700 Subject: [PATCH] Some evil-cp work --- init.el | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/init.el b/init.el index 831a77f..e114b0b 100644 --- a/init.el +++ b/init.el @@ -448,7 +448,31 @@ directory. Otherwise, run `find-file' on that file." (if (member major-mode '(lisp-mode emacs-lisp-mode lisp-interaction-mode)) (evil-cleverparens-mode 1) - (electric-pair-local-mode 1)))) + (electric-pair-local-mode 1))) + (defun my/inside-bound-p (beg end bounds) + "Return non-nil if BEG and END are inside BOUNDS. +BOUNDS should be either nil, in which case this will return nil, or a cons cell +of the form (bound-start . bound-end)" + (when bounds + (cl-destructuring-bind (bs . be) bounds + (and (>= beg bs) (<= beg be) + (>= end bs) (<= end be))))) + (defun my/-fix-evil-cp-delete (oldfun beg end type register yank-handler) + "Make `evil-cp-delete' fall back to `evil-delete' if we are inside a +string." + (if (my/inside-bound-p beg end (bounds-of-thing-at-point 'string)) + (funcall 'evil-delete beg end type register yank-handler) + (funcall oldfun beg end type register yank-handler))) + (defun my/-fix-evil-cp-delete-char-or-splice + (oldfun beg end type register yank-handler) + "Make `evil-cp-delete' fall back to `evil-delete' if we are inside a +string." + (if (my/inside-bound-p beg end (bounds-of-thing-at-point 'string)) + (funcall 'evil-delete-char beg end type register) + (funcall oldfun beg end type register yank-handler))) + (advice-add 'evil-cp-delete) + (advice-add 'evil-cp-delete-char-or-splice :around + 'my/-fix-evil-cp-delete-char-or-splice)) ;; make lisp editing nicer (use-package aggressive-indent