From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: [bug?, org-element] latex-environment delimiters must be at BOL Date: Mon, 21 Jul 2014 11:29:00 +0200 Message-ID: <87egxf12n7.fsf@gmx.us> References: <877g3ltomt.fsf@gmx.us> <87iomxjvyv.fsf@nicolasgoaziou.fr> <87vbqu1xb6.fsf@gmx.us> <87mwc3gbtj.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47066) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X99uE-0005CV-7h for emacs-orgmode@gnu.org; Mon, 21 Jul 2014 05:29:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X99u8-0002PX-Tc for emacs-orgmode@gnu.org; Mon, 21 Jul 2014 05:29:14 -0400 Received: from mout.gmx.net ([212.227.17.22]:63110) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X99u8-0002PE-IU for emacs-orgmode@gnu.org; Mon, 21 Jul 2014 05:29:08 -0400 Received: from W530 ([109.201.154.143]) by mail.gmx.com (mrgmx103) with ESMTPSA (Nemesis) id 0MWCKz-1X2ly209Dl-00XIY0 for ; Mon, 21 Jul 2014 11:29:03 +0200 In-Reply-To: <87mwc3gbtj.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Sun, 20 Jul 2014 19:49:28 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hi, Nicolas Goaziou writes: > Rasmus writes: > >> I changed a couple of things, > > A couple of things? AFAIU, it only requires to change the regexp in > `org-element-latex-environment-parser', doesn't it? Turns out that I also had to modify the regexp in org-element--current-element as this kicks off org-element-latex-environment-parser (correct me if I am wrong). In the patch I define new regexps and use them everywhere. Org-element.el seems to rather use spelled-out regexps. If desirable, I can use this practice rather than defining new regexps. [BTW: Is there a way to test performance systematically?] The change in org-element-paragraph-parser, namely using the mentioned regexp, may be redundant. I have added tests on new newline behavior as well as a test on different begin and end tags. The latter could be moved to a separate commit or entirely dropped (but it is in the org-syntax document). This patch does not change the manual as I did not find any direct discussion of newlines and LaTeX environments. I do not change the syntax document, as it seems to only live on Worg (different rope). Cheers, Rasmus -- May contains speling mistake --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-org-element.el-allow-one-line-LaTeX-environments.patch >From f21ae57759ca5a1d4f19424c4eb0be8db4dcbfb5 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Fri, 18 Jul 2014 17:01:53 +0200 Subject: [PATCH] org-element.el: allow one-line LaTeX environments * org-element.el (org-elment--latex-begin-environment, org-element--latex-end-environment): New regexps identifying begining and ending of LaTeX environment. (org-element-latex-environment-parser, org-element-paragraph-parser, org-element--current-element): use org-elment--latex-begin-environment and org-element--latex-end-environment * test-org-element.el (test-org-element/latex-environment-parser): test for one-line LaTeX environments. (test-org-element/latex-environment-parser): test different start tag and end tag. --- lisp/org-element.el | 19 ++++++++++++------- testing/lisp/test-org-element.el | 13 ++++++++++++- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index 91b4934..5311e60 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -2083,6 +2083,13 @@ CONTENTS is nil." ;;;; Latex Environment +(defconst org-elment--latex-begin-environment + "[ \t]*\\\\begin{\\([A-Za-z0-9*]+\\)}\\(\\[.*?\\]\\|{.*?}\\)*[ \t]*?" + "Holds regexp matching beginning of LaTeX environments.") + +(defconst org-element--latex-end-environment + "[ \t]*\\\\end{%s}[ \t]*" + "Holds regexp matching ending of LaTeX environments.") (defun org-element-latex-environment-parser (limit affiliated) "Parse a LaTeX environment. @@ -2100,8 +2107,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-elment--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 +2226,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-elment--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 +3713,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-elment--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..0c042e1 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -1310,9 +1310,20 @@ 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\nvalue\n\\end{env}" + (org-test-with-temp-text "\\begin{env*}{arg}something\\end{env}" (org-element-type (org-element-at-point))))) ;; Handle non-empty blank line at the end of buffer. (should -- 2.0.2 --=-=-=--