From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.bugs Subject: bug#29710: Emacs becomes unresponsive when typing brackets (haskell-mode) Date: Thu, 14 Dec 2017 21:31:20 -0500 Message-ID: <871sjwd8nb.fsf@users.sourceforge.net> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1513305198 24097 195.159.176.226 (15 Dec 2017 02:33:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 15 Dec 2017 02:33:18 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) Cc: 29710@debbugs.gnu.org, Linus Shoravi To: Hariharan Rangasamy Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Dec 15 03:33:14 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ePfoH-00062w-RD for geb-bug-gnu-emacs@m.gmane.org; Fri, 15 Dec 2017 03:33:14 +0100 Original-Received: from localhost ([::1]:43866 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePfoO-0007aB-QO for geb-bug-gnu-emacs@m.gmane.org; Thu, 14 Dec 2017 21:33:20 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37241) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePfnC-0006tJ-QF for bug-gnu-emacs@gnu.org; Thu, 14 Dec 2017 21:32:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ePfn8-0003Nl-R8 for bug-gnu-emacs@gnu.org; Thu, 14 Dec 2017 21:32:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:53942) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ePfn8-0003NY-M5 for bug-gnu-emacs@gnu.org; Thu, 14 Dec 2017 21:32:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ePfn8-0005xD-G4 for bug-gnu-emacs@gnu.org; Thu, 14 Dec 2017 21:32:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 15 Dec 2017 02:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 29710 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 29710-submit@debbugs.gnu.org id=B29710.151330509222850 (code B ref 29710); Fri, 15 Dec 2017 02:32:02 +0000 Original-Received: (at 29710) by debbugs.gnu.org; 15 Dec 2017 02:31:32 +0000 Original-Received: from localhost ([127.0.0.1]:34389 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ePfme-0005wP-3c for submit@debbugs.gnu.org; Thu, 14 Dec 2017 21:31:32 -0500 Original-Received: from mail-it0-f42.google.com ([209.85.214.42]:43694) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ePfma-0005w5-6i; Thu, 14 Dec 2017 21:31:29 -0500 Original-Received: by mail-it0-f42.google.com with SMTP id u62so16178730ita.2; Thu, 14 Dec 2017 18:31:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=1YlPLQ2oDJEqBBTDdqbxZW9LJpErtykcVc0gjkdCabE=; b=XIyjzOseq1zO6T2MOvtaLe4bakTMofAS6LmGMLjLnGtP0qEN/r7TTw3U2DLVRR4E3y wVJTBFko854a3fZLOCM0l5C4SmS3OqTM7bUXTjoVWrHOkeO59jVwWuNzMo0iMtbWyRHR 6QnNQ/scJk/ms74ZQfydnJ1zR9TDZPy3qGNqE9S2nAjL6dOOdjLrtSGzXlJREEfMWnAb +o1O5rduKueP8S6FOFMcAQ6ntuzE1HjvQlAaRwmvbKbtiJUvM3hhzNKO9NSYu3WSFTuX LlLMGFv0MtHQVG9ZXjZxAKJHY5QoG8eoPCDQUhbOf6yuyah0Q6cZJcG7mTaRSg1J08IN UBGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=1YlPLQ2oDJEqBBTDdqbxZW9LJpErtykcVc0gjkdCabE=; b=YuAFl+mtdwTmbNNPalMOKYrFZ8LEy/GSGo66RLV2hOiwOooEKSnUYt7R9rXTAIYm6Z G/LIVC8Q5GDJlRBHlazmgd3czfncGV+uU5UnCTy1/q9IWRc2qw3O2ZHh2zutHAXPD0qn qrRuDnpJIb1D5EY8pHbcSI1Jr8Lnbn7ss5wxwsQsWdz10n7aZBNq9qxkegtF5nyIzUpm VQ4ArZbf633Np9rh8N3+phf/aCpXzprAzvqOHGuwUGXO3bhevgL2xj67Y23+iw/LWsZq QieTKG3VqGHgWPs1wG6PJTHsQ2v95Gj1TsHw/BwdoLASL+OuEufMqFIAWAB0P+RG9/fw BKNQ== X-Gm-Message-State: AKGB3mJtPfuzekq3H+DUgvR6jke3wmdkIFvK/gMBRY5o4fGlIvEHVzU+ OPfC9XG884QshxQqsBnymCpcjA== X-Google-Smtp-Source: ACJfBouO9Jx+DEN4kJzGw3WdKjyKi5CuqgHtjbGg2bUS+J/C4bw2mChmASvYkCELTM73l25NOuhcsw== X-Received: by 10.36.22.147 with SMTP id a141mr6144936ita.30.1513305082491; Thu, 14 Dec 2017 18:31:22 -0800 (PST) Original-Received: from zebian ([45.2.119.34]) by smtp.googlemail.com with ESMTPSA id g187sm3274209itb.29.2017.12.14.18.31.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Dec 2017 18:31:21 -0800 (PST) In-Reply-To: (Noam Postavsky's message of "Thu, 14 Dec 2017 14:24:09 -0500") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:141086 Archived-At: --=-=-= Content-Type: text/plain tags 29710 + patch quit Noam Postavsky 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v1-0001-Don-t-mess-up-syntax-ppss-cache-in-electric-pair-.patch Content-Description: patch >From 5b3f0dfb1673617e4646be2be0874b168acc46c4 Mon Sep 17 00:00:00 2001 From: Noam Postavsky 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 --=-=-=--