;;; Code:
(require 'electric)
+(eval-when-compile (require 'cl-lib))
;;; Electric pairing.
(electric-pair-mode nil))
(self-insert-command 1)))
+(cl-defmacro electric-pair--with-uncached-syntax ((table &optional start) &rest body)
+ "Like `with-syntax-table', but flush the syntax-ppss cache afterwards.
+Use this instead of (with-syntax-table TABLE BODY) when BODY
+contains code which may update the syntax-ppss cache. This
+includes calling `parse-partial-sexp' and any sexp-based movement
+functions when `parse-sexp-lookup-properties' is non-nil. The
+cache is flushed from position START, defaulting to point."
+ (declare (debug ((form &optional form) body)) (indent 1))
+ (let ((start-var (make-symbol "start")))
+ `(let ((syntax-propertize-function nil)
+ (,start-var ,(or start '(point))))
+ (unwind-protect
+ (with-syntax-table ,table
+ ,@body)
+ (syntax-ppss-flush-cache ,start-var)))))
+
(defun electric-pair--syntax-ppss (&optional pos where)
"Like `syntax-ppss', but sometimes fallback to `parse-partial-sexp'.
(skip-syntax-forward " >!")
(point)))))
(if s-or-c-start
- (with-syntax-table electric-pair-text-syntax-table
+ (electric-pair--with-uncached-syntax (electric-pair-text-syntax-table
+ s-or-c-start)
(parse-partial-sexp s-or-c-start pos))
;; HACK! cc-mode apparently has some `syntax-ppss' bugs
(if (memq major-mode '(c-mode c++ mode))
(cond ((< direction 0)
(condition-case nil
(eq (char-after pos)
- (with-syntax-table table
+ (electric-pair--with-uncached-syntax
+ (table)
(matching-paren
(char-before
(scan-sexps (point) 1)))))
(save-excursion
(while (not outermost)
(condition-case err
- (with-syntax-table table
+ (electric-pair--with-uncached-syntax (table)
(scan-sexps (point) (if (> direction 0)
(point-max)
(- (point-max))))