all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michal Nazarewicz <mina86@mina86.com>
To: 17699@debbugs.gnu.org
Subject: bug#17699: [PATCH 5/7] tildify.el: Optimise environments regexes
Date: Thu,  5 Jun 2014 13:27:34 +0200	[thread overview]
Message-ID: <1401967656-16171-5-git-send-email-mina86@mina86.com> (raw)
In-Reply-To: <1401967656-16171-1-git-send-email-mina86@mina86.com>

* 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  <mina86@mina86.com>
 
+	* 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
-     ("<pre[^>]*>" . "</pre>")
-     ("<dfn>" . "</dfn>")
-     ("<code>" . "</code>")
-     ("<samp>" . "</samp>")
-     ("<kbd>" . "</kbd>")
-     ("<var>" . "</var>")
-     ("<PRE[^>]*>" . "</PRE>")
-     ("<DFN>" . "</DFN>")
-     ("<CODE>" . "</CODE>")
-     ("<SAMP>" . "</SAMP>")
-     ("<KBD>" . "</KBD>")
-     ("<VAR>" . "</VAR>")
+     (,(eval-when-compile (concat
+                           "<\\("
+                           (regexp-opt '("pre" "dfn" "code" "samp" "kbd" "var"
+                                         "PRE" "DFN" "CODE" "SAMP" "KBD" "VAR"))
+                           "\\)\\>[^>]*>"))
+      . ("</" 1 ">"))
      ("<! *--" . "-- *>")
      ("<" . ">"))
     (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






  parent reply	other threads:[~2014-06-05 11:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-05 11:24 bug#17699: Various tildify.el improvements Michal Nazarewicz
2014-06-05 11:27 ` bug#17699: [PATCH 1/7] tildify.el: Fix end-regex building in `tildify-find-env' Michal Nazarewicz
2014-06-05 11:27   ` bug#17699: [PATCH 2/7] tildify.el: Fix matched group indexes in end-regex building Michal Nazarewicz
2014-06-05 11:27   ` bug#17699: [PATCH 3/7] tildify.el: Improve defcustom's types Michal Nazarewicz
2014-06-05 11:27   ` bug#17699: [PATCH 4/7] tildify.el: Better support for XML Michal Nazarewicz
2014-06-05 11:27   ` Michal Nazarewicz [this message]
2014-06-05 11:27   ` bug#17699: [PATCH 6/7] tildify.el: Rewrite `tildify-region' and co., add foreach function Michal Nazarewicz
2014-06-05 11:27   ` bug#17699: [PATCH 7/7] * tests/automated/tildify-tests.el (tildify-test--test): Optimise the test slightly by reusing the same temporary buffer across multiple test cases Michal Nazarewicz
2014-06-05 13:54 ` bug#17699: Various tildify.el improvements Stefan Monnier
2014-06-05 14:47   ` Michal Nazarewicz
2014-06-06 17:35     ` Glenn Morris
2014-06-06 18:13       ` Michal Nazarewicz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1401967656-16171-5-git-send-email-mina86@mina86.com \
    --to=mina86@mina86.com \
    --cc=17699@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.