all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Noam Postavsky <npostavs@users.sourceforge.net>
To: Hariharan Rangasamy <hariharanrangasamy@gmail.com>
Cc: 29710@debbugs.gnu.org, Linus Shoravi <linusshoravi@gmail.com>
Subject: bug#29710: Emacs becomes unresponsive when typing brackets (haskell-mode)
Date: Thu, 14 Dec 2017 21:31:20 -0500	[thread overview]
Message-ID: <871sjwd8nb.fsf@users.sourceforge.net> (raw)
In-Reply-To: <CAM-tV--zJ2bqjO15eyNyKcxaxfXtAxqA60zha1-yTYFYN+B8Ag@mail.gmail.com> (Noam Postavsky's message of "Thu, 14 Dec 2017 14:24:09 -0500")

[-- Attachment #1: Type: text/plain, Size: 282 bytes --]

tags 29710 + patch
quit

Noam Postavsky <npostavs@users.sourceforge.net> writes:

> I can reproduce also in 25.3, not in 24.5. Probably same issue as
> Bug#23443, i.e., electric-pair-mode needs to clear the cache after it
> finishes messing with the syntax table.

Here's a patch:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 3315 bytes --]

From 5b3f0dfb1673617e4646be2be0874b168acc46c4 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Thu, 14 Dec 2017 21:25:13 -0500
Subject: [PATCH v1] Don't mess up syntax-ppss cache in electric-pair
 (Bug#29710)

In Emacs 25 and above, calling `scan-sexps', `parse-partial-sexp', or
similar may update the syntax-ppss cache if
`parse-sexp-lookup-properties' is non-nil.  Therefore, when calling
any of these functions with a different than normal syntax-table, the
cache must be cleaned afterwards.
* lisp/elec-pair.el (electric-pair--with-uncached-syntax): New macro.
(electric-pair--syntax-ppss, electric-pair--balance-info): Use it.
---
 lisp/elec-pair.el | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el
index 7f523d1df4..bdf4bd14b5 100644
--- a/lisp/elec-pair.el
+++ b/lisp/elec-pair.el
@@ -24,6 +24,7 @@
 ;;; Code:
 
 (require 'electric)
+(eval-when-compile (require 'cl-lib))
 
 ;;; Electric pairing.
 
@@ -222,6 +223,18 @@ electric-pair--insert
 	(electric-pair-mode nil))
     (self-insert-command 1)))
 
+(cl-defmacro electric-pair--with-uncached-syntax ((table &optional start-scan) &rest body)
+  "Like `with-syntax-table', but flush the syntax-ppss cache after."
+  ;; See Bug#29710 and Bug#23443.
+  (declare (debug ((form &optional form) body)) (indent 1))
+  (let ((start-scan-var (make-symbol "start-scan")))
+    `(let ((syntax-propertize-function nil)
+           (,start-scan-var ,(or start-scan '(point))))
+       (unwind-protect
+           (with-syntax-table ,table
+             ,@body)
+         (syntax-ppss-flush-cache ,start-scan-var)))))
+
 (defun electric-pair--syntax-ppss (&optional pos where)
   "Like `syntax-ppss', but sometimes fallback to `parse-partial-sexp'.
 
@@ -240,7 +253,8 @@ electric-pair--syntax-ppss
                               (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))
@@ -293,7 +307,8 @@ electric-pair--balance-info
                         (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)))))
@@ -323,7 +338,7 @@ electric-pair--balance-info
     (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))))
-- 
2.11.0


  reply	other threads:[~2017-12-15  2:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-14 17:05 bug#29710: Emacs becomes unresponsive when typing brackets (haskell-mode) Hariharan Rangasamy
2017-12-14 19:24 ` Noam Postavsky
2017-12-15  2:31   ` Noam Postavsky [this message]
2017-12-15  3:32     ` Hariharan Rangasamy
2017-12-15  8:54     ` Eli Zaretskii
2017-12-17  2:05       ` Noam Postavsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871sjwd8nb.fsf@users.sourceforge.net \
    --to=npostavs@users.sourceforge.net \
    --cc=29710@debbugs.gnu.org \
    --cc=hariharanrangasamy@gmail.com \
    --cc=linusshoravi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.