Improve web-mode + smartparens compatibility
This addresses two edge cases: 1. if web-mode-auto-close-style == 3, <'s behavior may insert an extra > 2. Some web-mode engines have pairs that end with smartparens pairs, which will result in web-mode inserting its closing pairs _and_ smartparens inserting its closing pairs; resulting in extra characters. Reported by @ar1a
This commit is contained in:
parent
c4ec1413dc
commit
8248e80570
1 changed files with 16 additions and 11 deletions
|
@ -19,21 +19,26 @@
|
||||||
web-mode-auto-close-style 2)
|
web-mode-auto-close-style 2)
|
||||||
|
|
||||||
(after! smartparens
|
(after! smartparens
|
||||||
|
(defun +web-is-auto-close-style-3 (_id action _context)
|
||||||
|
(and (eq action 'insert)
|
||||||
|
(eq web-mode-auto-close-style 3)))
|
||||||
|
(sp-local-pair 'web-mode "<" nil :unless '(:add +web-is-auto-close-style-3))
|
||||||
|
|
||||||
;; let smartparens handle these
|
;; let smartparens handle these
|
||||||
(setq web-mode-enable-auto-quoting nil
|
(setq web-mode-enable-auto-quoting nil
|
||||||
web-mode-enable-auto-pairing t)
|
web-mode-enable-auto-pairing t)
|
||||||
;; Remove web-mode auto pairs that end with >, because smartparens autopairs
|
|
||||||
;; them, causing duplicates. Also remove truncated autopairs, like <?p and
|
;; 1. Remove web-mode auto pairs whose end pair starts with a latter
|
||||||
;; hp ?>.
|
;; (truncated autopairs like <?p and hp ?>). Smartparens handles these
|
||||||
|
;; better.
|
||||||
|
;; 2. Strips out extra closing pairs to prevent redundant characters
|
||||||
|
;; inserted by smartparens.
|
||||||
(dolist (alist web-mode-engines-auto-pairs)
|
(dolist (alist web-mode-engines-auto-pairs)
|
||||||
(setcdr alist (delq nil
|
(setcdr alist
|
||||||
(mapcar (lambda (pair)
|
(cl-loop for pair in (cdr alist)
|
||||||
(unless (string-match-p "^[a-z-]" (cdr pair))
|
unless (string-match-p "^[a-z-]" (cdr pair))
|
||||||
(cons (car pair)
|
collect (cons (car pair)
|
||||||
(if (equal (substring (cdr pair) -1) ">")
|
(string-trim-right (cdr pair) "\\(?:>\\|]\\|}\\)+")))))
|
||||||
(substring (cdr pair) 0 -1)
|
|
||||||
(cdr pair)))))
|
|
||||||
(cdr alist)))))
|
|
||||||
(setf (alist-get nil web-mode-engines-auto-pairs) nil))
|
(setf (alist-get nil web-mode-engines-auto-pairs) nil))
|
||||||
|
|
||||||
(map! :map web-mode-map
|
(map! :map web-mode-map
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue