GNU bug report logs - #29710
Emacs becomes unresponsive when typing brackets (haskell-mode)

Previous Next

Package: emacs;

Reported by: Hariharan Rangasamy <hariharanrangasamy <at> gmail.com>

Date: Thu, 14 Dec 2017 17:06:01 UTC

Severity: normal

Tags: fixed, patch

Merged with 29715

Found in version 25.3

Fixed in version 26.1

Done: Noam Postavsky <npostavs <at> users.sourceforge.net>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 29710 in the body.
You can then email your comments to 29710 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#29710; Package emacs. (Thu, 14 Dec 2017 17:06:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Hariharan Rangasamy <hariharanrangasamy <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 14 Dec 2017 17:06:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Hariharan Rangasamy <hariharanrangasamy <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Emacs becomes unresponsive when typing brackets (haskell-mode)
Date: Thu, 14 Dec 2017 22:35:39 +0530
Emacs becomes unresponsive when typing {-[]-} when both haskell mode and
electric pair mode are enabled.

Install haskell mode from https://github.com/haskell/haskell-mode

* emacs -Q
* enable electric-pair-mode
* enable haskell mode in scratch buffer
* type {--}
* try to input brackets
{-[]-}

On pressing [  emacs becomes unresponsive, the mouse pointer rotates
continuously. On giving C-g repeatedly, the brackets are inserted and
emacs becomes responsive again. Also when i send SIGUSR2 signal emacs
becomes responsive.

The bug was posted in
https://www.reddit.com/r/emacs/comments/7jb4qu/bug_with_haskellmode_and_electricpairmode_doesnt/
In the original post the user mentioned emacs was crashing but i was
able to reproduce the emacs hang only.

I was able to reproduce this issue easily on two different systems.
Let me know if you are unable to reproduce the issue or if you need
more info.

In GNU Emacs 27.0.50 (build 4, x86_64-pc-linux-gnu, GTK+ Version 2.24.30)
 of 2017-12-10 built on hari-VirtualBox
Repository revision: 94179453039a23b7f2aefa990e317f72a3df03d5
Windowing system distributor 'The X.Org Foundation', version 11.0.11903000
System Description:    Ubuntu 16.04.3 LTS

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Error during redisplay: (internal--syntax-propertize 148) signaled
(quit) [2 times]
Quit
Configured using:
 'configure --enable-checking=yes,glyphs --enable-check-lisp-object-type
 --prefix=/home/hari/.install --without-pop 'CFLAGS=-O0 -g3''

Configured features:
XPM JPEG TIFF GIF PNG SOUND GSETTINGS NOTIFY GNUTLS FREETYPE XFT ZLIB
TOOLKIT_SCROLL_BARS GTK2 X11

Important settings:
  value of $LANG: en_IN
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: iso-latin-1-unix

Major mode: Haskell

Minor modes in effect:
  shell-dirtrack-mode: t
  haskell-indentation-mode: t
  ivy-mode: t
  electric-pair-mode: t
  global-company-mode: t
  company-mode: t
  show-paren-mode: t
  override-global-mode: t
  global-auto-revert-mode: t
  auto-compile-on-load-mode: t
  auto-compile-on-save-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny format-spec rfc822 mml
mml-sec epa derived epg gnus-util rmail rmail-loaddefs mm-decode
mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader
sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
haskell-doc inf-haskell haskell-decl-scan imenu shell pcomplete haskell
haskell-load haskell-commands highlight-uses-mode haskell-modules
haskell-sandbox haskell-navigate-imports haskell-repl haskell-collapse
hideshow haskell-debug haskell-hoogle haskell-completions
haskell-interactive-mode haskell-presentation-mode haskell-compile
haskell-process haskell-session url-util json map haskell-mode
haskell-cabal haskell-utils haskell-font-lock haskell-indentation
haskell-string haskell-sort-imports haskell-lexeme haskell-align-imports
haskell-compat haskell-complete-module haskell-ghc-support noutline
outline flymake-proc flymake warnings dabbrev haskell-customize colir
color counsel dired dired-loaddefs compile comint ansi-color esh-util
swiper ivy delsel ivy-overlay ffap company-oddmuse company-keywords
company-etags etags xref project ring company-gtags company-dabbrev-code
company-dabbrev company-files company-capf company-cmake company-xcode
company-clang company-semantic company-eclim company-template
company-css company-nxml company-bbdb elec-pair company-c-headers rx
company pcase highlight-symbol thingatpt paren smex ido two-column
edmacro kmacro diminish cl-extra help-mode use-package
use-package-ensure use-package-delight use-package-diminish
use-package-bind-key bind-key easy-mmode use-package-core autorevert
filenotify jka-compr auto-compile advice packed finder-inf info package
easymenu epg-config url-handlers url-parse auth-source cl-seq eieio
eieio-core cl-macs eieio-loaddefs password-cache url-vars seq byte-opt
gv bytecomp byte-compile cconv cl-loaddefs cl-lib time-date mule-util
tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type
mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode elisp-mode
lisp-mode prog-mode register page menu-bar rfn-eshadow isearch timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors frame cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite charscript charprop case-table epa-hook jka-cmpr-hook
help simple abbrev obarray minibuffer cl-preloaded nadvice loaddefs
button faces cus-face macroexp files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote inotify dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty
make-network-process emacs)

