From bbac413d6d50b3190b9e522ae8754c4bf858c7d8 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Fri, 10 Jan 2020 12:25:45 +0100 Subject: Emacs: add slash surround pair --- user/emacs/.emacs.d/init.el | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/user/emacs/.emacs.d/init.el b/user/emacs/.emacs.d/init.el index c425d723..0365b710 100644 --- a/user/emacs/.emacs.d/init.el +++ b/user/emacs/.emacs.d/init.el @@ -323,14 +323,32 @@ _p_rev _u_pper _=_: upper/lower _r_esolve :after evil :config (evil-space-mode +1)) +;; this macro was copied from here: https://stackoverflow.com/a/22418983/4921402 +(defmacro define-and-bind-quoted-text-object (name key start-regex end-regex) + (let ((inner-name (make-symbol (concat "evil-inner-" name))) + (outer-name (make-symbol (concat "evil-a-" name)))) + `(progn + (evil-define-text-object ,inner-name (count &optional beg end type) + (evil-select-paren ,start-regex ,end-regex beg end type count nil)) + (evil-define-text-object ,outer-name (count &optional beg end type) + (evil-select-paren ,start-regex ,end-regex beg end type count t)) + (define-key evil-inner-text-objects-map ,key #',inner-name) + (define-key evil-outer-text-objects-map ,key #',outer-name)))) + (use-package evil-surround :after evil :defer 2 - :config (global-evil-surround-mode +1)) + :config (progn + (define-and-bind-quoted-text-object "slash" "/" "\\/" "\\/") + (push '(?\/ . ("/" . "/")) evil-surround-pairs-alist) + (global-evil-surround-mode +1))) + (use-package evil-embrace :after evil-surround :config (progn + (setq evil-embrace-show-help-p nil) + (push ?\/ evil-embrace-evil-surround-keys) (evil-embrace-enable-evil-surround-integration) (add-hook 'LaTeX-mode-hook #'embrace-LaTeX-mode-hook) (add-hook 'org-mode-hook #'embrace-org-mode-hook) -- cgit 1.4.1