Subject: bug#31551: closed (Re: bug#31551: 27.0.50; emacs hangs in hexl-mode on modula2 files)

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 22 Jun 2018 03:33:02 +0000

Your bug report

#31551: 27.0.50; emacs hangs in hexl-mode on modula2 files

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
31551: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=31551
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#31551: 27.0.50; emacs hangs in hexl-mode on modula2 files
From: Stefan Monnier <[email-masked]>
To: [email-masked]
Cc: Eli Zaretskii <[email-masked]>, [email-masked]
Date: Thu, 21 Jun 2018 23:31:55 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

> idea.  So I plan on cleaning it up (and adding an entry in NEWS, not
> sure if it deserves an entry in the lispref) and installing it
> into master.

Installed,

        Stefan

Subject: 27.0.50; emacs hangs in hexl-mode on modula2 files
From: Alexandre Adolphe <[email-masked]>
To: [email-masked]
Date: Tue, 22 May 2018 15:24:09 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi,

I run into an issue lately while trying to use the hexl-mode with
a modula2 file that I found and emacs starts to hang after the
hexl-mode starts. I tested it on emacs 24.5, 25.2 and master.

To reproduce the issue you can use :
echo "abcd" > test.MOD
emacs -Q --eval '(show-paren-mode 1)' test.MOD
M-x hexl-mode

--> emacs hangs and use 100% cpu. It only happen on the first character so
we can run out the hang with multiple C-g + an arrow key.

I dig into the issue and it appears that the was because of the
show-paren-mode and the fact that the ":" character have meaning in
modula-2-mode. Emacs is stuck in the loop of the
m2-smie-refine-colon function because after the "00000000" that start
the hexl buffer there is no more sexp to parse so the tok variable is
empty but the (forward-sexp -1) call does not fail.

I fixed that myself by stopping the loop if the point is at the beginning
of the buffer. Not sure if it correct but here is the diff :

diff --git a/lisp/progmodes/modula2.el b/lisp/progmodes/modula2.el
index 582e495..30c8c46 100644
--- a/lisp/progmodes/modula2.el
+++ b/lisp/progmodes/modula2.el
@@ -203,6 +203,7 @@ m2-smie-refine-colon
     (while (not res)
       (let ((tok (smie-default-backward-token)))
         (cond
+         ((= (point) (point-min)) (setq res ":"))
          ((zerop (length tok))
           (let ((forward-sexp-function nil))
             (condition-case nil

I am not really into modula2 files but this bug was quite surprising.

best regards,
Alexandre