Getting smartparens wrapping to work in evil-visual-state
Frank Fischer
frank-fischer at shadow-soft.de
Mon Nov 28 15:33:51 CET 2016
On 27.11.2016 14:27, ivan wrote:
> But in evil-visual-state, "(" is bound to evil-backward-sentence-begin.
> The binding originates in evil-motion-state-map, which both normal and
> visual states inherit from. I've tried a few ways to rebind "(" to
> self-insert-command in order to let smartparens do its thing, but so far
> nothing I've tried has worked:
>
> (define-key evil-visual-state-map (kbd "(") 'self-insert-command)
> (define-key evil-motion-state-map (kbd "(") 'self-insert-command)
> (define-key evil-motion-state-map (kbd "(") nil)
> (evil-define-key 'visual evil-visual-state-map (kbd "(")
> 'self-insert-command)
>
> How can I properly configure this?
You probably need to write your own command that inserts both characters
at the beginning and the end of the region. Something like this might work:
(defconst my-pairs-alist '((?( . ?))
(?{ . ?})
(?[ . ?])))
(evil-define-operator my-wrap (beg end type)
(interactive "<R>")
(let* ((ch last-command-event)
(pair (or (assoc ch my-pairs-alist)
(rassoc ch my-pairs-alist))))
;; Other characters a paired literally, e.g. "
(unless pair
(unless (characterp ch)
(user-error "Cannot pair key %s" ch))
(setq pair (cons ch ch)))
(save-excursion
(goto-char end)
(insert-char (cdr pair))
(goto-char beg)
(insert-char (car pair)))))
(define-key evil-visual-state-map "(" 'my-wrap)
(define-key evil-visual-state-map ")" 'my-wrap)
(define-key evil-visual-state-map "[" 'my-wrap)
(define-key evil-visual-state-map "]" 'my-wrap)
(define-key evil-visual-state-map "{" 'my-wrap)
(define-key evil-visual-state-map "}" 'my-wrap)
(define-key evil-visual-state-map "\"" 'my-wrap)
(define-key evil-visual-state-map "'" 'my-wrap)
Bind `my-wrap` to whatever key should be paired. Maybe " or ' are not so
good because this would shadow register and mark access.
Frank
More information about the implementations-list
mailing list