Memory information:
((conses 16 256157 11502)
 (symbols 48 32465 1)
 (miscs 40 56 142)
 (strings 32 81273 4132)
 (string-bytes 1 2196417)
 (vectors 16 31144)
 (vector-slots 8 748034 12446)
 (floats 8 246 393)
 (intervals 56 389 11)
 (buffers 992 11)
 (heap 1024 36431 1849))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29710; Package emacs. (Thu, 14 Dec 2017 19:25:01 GMT) Full text and rfc822 format available.

Message #8 received at 29710 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> users.sourceforge.net>
To: Hariharan Rangasamy <hariharanrangasamy <at> gmail.com>
Cc: 29710 <at> debbugs.gnu.org
Subject: Re: bug#29710: Emacs becomes unresponsive when typing brackets
 (haskell-mode)
Date: Thu, 14 Dec 2017 14:24:09 -0500
On Thu, Dec 14, 2017 at 12:05 PM, Hariharan Rangasamy
<hariharanrangasamy <at> gmail.com> wrote:
> Emacs becomes unresponsive when typing {-[]-} when both haskell mode and
> electric pair mode are enabled.
>
> Install haskell mode from https://github.com/haskell/haskell-mode
>
> * emacs -Q
> * enable electric-pair-mode
> * enable haskell mode in scratch buffer
> * type {--}
> * try to input brackets
> {-[]-}
>
> On pressing [  emacs becomes unresponsive, the mouse pointer rotates
> continuously. On giving C-g repeatedly, the brackets are inserted and
> emacs becomes responsive again. Also when i send SIGUSR2 signal emacs
> becomes responsive.
>
> The bug was posted in
> https://www.reddit.com/r/emacs/comments/7jb4qu/bug_with_haskellmode_and_electricpairmode_doesnt/
> In the original post the user mentioned emacs was crashing but i was
> able to reproduce the emacs hang only.
>
> I was able to reproduce this issue easily on two different systems.
> Let me know if you are unable to reproduce the issue or if you need
> more info.

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.




Merged 29710 29715. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Thu, 14 Dec 2017 22:35:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29710; Package emacs. (Fri, 15 Dec 2017 02:32:02 GMT) Full text and rfc822 format available.

Message #13 received at 29710 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> users.sourceforge.net>
To: Hariharan Rangasamy <hariharanrangasamy <at> gmail.com>
Cc: 29710 <at> debbugs.gnu.org, Linus Shoravi <linusshoravi <at> gmail.com>
Subject: Re: bug#29710: Emacs becomes unresponsive when typing brackets
 (haskell-mode)
Date: Thu, 14 Dec 2017 21:31:20 -0500
[Message part 1 (text/plain, inline)]
tags 29710 + patch
quit

Noam Postavsky <npostavs <at> 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:

[v1-0001-Don-t-mess-up-syntax-ppss-cache-in-electric-pair-.patch (text/x-diff, inline)]
From 5b3f0dfb1673617e4646be2be0874b168acc46c4 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> 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


Added tag(s) patch. Request was from Noam Postavsky <npostavs <at> users.sourceforge.net> to control <at> debbugs.gnu.org. (Fri, 15 Dec 2017 02:32:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29710; Package emacs. (Fri, 15 Dec 2017 03:33:01 GMT) Full text and rfc822 format available.

Message #18 received at 29710 <at> debbugs.gnu.org (full text, mbox):

From: Hariharan Rangasamy <hariharanrangasamy <at> gmail.com>
To: Noam Postavsky <npostavs <at> users.sourceforge.net>
Cc: 29710 <at> debbugs.gnu.org, Linus Shoravi <linusshoravi <at> gmail.com>
Subject: Re: bug#29710: Emacs becomes unresponsive when typing brackets
 (haskell-mode)
Date: Fri, 15 Dec 2017 09:02:35 +0530
Hi Noam,

After applying the patch, the issue is fixed.

Thanks,
Hari

On Fri, Dec 15, 2017 at 8:01 AM, Noam Postavsky
<npostavs <at> users.sourceforge.net> wrote:
> tags 29710 + patch
> quit
>
> Noam Postavsky <npostavs <at> 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:
>




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29710; Package emacs. (Fri, 15 Dec 2017 08:55:02 GMT) Full text and rfc822 format available.

Message #21 received at 29710 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Noam Postavsky <npostavs <at> users.sourceforge.net>
Cc: hariharanrangasamy <at> gmail.com, 29710 <at> debbugs.gnu.org, linusshoravi <at> gmail.com
Subject: Re: bug#29710: Emacs becomes unresponsive when typing brackets
 (haskell-mode)
Date: Fri, 15 Dec 2017 10:54:07 +0200
> From: Noam Postavsky <npostavs <at> users.sourceforge.net>
> Date: Thu, 14 Dec 2017 21:31:20 -0500
> Cc: 29710 <at> debbugs.gnu.org, Linus Shoravi <linusshoravi <at> gmail.com>
> 
> > 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:

Thanks, this is okay for the release branch, but please add some
commentary to the new macro explaining why it is needed and when it
should be used.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29710; Package emacs. (Sun, 17 Dec 2017 02:06:01 GMT) Full text and rfc822 format available.

Message #24 received at 29710 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> users.sourceforge.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: hariharanrangasamy <at> gmail.com, 29710 <at> debbugs.gnu.org, linusshoravi <at> gmail.com
Subject: Re: bug#29710: Emacs becomes unresponsive when typing brackets
 (haskell-mode)
Date: Sat, 16 Dec 2017 21:05:21 -0500
tags 29710 fixed
close 29710 26.1
quit

Eli Zaretskii <eliz <at> gnu.org> writes:

> Thanks, this is okay for the release branch, but please add some
> commentary to the new macro explaining why it is needed and when it
> should be used.

Done.

[1: 89cfdbf729]: 2017-12-16 21:02:38 -0500
  Don't mess up syntax-ppss cache in electric-pair (Bug#29710)
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=89cfdbf729bc731331358e0efc69547547aa3ca2




Added tag(s) fixed. Request was from Noam Postavsky <npostavs <at> users.sourceforge.net> to control <at> debbugs.gnu.org. (Sun, 17 Dec 2017 02:06:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 26.1, send any further explanations to 29710 <at> debbugs.gnu.org and Hariharan Rangasamy <hariharanrangasamy <at> gmail.com> Request was from Noam Postavsky <npostavs <at> users.sourceforge.net> to control <at> debbugs.gnu.org. (Sun, 17 Dec 2017 02:06:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 14 Jan 2018 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 236 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.