unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#29710: Emacs becomes unresponsive when typing brackets (haskell-mode)
@ 2017-12-14 17:05 Hariharan Rangasamy
  2017-12-14 19:24 ` Noam Postavsky
  0 siblings, 1 reply; 6+ messages in thread
From: Hariharan Rangasamy @ 2017-12-14 17:05 UTC (permalink / raw)
  To: 29710

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))





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#29710: Emacs becomes unresponsive when typing brackets (haskell-mode)
  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
  0 siblings, 1 reply; 6+ messages in thread
From: Noam Postavsky @ 2017-12-14 19:24 UTC (permalink / raw)
  To: Hariharan Rangasamy; +Cc: 29710

On Thu, Dec 14, 2017 at 12:05 PM, Hariharan Rangasamy
<hariharanrangasamy@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.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#29710: Emacs becomes unresponsive when typing brackets (haskell-mode)
  2017-12-14 19:24 ` Noam Postavsky
@ 2017-12-15  2:31   ` Noam Postavsky
  2017-12-15  3:32     ` Hariharan Rangasamy
  2017-12-15  8:54     ` Eli Zaretskii
  0 siblings, 2 replies; 6+ messages in thread
From: Noam Postavsky @ 2017-12-15  2:31 UTC (permalink / raw)
  To: Hariharan Rangasamy; +Cc: 29710, Linus Shoravi

[-- 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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#29710: Emacs becomes unresponsive when typing brackets (haskell-mode)
  2017-12-15  2:31   ` Noam Postavsky
@ 2017-12-15  3:32     ` Hariharan Rangasamy
  2017-12-15  8:54     ` Eli Zaretskii
  1 sibling, 0 replies; 6+ messages in thread
From: Hariharan Rangasamy @ 2017-12-15  3:32 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: 29710, Linus Shoravi

Hi Noam,

After applying the patch, the issue is fixed.

Thanks,
Hari

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





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#29710: Emacs becomes unresponsive when typing brackets (haskell-mode)
  2017-12-15  2:31   ` Noam Postavsky
  2017-12-15  3:32     ` Hariharan Rangasamy
@ 2017-12-15  8:54     ` Eli Zaretskii
  2017-12-17  2:05       ` Noam Postavsky
  1 sibling, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2017-12-15  8:54 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: hariharanrangasamy, 29710, linusshoravi

> From: Noam Postavsky <npostavs@users.sourceforge.net>
> Date: Thu, 14 Dec 2017 21:31:20 -0500
> Cc: 29710@debbugs.gnu.org, Linus Shoravi <linusshoravi@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.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#29710: Emacs becomes unresponsive when typing brackets (haskell-mode)
  2017-12-15  8:54     ` Eli Zaretskii
@ 2017-12-17  2:05       ` Noam Postavsky
  0 siblings, 0 replies; 6+ messages in thread
From: Noam Postavsky @ 2017-12-17  2:05 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: hariharanrangasamy, 29710, linusshoravi

tags 29710 fixed
close 29710 26.1
quit

Eli Zaretskii <eliz@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





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-12-17  2:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2017-12-15  3:32     ` Hariharan Rangasamy
2017-12-15  8:54     ` Eli Zaretskii
2017-12-17  2:05       ` Noam Postavsky

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).