Subject: bug#24205: 25.1.50; Re-display issue (lag) when opening certain files [sml-mode]

From: Stefan Monnier <[email-masked]>
Date: Thu, 11 Aug 2016 18:21:59 -0400

>  (* ''a is a special equality type (it is not the same as the generic 'a
> type. It *)

Apparently, it's the following font-lock rule which takes forever:

    (,(concat "\\_<\\(\\(?:data\\|abs\\|with\\|eq\\)?type\\)\\s-+"
              sml-tyvarseq-re "\\(" sml-id-re "\\)")
     (1 font-lock-keyword-face)
     (2 font-lock-type-def-face))

The sml-tyvarseq-re part of it matches type annotation which typically
take the form ('a, 'b), so it normally matches things like

     datatype ('a, 'b) foo
or
     type ('a, 'b) foo

and the regexp is loose enough to match any mix of , ' and identifiers
inside parentheses.  This in itself is not a big problem, except that
the regexp is not careful enough and match "abc" either as a single
identifier, or as 2 identifiers (in two different ways: "a" followed by
"bc" or "ab" "followed by "c"), or as 3 identifiers.  For longish words
like "generic" you can guess that it ends up with very many different
ways to match, so when the match fails, it takes many trials to notice
that none of the ways succeeds.

Can you try the patch below, which tightens the regexp a bit and tries
to remove these redundant ways to match the same thing?

        Stefan

diff --git a/packages/sml-mode/sml-mode.el b/packages/sml-mode/sml-mode.el
index e94b571..f4adf11 100644
--- a/packages/sml-mode/sml-mode.el
+++ b/packages/sml-mode/sml-mode.el
@@ -257,8 +257,8 @@ notion of \"the end of an outline\".")
   (defconst sml-id-re "\\sw\\(?:\\sw\\|\\s_\\)*"))
 
 (defconst sml-tyvarseq-re
-  (concat "\\(?:\\(?:'+" sml-id-re "\\|(\\(?:[,']\\|" sml-id-re
-          "\\|\\s-\\)+)\\)\\s-+\\)?"))
+  (concat "\\(?:\\(?:'+" sml-id-re "\\|(\\(?:[,' \t\n]+" sml-id-re
+          "\\)+)\\)\\s-+\\)?"))
 
 ;;; Font-lock settings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;