From: Rasmus <rasmus@gmx.us>
To: emacs-orgmode@gnu.org
Subject: Re: [bug?, org-element] latex-environment delimiters must be at BOL
Date: Tue, 22 Jul 2014 11:08:22 +0200 [thread overview]
Message-ID: <87fvhtlq0p.fsf@gmx.us> (raw)
In-Reply-To: <87ha29g76m.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Tue, 22 Jul 2014 09:54:09 +0200")
[-- Attachment #1: Type: text/plain, Size: 672 bytes --]
Hi,
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> IMO, the way to go would be to define regexps as constants everywhere in
> "org-element.el", but that would introduce duplicates with some
> constants in "org.el". IOW, there's no clear design about it. Situation
> may change when the parser gets more integrated into core.
Sounds like an daunting, but worthwhile task.
> Meanwhile, it can't hurt to use constants in "org-element.el".
Good to know.
The attached patch hopefully addresses all of the issues you pointed
out. Sorry about those typos before!
Thanks,
Rasmus
--
Sådan en god dansk lagereddike kan man slet ikke bruge mere
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-element.el-Allow-one-line-LaTeX-environments.patch --]
[-- Type: text/x-diff, Size: 4837 bytes --]
From b34f2199a648f6eafd6917662ec0d6c56e12bc8b Mon Sep 17 00:00:00 2001
From: Rasmus <rasmus@gmx.us>
Date: Fri, 18 Jul 2014 17:01:53 +0200
Subject: [PATCH] org-element.el: Allow one-line LaTeX environments
* org-element.el (org-element--latex-begin-environment,
org-element--latex-end-environment): New format strings to identify
beginning and ending of LaTeX environments.
(org-element-latex-environment-parser, org-element-paragraph-parser,
org-element--current-element): Use `org-element--latex-begin-environment'
and `org-element--latex-end-environment'.
* test-org-element.el (test-org-element/latex-environment-parser):
Add tests.
---
lisp/org-element.el | 29 ++++++++++++++++++++++-------
testing/lisp/test-org-element.el | 22 +++++++++++++++++++++-
2 files changed, 43 insertions(+), 8 deletions(-)
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 850ed94..147432e 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -2084,6 +2084,23 @@ CONTENTS is nil."
;;;; Latex Environment
+(defconst org-element--latex-begin-environment
+ "^[ \t]*\\\\begin{\\([A-Za-z0-9*]+\\)}"
+ ;; The following format string also matches optional arguments:
+ ;; "^[ \t]*\\\\begin{\\([A-Za-z0-9*]+\\)}\\(\\[.*?\\]\\|{.*?}\\)*[ \t]*?"
+ "Format string matching the beginning of a LaTeX environment.
+
+Usage example:
+ (format org-element--latex-begin-environment ENV)
+where ENV is a LaTeX environment.
+
+See also `org-element--latex-end-environment'.")
+
+(defconst org-element--latex-end-environment
+ "\\\\end{%s}[ \t]*$"
+ "Format string matching the ending of a LaTeX environment.
+See also `org-element--latex-begin-environment'.")
+
(defun org-element-latex-environment-parser (limit affiliated)
"Parse a LaTeX environment.
@@ -2100,8 +2117,8 @@ Assume point is at the beginning of the latex environment."
(save-excursion
(let ((case-fold-search t)
(code-begin (point)))
- (looking-at "[ \t]*\\\\begin{\\([A-Za-z0-9]+\\*?\\)}")
- (if (not (re-search-forward (format "^[ \t]*\\\\end{%s}[ \t]*$"
+ (looking-at org-element--latex-begin-environment)
+ (if (not (re-search-forward (format org-element--latex-end-environment
(regexp-quote (match-string 1)))
limit t))
;; Incomplete latex environment: parse it as a paragraph.
@@ -2219,11 +2236,10 @@ Assume point is at the beginning of the paragraph."
(org-match-string-no-properties 1)))
limit t)))
;; Stop at valid latex environments.
- (and (looking-at
- "[ \t]*\\\\begin{\\([A-Za-z0-9]+\\*?\\)}")
+ (and (looking-at org-element--latex-begin-environment)
(save-excursion
(re-search-forward
- (format "^[ \t]*\\\\end{%s}[ \t]*$"
+ (format org-element--latex-end-environment
(regexp-quote
(org-match-string-no-properties 1)))
limit t)))
@@ -3707,8 +3723,7 @@ element it has to parse."
(goto-char (car affiliated))
(org-element-keyword-parser limit nil))
;; LaTeX Environment.
- ((looking-at
- "[ \t]*\\\\begin{[A-Za-z0-9*]+}\\(\\[.*?\\]\\|{.*?}\\)*[ \t]*$")
+ ((looking-at org-element--latex-begin-environment)
(org-element-latex-environment-parser limit affiliated))
;; Drawer and Property Drawer.
((looking-at org-drawer-regexp)
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index 04ef1ce..0ca0f8a 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -1310,9 +1310,29 @@ e^{i\\pi}+1=0
(eq 'latex-environment
(org-test-with-temp-text "\\begin{env}{arg}\nvalue\n\\end{env}"
(org-element-type (org-element-at-point)))))
+ ;; Allow environments without newline after \begin{.}.
+ (should
+ (eq 'latex-environment
+ (org-test-with-temp-text "\\begin{env}{arg}something\nvalue\n\\end{env}"
+ (org-element-type (org-element-at-point)))))
+ ;; Allow one-line environments.
+ (should
+ (eq 'latex-environment
+ (org-test-with-temp-text "\\begin{env}{arg}something\\end{env}"
+ (org-element-type (org-element-at-point)))))
+ ;; Should not allow different tags.
+ (should-not
+ (eq 'latex-environment
+ (org-test-with-temp-text "\\begin{env*}{arg}something\\end{env}"
+ (org-element-type (org-element-at-point)))))
+ ;; LaTeX environments must be on separate lines.
+ (should-not
+ (eq 'latex-environment
+ (org-test-with-temp-text "\\begin{env} x \\end{env} y"
+ (org-element-type (org-element-at-point)))))
(should-not
(eq 'latex-environment
- (org-test-with-temp-text "\\begin{env}{arg} something\nvalue\n\\end{env}"
+ (org-test-with-temp-text "y \\begin{env} x<point> \\end{env}"
(org-element-type (org-element-at-point)))))
;; Handle non-empty blank line at the end of buffer.
(should
--
2.0.2
next prev parent reply other threads:[~2014-07-22 9:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-10 11:54 [bug?, org-element] latex-environment delimiters must be at BOL Rasmus
2014-07-16 13:04 ` Nicolas Goaziou
2014-07-18 15:49 ` Rasmus
2014-07-20 17:49 ` Nicolas Goaziou
2014-07-21 9:29 ` Rasmus
2014-07-22 7:54 ` Nicolas Goaziou
2014-07-22 9:08 ` Rasmus [this message]
2014-07-22 10:03 ` Nicolas Goaziou
2014-07-22 13:28 ` Rasmus
2014-07-23 8:29 ` Nicolas Goaziou
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
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fvhtlq0p.fsf@gmx.us \
--to=rasmus@gmx.us \
--cc=emacs-orgmode@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 public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.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).