From 95c20919bb69d46e6f44a9e330c78e6f1d4a6a8b Mon Sep 17 00:00:00 2001 From: Allen Li Date: Sun, 26 Jun 2022 02:32:47 -0700 Subject: [PATCH] elec-pair: Fix bug incorrectly hiding syntax-propertize-function Notably, this causes electric-pair-mode to often misbehave in HTML files when pairing angle brackets. --- lisp/elec-pair.el | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el index 964d21f11c..915a6d6333 100644 --- a/lisp/elec-pair.el +++ b/lisp/elec-pair.el @@ -237,16 +237,21 @@ electric-pair--insert (electric-layout-allow-duplicate-newlines t)) (self-insert-command 1))) -(cl-defmacro electric-pair--with-uncached-syntax ((table &optional start) &rest body) +(cl-defmacro electric-pair--with-uncached-syntax ((table &optional start func) &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 #'ignore) +cache is flushed from position START, defaulting to point. +FUNC is an optional function to set to `syntax-propertize-function'." + (declare (debug ((form &optional form form) body)) (indent 1)) + (let ((start-var (make-symbol "start")) + (func-var (make-symbol "func"))) + `(let ((syntax-propertize-function (let ((,func-var ,func)) + (if ,func-var + ,func-var + syntax-propertize-function))) (,start-var ,(or start '(point)))) (unwind-protect (with-syntax-table ,table @@ -272,7 +277,7 @@ electric-pair--syntax-ppss (point))))) (if s-or-c-start (electric-pair--with-uncached-syntax (electric-pair-text-syntax-table - s-or-c-start) + s-or-c-start #'ignore) (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)) @@ -326,7 +331,7 @@ electric-pair--balance-info (condition-case nil (eq (char-after pos) (electric-pair--with-uncached-syntax - (table) + (table (point) (if string-or-comment #'ignore)) (matching-paren (char-before (scan-sexps (point) 1))))) @@ -356,7 +361,8 @@ electric-pair--balance-info (save-excursion (while (not outermost) (condition-case err - (electric-pair--with-uncached-syntax (table) + (electric-pair--with-uncached-syntax + (table (point) (if string-or-comment #'ignore)) (scan-sexps (point) (if (> direction 0) (point-max) (- (point-max)))) -- 2.36.1