all repos — nixfiles @ bbac413d6d50b3190b9e522ae8754c4bf858c7d8

System and user configuration, managed by nix and home-manager

Emacs: add slash surround pair
Alan Pearce alan@alanpearce.eu
Fri, 10 Jan 2020 12:25:45 +0100
commit

bbac413d6d50b3190b9e522ae8754c4bf858c7d8

parent

8eaf0d14cef48c3aba20c67ad199c1b02e5dcf41

1 files changed, 19 insertions(+), 1 deletions(-)

jump to
M user/emacs/.emacs.d/init.eluser/emacs/.emacs.d/init.el
@@ -323,14 +323,32 @@ :defer 1   :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)