From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michal Nazarewicz Newsgroups: gmane.emacs.bugs Subject: bug#17699: [PATCH 5/7] tildify.el: Optimise environments regexes Date: Thu, 5 Jun 2014 13:27:34 +0200 Message-ID: <1401967656-16171-5-git-send-email-mina86@mina86.com> References: <1401967656-16171-1-git-send-email-mina86@mina86.com> NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1401968505 11975 80.91.229.3 (5 Jun 2014 11:41:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 5 Jun 2014 11:41:45 +0000 (UTC) To: 17699@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jun 05 13:41:38 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WsW37-0005ZG-UG for geb-bug-gnu-emacs@m.gmane.org; Thu, 05 Jun 2014 13:41:38 +0200 Original-Received: from localhost ([::1]:40049 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsW37-0002MY-HC for geb-bug-gnu-emacs@m.gmane.org; Thu, 05 Jun 2014 07:41:37 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40858) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsW2k-0001rR-3a for bug-gnu-emacs@gnu.org; Thu, 05 Jun 2014 07:41:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WsW2a-0005O1-Tz for bug-gnu-emacs@gnu.org; Thu, 05 Jun 2014 07:41:14 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:45944) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsW2a-0005Mr-Qn for bug-gnu-emacs@gnu.org; Thu, 05 Jun 2014 07:41:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1WsVpy-0007mH-JB for bug-gnu-emacs@gnu.org; Thu, 05 Jun 2014 07:28:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michal Nazarewicz Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 05 Jun 2014 11:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17699 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 17699-submit@debbugs.gnu.org id=B17699.140196767629852 (code B ref 17699); Thu, 05 Jun 2014 11:28:02 +0000 Original-Received: (at 17699) by debbugs.gnu.org; 5 Jun 2014 11:27:56 +0000 Original-Received: from localhost ([127.0.0.1]:44806 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WsVpr-0007lD-UZ for submit@debbugs.gnu.org; Thu, 05 Jun 2014 07:27:56 -0400 Original-Received: from mail-we0-f201.google.com ([74.125.82.201]:36145) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WsVpo-0007kN-67 for 17699@debbugs.gnu.org; Thu, 05 Jun 2014 07:27:53 -0400 Original-Received: by mail-we0-f201.google.com with SMTP id w62so85909wes.2 for <17699@debbugs.gnu.org>; Thu, 05 Jun 2014 04:27:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=wNJuFK3/RGPF+dxvXarRFUVUh0bQjw3n+XQS//nYpvs=; b=T6A/CJ+vf5ju2PdyUsL4IBbd1iBbGx0yBvkWNOreRdSZ1sSx8wLO27G05W6WyfrFV/ H4PtuebN4haI7nkUAdOgFezM60xfEyBq9px7VFzyNFFajtxMbeD6HiVLY4sAS0NiYJlP VHMvQo4hRCQ/6xDDC6OfVaq7j/VCPOATBqH+HhC0tl7jsix6ytpCSFEtEV6gU1bi26ac LUJhQoy28tuNrfGXKvdQlRcSpWEJ0TPmr0D2Ccmc6ahNkjb1CW8cKUU8ht6Rdxlu+GZ8 zjgw48O94BsGS9Fv5IWZ/pNPBoUPi8yhqWFbLf4P3hYr6yxpFbqAvmvSG7ZfxaOnXbX5 HTMw== X-Gm-Message-State: ALoCoQl60Jj4hMWWjOzV/TZ0ngVHWJCgzS4NPAHGYbTKBi9Ue6goGlgXvQAG3xDUXxlO6numYLRpn7pJaDK6vZWebObS7As7xpen1VmuAiHi/pVMCGamHExkKIpXNPiV+4M5zQroLc/x X-Received: by 10.152.29.169 with SMTP id l9mr6528163lah.3.1401967666255; Thu, 05 Jun 2014 04:27:46 -0700 (PDT) Original-Received: from corp2gmr1-2.eem.corp.google.com (corp2gmr1-2.eem.corp.google.com [172.25.138.117]) by gmr-mx.google.com with ESMTPS id ck3si212789wib.0.2014.06.05.04.27.46 for <17699@debbugs.gnu.org> (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Jun 2014 04:27:46 -0700 (PDT) Original-Received: from hpgntag-ubiq62.eem.corp.google.com (hpgntag-ubiq62.eem.corp.google.com [172.25.135.103]) by corp2gmr1-2.eem.corp.google.com (Postfix) with ESMTP id 12FC11E4312 for <17699@debbugs.gnu.org>; Thu, 5 Jun 2014 04:27:46 -0700 (PDT) Original-Received: by hpgntag-ubiq62.eem.corp.google.com (Postfix, from userid 126942) id E6A7010B66B; Thu, 5 Jun 2014 13:27:45 +0200 (CEST) X-Mailer: git-send-email 2.0.0.526.g5318336 In-Reply-To: <1401967656-16171-1-git-send-email-mina86@mina86.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:90041 Archived-At: * lisp/textmodes/tildify.el (tildify-ignored-environments-alist): Each time beginning of an environment to ignore is found, `tildify-find-env' needs to identify regexp for the ending of the environment. This is done by trying all the opening regexes on matched text in a loop, so to speed that up, this loop should have fewer things to match, which can be done by using alternatives in the opening regexes. Coincidentally, this should make matching of the opening regexp faster as well thanks to the use of `regexp-opt' and having common prefix pulled from many regexes. --- lisp/ChangeLog | 14 ++++++++++++++ lisp/textmodes/tildify.el | 37 +++++++++++++++---------------------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index c662add..0351d54 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,19 @@ 2014-06-05 Michal Nazarewicz + * textmodes/tildify.el (tildify-ignored-environments-alist): + Optimise environments regexes + + Each time beginning of an environment to ignore is found, + `tildify-find-env' needs to identify regexp for the ending + of the environment. This is done by trying all the opening + regexes on matched text in a loop, so to speed that up, this + loop should have fewer things to match, which can be done by + using alternatives in the opening regexes. + + Coincidentally, this should make matching of the opening + regexp faster as well thanks to the use of `regexp-opt' and + having common prefix pulled from many regexes. + * textmodes/tildify.el (tildify-string-alist) (tildify-ignored-environments-alist): Add `nxml-mode' to the list of supported modes since `xml-mode' is no longer a thing but just diff --git a/lisp/textmodes/tildify.el b/lisp/textmodes/tildify.el index 6dd471d..39ccad7 100644 --- a/lisp/textmodes/tildify.el +++ b/lisp/textmodes/tildify.el @@ -119,42 +119,35 @@ mode, the item for the mode SYMBOL is looked up in the alist instead." (symbol :tag "Like other"))))) (defcustom tildify-ignored-environments-alist - '((latex-mode + `((latex-mode ("\\\\\\\\" . "") ; do not remove this - ("\\\\begin{verbatim}" . "\\\\end{verbatim}") + (,(eval-when-compile (concat + "\\\\begin{\\(" + (regexp-opt '("verbatim" "math" "displaymath" + "equation" "eqnarray" "eqnarray*")) + "\\)}")) + . ("\\\\end{" 1 "}")) ("\\\\verb\\*?\\(.\\)" . (1)) - ("\\$\\$" . "\\$\\$") - ("\\$" . "\\$") + ("\\$\\$?" . (0)) ("\\\\(" . "\\\\)") ("\\\\[[]" . "\\\\[]]") - ("\\\\begin{math}" . "\\\\end{math}") - ("\\\\begin{displaymath}" . "\\\\end{displaymath}") - ("\\\\begin{equation}" . "\\\\end{equation}") - ("\\\\begin{eqnarray\\*?}" . "\\\\end{eqnarray\\*?}") ("\\\\[a-zA-Z]+\\( +\\|{}\\)[a-zA-Z]*" . "") ("%" . "$")) (plain-tex-mode . latex-mode) (html-mode - ("]*>" . "") - ("" . "") - ("" . "") - ("" . "") - ("" . "") - ("" . "") - ("]*>" . "") - ("" . "") - ("" . "") - ("" . "") - ("" . "") - ("" . "") + (,(eval-when-compile (concat + "<\\(" + (regexp-opt '("pre" "dfn" "code" "samp" "kbd" "var" + "PRE" "DFN" "CODE" "SAMP" "KBD" "VAR")) + "\\)\\>[^>]*>")) + . ("")) ("") ("<" . ">")) (sgml-mode . html-mode) (xml-mode ("") ("<" . ">")) - (nxml-mode . xml-mode) - (t nil)) + (nxml-mode . xml-mode)) "Alist specifying ignored structured text environments. Parts of text defined in this alist are skipped without performing hard space insertion on them. These setting allow skipping text parts like verbatim or -- 2.0.0.526.g5318336