emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [RFC] Change in export block syntax
@ 2015-10-26 14:09 Nicolas Goaziou
  2015-10-26 16:32 ` Eric S Fraga
  0 siblings, 1 reply; 2+ messages in thread
From: Nicolas Goaziou @ 2015-10-26 14:09 UTC (permalink / raw)
  To: Org Mode List

[-- Attachment #1: Type: text/plain, Size: 2955 bytes --]

Hello,

This one is a long standing issue. I didn't include it in the projects
thread since the patch was almost finished.

Basically, syntax between export blocks and special blocks is ambiguous,
as it depends on the export back-end loaded. For example,

  #+begin_odt
  <<target>>
  #+end_odt

will be parsed very differently if `ox-odt' is loaded or not. In the
former case, the target is inactive whereas in the latter case, it can
be reached with an internal link.

As a solution, export blocks are explicitly marked as such at the syntax
level to disambiguate their parsing from special blocks. The new syntax
is:

  #+BEGIN_EXPORT backend
  ...
  #+END_EXPORT

instead of

  #+BEGIN_backend
  ...
  #+END_backend

So, basically, "export" is a reserved block type, much like "src". As
a consequence, =INCLUDE= keywords syntax is modified, e.g.,

,#+INCLUDE: "file.org" HTML

becomes

,#+INCLUDE: "file.org" export html

The following function, included in ORG-NEWS, updates any Org document
to the new syntax. It is meant to be applied after applying the patch.

  (defun org-repair-export-blocks ()
    "Repair export blocks and INCLUDE keywords in current buffer."
    (when (eq major-mode 'org-mode)
      (let ((case-fold-search t)
            (back-end-re (regexp-opt
                          '("HTML" "ASCII" "LATEX" "ODT" "MARKDOWN" "MD" "ORG"
                            "MAN" "BEAMER" "TEXINFO" "GROFF" "KOMA-LETTER")
                          t)))
        (org-with-wide-buffer
         (goto-char (point-min))
         (let ((block-re (concat "^[ \t]*#\\+BEGIN_" back-end-re)))
           (save-excursion
             (while (re-search-forward block-re nil t)
               (let ((element (save-match-data (org-element-at-point))))
                 (when (eq (org-element-type element) 'special-block)
                   (save-excursion
                     (goto-char (org-element-property :end element))
                     (save-match-data (search-backward "_"))
                     (forward-char)
                     (insert "EXPORT")
                     (delete-region (point) (line-end-position)))
                   (replace-match "EXPORT \\1" nil nil nil 1))))))
         (let ((include-re
                (format "^[ \t]*#\\+INCLUDE: .*?%s[ \t]*$" back-end-re)))
           (while (re-search-forward include-re nil t)
             (let ((element (save-match-data (org-element-at-point))))
               (when (and (eq (org-element-type element) 'keyword)
                          (string= (org-element-property :key element) "INCLUDE"))
                 (replace-match "EXPORT \\1" nil nil nil 1)))))))))

The patch is still lacking documentation update. Once applied, I plan to
implement two checkers in Org lint: one to detect old syntax and another
one to signal a missing back-end after BEGIN_EXPORT string.

Feedback welcome,


Regards,

-- 
Nicolas Goaziou                                                0x80A93738

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Change-export-block-syntax.patch --]
[-- Type: text/x-diff, Size: 33686 bytes --]

From 0190f756ce4393b9db851da89cc731baabdfe7ce Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Date: Tue, 3 Feb 2015 16:16:54 +0100
Subject: [PATCH] Change export block syntax

* lisp/org-element.el (org-element-export-block-parser):
(org-element--current-element): Use new syntax for export blocks.
(org-element-block-name-alist): Remove.

* lisp/ox.el (org-export-register-backend):
(org-export-define-derived-backend): Remove :export-block keyword from
back-end's definition.
(org-export-expand-include-keyword): Use new syntax for include
keywords.

* lisp/ox-ascii.el (ascii):
* lisp/ox-beamer.el (beamer):
* lisp/ox-html.el (html):
* lisp/ox-latex.el (latex):
(org-latex-prefer-user-labels):
* lisp/ox-man.el (man):
* lisp/ox-md.el (md):
* lisp/ox-odt.el (odt):
* lisp/ox-texinfo.el (texinfo): Propagate changes to "ox.el".

* lisp/ob-core.el (org-babel-insert-result):
* lisp/ob-haskell.el (org-babel-haskell-export-to-lhs): Use new syntax.

* lisp/org.el (org-structure-template-alist): Use new syntax.
(org-protecting-blocks): Add "export" to protected blocks.  Remove
  back-ends blocks, which are now special blocks.
(org-fontify-meta-lines-and-blocks-1): Fontify correctly new blocks.

* lisp/org-footnote.el (org-footnote-forbidden-blocks):
* lisp/org-list.el (org-list-forbidden-blocks): Add "export" to
  forbidden blocks.  Remove back-ends blocks, which are now special
  blocks.

* contrib/lisp/ox-extra.el: Update comments.

* testing/lisp/test-org-element.el (test-org-element/export-block-parser):
(test-org-element/export-block-interpreter):
* testing/lisp/test-ob.el (test-ob/org-babel-remove-result--results-html):
(test-ob/org-babel-remove-result--results-latex):
* testing/lisp/test-ox.el (test-org-export/expand-include): Update tests.

Export blocks are explicitly marked as such at the syntax level to
disambiguate their parsing from special blocks.  The new syntax is

  #+BEGIN_EXPORT backend
  ...
  #+END_EXPORT

instead of

  #+BEGIN_backend
  ...
  #+END_backend

As a consequence, =INCLUDE= keywords syntax is modified, e.g.,

,#+INCLUDE: "file.org" HTML

becomes

,#+INCLUDE: "file.org" export html
---
 contrib/lisp/ox-extra.el         |   4 +-
 etc/ORG-NEWS                     |  67 +++++++++++++++++++++
 lisp/ob-core.el                  |  17 +++---
 lisp/ob-haskell.el               |   4 +-
 lisp/org-element.el              | 123 ++++++++++++++++++---------------------
 lisp/org-footnote.el             |   3 +-
 lisp/org-list.el                 |   3 +-
 lisp/org.el                      |  17 +++---
 lisp/ox-ascii.el                 |   1 -
 lisp/ox-beamer.el                |   1 -
 lisp/ox-html.el                  |   1 -
 lisp/ox-latex.el                 |   5 +-
 lisp/ox-man.el                   |   1 -
 lisp/ox-md.el                    |   1 -
 lisp/ox-odt.el                   |   1 -
 lisp/ox-texinfo.el               |   1 -
 lisp/ox.el                       |  63 ++++++--------------
 testing/lisp/test-ob.el          |   8 +--
 testing/lisp/test-org-element.el |  38 ++++++------
 testing/lisp/test-ox.el          |  14 +----
 20 files changed, 192 insertions(+), 181 deletions(-)

diff --git a/contrib/lisp/ox-extra.el b/contrib/lisp/ox-extra.el
index e6d45cc..85dae47 100644
--- a/contrib/lisp/ox-extra.el
+++ b/contrib/lisp/ox-extra.el
@@ -37,9 +37,9 @@
 ;; for export.  These blocks should be tagged with #+header: :header
 ;; yes.  For example:
 ;; #+header: :header yes
-;; #+begin_latex
+;; #+begin_export latex
 ;;   ...
-;; #+end_latex
+;; #+end_export
 
 ;; - `ignore-headlines' -- allow a headline (but not its children) to
 ;; be ignored.  Any headline tagged with the 'ignore' tag will be
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 624654a..1819a63 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -9,6 +9,73 @@ See the end of the file for license conditions.
 Please send Org bug reports to mailto:emacs-orgmode@gnu.org.
 
 * Version 8.4
+** Incompatible changes
+*** New syntax for export blocks
+Export blocks are explicetly marked as such at the syntax level to
+disambiguate their parsing from special blocks.  The new syntax is
+
+#+BEGIN_SRC org
+,#+BEGIN_EXPORT backend
+...
+,#+END_EXPORT
+#+END_SRC
+
+instead of
+
+#+BEGIN_SRC org
+,#+BEGIN_backend
+...
+,#+END_backend
+#+END_SRC
+
+As a consequence, =INCLUDE= keywords syntax is modified, e.g.,
+
+#+BEGIN_SRC org
+,#+INCLUDE: "file.org" HTML
+#+END_SRC
+
+becomes
+
+#+BEGIN_SRC org
+,#+INCLUDE: "file.org" export html
+#+END_SRC
+
+
+The following function repairs export blocks and =INCLUDE= keywords
+using previous syntax:
+
+#+BEGIN_SRC emacs-lisp
+(defun org-repair-export-blocks ()
+  "Repair export blocks and INCLUDE keywords in current buffer."
+  (when (eq major-mode 'org-mode)
+    (let ((case-fold-search t)
+          (back-end-re (regexp-opt
+                        '("HTML" "ASCII" "LATEX" "ODT" "MARKDOWN" "MD" "ORG"
+                          "MAN" "BEAMER" "TEXINFO" "GROFF" "KOMA-LETTER")
+                        t)))
+      (org-with-wide-buffer
+       (goto-char (point-min))
+       (let ((block-re (concat "^[ \t]*#\\+BEGIN_" back-end-re)))
+         (save-excursion
+           (while (re-search-forward block-re nil t)
+             (let ((element (save-match-data (org-element-at-point))))
+               (when (eq (org-element-type element) 'special-block)
+                 (save-excursion
+                   (goto-char (org-element-property :end element))
+                   (save-match-data (search-backward "_"))
+                   (forward-char)
+                   (insert "EXPORT")
+                   (delete-region (point) (line-end-position)))
+                 (replace-match "EXPORT \\1" nil nil nil 1))))))
+       (let ((include-re
+              (format "^[ \t]*#\\+INCLUDE: .*?%s[ \t]*$" back-end-re)))
+         (while (re-search-forward include-re nil t)
+           (let ((element (save-match-data (org-element-at-point))))
+             (when (and (eq (org-element-type element) 'keyword)
+                        (string= (org-element-property :key element) "INCLUDE"))
+               (replace-match "EXPORT \\1" nil nil nil 1)))))))))
+#+END_SRC
+
 ** New features
 *** Org linter
 ~org-lint~ can check syntax and report common issues in Org documents.
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 902315a..d35a23b 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2096,15 +2096,16 @@ org ----- results are added inside of a \"src_org{}\" or \"#+BEGIN_SRC
           but Org syntax here will be discarded when exporting the
           file.
 
-html ---- results are added inside of a #+BEGIN_HTML block or
-          html export snippet depending on whether the current
+html ---- results are added inside of a #+BEGIN_EXPORT HTML block
+          or html export snippet depending on whether the current
           source block is inline or not.  This is a good option
           if your code block will output html formatted text.
 
-latex --- results are added inside of a #+BEGIN_LATEX block or
-          latex export snippet depending on whether the current
-          source block is inline or not.  This is a good option
-          if your code block will output latex formatted text.
+latex --- results are added inside of a #+BEGIN_EXPORT LATEX
+          block or latex export snippet depending on whether the
+          current source block is inline or not.  This is a good
+          option if your code block will output latex formatted
+          text.
 
 code ---- the results are extracted in the syntax of the source
           code of the language being evaluated and are added
@@ -2279,10 +2280,10 @@ INFO may provide the values of these header arguments (in the
 			     (concat "#+END_" (car (org-split-string name)))
 			     nil nil (concat "{{{results(@@" name ":") "@@)}}}")))
 		 ((member "html" result-params)
-		  (funcall wrap "#+BEGIN_HTML" "#+END_HTML" nil nil
+		  (funcall wrap "#+BEGIN_EXPORT html" "#+END_EXPORT" nil nil
 			   "{{{results(@@html:" "@@)}}}"))
 		 ((member "latex" result-params)
-		  (funcall wrap "#+BEGIN_LaTeX" "#+END_LaTeX" nil nil
+		  (funcall wrap "#+BEGIN_EXPORT latex" "#+END_EXPORT" nil nil
 			   "{{{results(@@latex:" "@@)}}}"))
 		 ((member "org" result-params)
 		  (goto-char beg) (if (org-at-table-p) (org-cycle))
diff --git a/lisp/ob-haskell.el b/lisp/ob-haskell.el
index 84b1309..8d16223 100644
--- a/lisp/ob-haskell.el
+++ b/lisp/ob-haskell.el
@@ -177,12 +177,12 @@ constructs (header arguments, no-web syntax etc...) are ignored."
         (save-match-data (setq indentation (length (match-string 1))))
         (replace-match (save-match-data
                          (concat
-                          "#+begin_latex\n\\begin{code}\n"
+                          "#+begin_export latex\n\\begin{code}\n"
                           (if (or preserve-indentp
                                   (string-match "-i" (match-string 2)))
                               (match-string 3)
                             (org-remove-indentation (match-string 3)))
-                          "\n\\end{code}\n#+end_latex\n"))
+                          "\n\\end{code}\n#+end_export\n"))
                        t t)
         (indent-code-rigidly (match-beginning 0) (match-end 0) indentation)))
     (save-excursion
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 834756e..c7d9072 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -257,17 +257,6 @@ specially in `org-element--object-lex'.")
   (append org-element-recursive-objects '(paragraph table-row verse-block))
   "List of object or element types that can directly contain objects.")
 
-(defvar org-element-block-name-alist
-  '(("CENTER" . org-element-center-block-parser)
-    ("COMMENT" . org-element-comment-block-parser)
-    ("EXAMPLE" . org-element-example-block-parser)
-    ("QUOTE" . org-element-quote-block-parser)
-    ("SRC" . org-element-src-block-parser)
-    ("VERSE" . org-element-verse-block-parser))
-  "Alist between block names and the associated parsing function.
-Names must be uppercase.  Any block whose name has no association
-is parsed with `org-element-special-block-parser'.")
-
 (defconst org-element-affiliated-keywords
   '("CAPTION" "DATA" "HEADER" "HEADERS" "LABEL" "NAME" "PLOT" "RESNAME" "RESULT"
     "RESULTS" "SOURCE" "SRCNAME" "TBLNAME")
@@ -1599,9 +1588,6 @@ CONTENTS is the contents of the element."
 ;; through the following steps: implement a parser and an interpreter,
 ;; tweak `org-element--current-element' so that it recognizes the new
 ;; type and add that new type to `org-element-all-elements'.
-;;
-;; As a special case, when the newly defined type is a block type,
-;; `org-element-block-name-alist' has to be modified accordingly.
 
 
 ;;;; Babel Call
@@ -1952,42 +1938,41 @@ containing `:begin', `:end', `:type', `:value', `:post-blank' and
 `:post-affiliated' keywords.
 
 Assume point is at export-block beginning."
-  (let* ((case-fold-search t)
-	 (type (progn (looking-at "[ \t]*#\\+BEGIN_\\(\\S-+\\)")
-		      (upcase (org-match-string-no-properties 1)))))
+  (let* ((case-fold-search t))
     (if (not (save-excursion
-	       (re-search-forward
-		(format "^[ \t]*#\\+END_%s[ \t]*$" type) limit t)))
+	       (re-search-forward "^[ \t]*#\\+END_EXPORT[ \t]*$" limit t)))
 	;; Incomplete block: parse it as a paragraph.
 	(org-element-paragraph-parser limit affiliated)
-      (let ((contents-end (match-beginning 0)))
-	(save-excursion
-	  (let* ((begin (car affiliated))
-		 (post-affiliated (point))
-		 (contents-begin (progn (forward-line) (point)))
-		 (pos-before-blank (progn (goto-char contents-end)
-					  (forward-line)
-					  (point)))
-		 (end (progn (skip-chars-forward " \r\t\n" limit)
-			     (if (eobp) (point) (line-beginning-position))))
-		 (value (buffer-substring-no-properties contents-begin
-							contents-end)))
-	    (list 'export-block
-		  (nconc
-		   (list :begin begin
-			 :end end
-			 :type type
-			 :value value
-			 :post-blank (count-lines pos-before-blank end)
-			 :post-affiliated post-affiliated)
-		   (cdr affiliated)))))))))
+      (save-excursion
+	(let* ((contents-end (match-beginning 0))
+	       (backend (progn
+			  (looking-at "[ \t]*#\\+BEGIN_EXPORT[ \t]+\\(\\S-+\\)")
+			  (org-match-string-no-properties 1)))
+	       (begin (car affiliated))
+	       (post-affiliated (point))
+	       (contents-begin (progn (forward-line) (point)))
+	       (pos-before-blank (progn (goto-char contents-end)
+					(forward-line)
+					(point)))
+	       (end (progn (skip-chars-forward " \r\t\n" limit)
+			   (if (eobp) (point) (line-beginning-position))))
+	       (value (buffer-substring-no-properties contents-begin
+						      contents-end)))
+	  (list 'export-block
+		(nconc
+		 (list :type backend
+		       :begin begin
+		       :end end
+		       :value value
+		       :post-blank (count-lines pos-before-blank end)
+		       :post-affiliated post-affiliated)
+		 (cdr affiliated))))))))
 
 (defun org-element-export-block-interpreter (export-block _)
   "Interpret EXPORT-BLOCK element as Org syntax."
-  (let ((type (org-element-property :type export-block)))
-    (concat (format "#+BEGIN_%s\n" type)
-	    (org-element-property :value export-block)
-	    (format "#+END_%s" type))))
+  (format "#+BEGIN_EXPORT %s\n%s#+END_EXPORT"
+	  (org-element-property :type export-block)
+	  (org-element-property :value export-block)))
 
 
 ;;;; Fixed-width
@@ -3762,27 +3747,35 @@ element it has to parse."
 	     ;; Keywords.
 	     ((looking-at "[ \t]*#")
 	      (goto-char (match-end 0))
-	      (cond ((looking-at "\\(?: \\|$\\)")
-		     (beginning-of-line)
-		     (org-element-comment-parser limit affiliated))
-		    ((looking-at "\\+BEGIN_\\(\\S-+\\)")
-		     (beginning-of-line)
-		     (let ((parser (assoc (upcase (match-string 1))
-					  org-element-block-name-alist)))
-		       (if parser (funcall (cdr parser) limit affiliated)
-			 (org-element-special-block-parser limit affiliated))))
-		    ((looking-at "\\+CALL:")
-		     (beginning-of-line)
-		     (org-element-babel-call-parser limit affiliated))
-		    ((looking-at "\\+BEGIN:? ")
-		     (beginning-of-line)
-		     (org-element-dynamic-block-parser limit affiliated))
-		    ((looking-at "\\+\\S-+:")
-		     (beginning-of-line)
-		     (org-element-keyword-parser limit affiliated))
-		    (t
-		     (beginning-of-line)
-		     (org-element-paragraph-parser limit affiliated))))
+	      (cond
+	       ((looking-at "\\(?: \\|$\\)")
+		(beginning-of-line)
+		(org-element-comment-parser limit affiliated))
+	       ((looking-at "\\+BEGIN_\\(\\S-+\\)")
+		(beginning-of-line)
+		(funcall (pcase (upcase (match-string 1))
+			   ("CENTER"  #'org-element-center-block-parser)
+			   ("COMMENT" #'org-element-comment-block-parser)
+			   ("EXAMPLE" #'org-element-example-block-parser)
+			   ("EXPORT"  #'org-element-export-block-parser)
+			   ("QUOTE"   #'org-element-quote-block-parser)
+			   ("SRC"     #'org-element-src-block-parser)
+			   ("VERSE"   #'org-element-verse-block-parser)
+			   (_         #'org-element-special-block-parser))
+			 limit
+			 affiliated))
+	       ((looking-at "\\+CALL:")
+		(beginning-of-line)
+		(org-element-babel-call-parser limit affiliated))
+	       ((looking-at "\\+BEGIN:? ")
+		(beginning-of-line)
+		(org-element-dynamic-block-parser limit affiliated))
+	       ((looking-at "\\+\\S-+:")
+		(beginning-of-line)
+		(org-element-keyword-parser limit affiliated))
+	       (t
+		(beginning-of-line)
+		(org-element-paragraph-parser limit affiliated))))
 	     ;; Footnote Definition.
 	     ((looking-at org-footnote-definition-re)
 	      (org-element-footnote-definition-parser limit affiliated))
diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el
index 759cc2e..d78e3fb 100644
--- a/lisp/org-footnote.el
+++ b/lisp/org-footnote.el
@@ -92,8 +92,7 @@
   (org-re "^\\[\\([0-9]+\\|fn:[-_[:word:]]+\\)\\]")
   "Regular expression matching the definition of a footnote.")
 
-(defconst org-footnote-forbidden-blocks
-  '("ascii" "beamer" "comment" "example" "html" "latex" "odt" "src")
+(defconst org-footnote-forbidden-blocks '("comment" "example" "export" "src")
   "Names of blocks where footnotes are not allowed.")
 
 (defgroup org-footnote nil
diff --git a/lisp/org-list.el b/lisp/org-list.el
index 798fbb0..71a5893 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -359,8 +359,7 @@ list, obtained by prompting the user."
 	  (list (symbol :tag "Major mode")
 		(string :tag "Format"))))
 
-(defvar org-list-forbidden-blocks '("example" "verse" "src" "ascii" "beamer"
-				    "html" "latex" "odt")
+(defvar org-list-forbidden-blocks '("example" "verse" "src" "export")
   "Names of blocks where lists are not allowed.
 Names must be in lower case.")
 
diff --git a/lisp/org.el b/lisp/org.el
index 4111084..32907d2 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -4407,8 +4407,7 @@ You need to reload Org or to restart Emacs after customizing this."
 	    (plist :tag "Face property list"))
 	   (option (const verbatim)))))
 
-(defvar org-protecting-blocks
-  '("src" "example" "latex" "ascii" "html" "ditaa" "dot" "r" "R")
+(defvar org-protecting-blocks '("src" "example" "export")
   "Blocks that contain text that is quoted, i.e. not processed as Org syntax.
 This is needed for font-lock setup.")
 
@@ -5916,7 +5915,7 @@ by a #."
 		  quoting (member block-type org-protecting-blocks))
 	    (when (re-search-forward
 		   (concat "^[ \t]*#\\+end" (match-string 4) "\\>.*")
-		   nil t)  ;; on purpose, we look further than LIMIT
+		   nil t)     ; on purpose, we look further than LIMIT
 	      (setq end (min (point-max) (match-end 0))
 		    end1 (min (point-max) (1- (match-beginning 0))))
 	      (setq block-end (match-beginning 0))
@@ -5932,12 +5931,14 @@ by a #."
 	       end1 (min (point-max) (1+ end)) '(face org-meta-line))
 	      (org-remove-flyspell-overlays-in end1 end)
 	      (cond
-	       ((and lang (not (string= lang "")) org-src-fontify-natively)
+	       ((and (org-string-nw-p lang)
+		     (string= block-type "src")
+		     org-src-fontify-natively)
 		(org-src-font-lock-fontify-block lang block-start block-end)
 		(add-text-properties beg1 block-end '(src-block t)))
 	       (quoting
 		(add-text-properties beg1 (min (point-max) (1+ end1))
-				     '(face org-block))) ; end of source block
+				     '(face org-block)))
 	       ((not org-fontify-quote-and-verse-blocks))
 	       ((string= block-type "quote")
 		(add-text-properties beg1 (min (point-max) (1+ end1)) '(face org-quote)))
@@ -12340,11 +12341,11 @@ keywords relative to each registered export back-end."
     ("v" "#+BEGIN_VERSE\n?\n#+END_VERSE")
     ("V" "#+BEGIN_VERBATIM\n?\n#+END_VERBATIM")
     ("c" "#+BEGIN_CENTER\n?\n#+END_CENTER")
-    ("l" "#+BEGIN_LaTeX\n?\n#+END_LaTeX")
+    ("l" "#+BEGIN_EXPORT latex\n?\n#+END_EXPORT")
     ("L" "#+LaTeX: ")
-    ("h" "#+BEGIN_HTML\n?\n#+END_HTML")
+    ("h" "#+BEGIN_EXPORT html\n?\n#+END_EXPORT")
     ("H" "#+HTML: ")
-    ("a" "#+BEGIN_ASCII\n?\n#+END_ASCII")
+    ("a" "#+BEGIN_EXPORT ascii\n?\n#+END_EXPORT")
     ("A" "#+ASCII: ")
     ("i" "#+INDEX: ?")
     ("I" "#+INCLUDE: %file ?"))
diff --git a/lisp/ox-ascii.el b/lisp/ox-ascii.el
index 59e311b..32e7a11 100644
--- a/lisp/ox-ascii.el
+++ b/lisp/ox-ascii.el
@@ -93,7 +93,6 @@
     (underline . org-ascii-underline)
     (verbatim . org-ascii-verbatim)
     (verse-block . org-ascii-verse-block))
-  :export-block "ASCII"
   :menu-entry
   '(?t "Export to Plain Text"
        ((?A "As ASCII buffer"
diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 6c2baaf..4f4e3db 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -231,7 +231,6 @@ Return overlay specification, as a string, or nil."
 ;;; Define Back-End
 
 (org-export-define-derived-backend 'beamer 'latex
-  :export-block "BEAMER"
   :menu-entry
   '(?l 1
        ((?B "As LaTeX buffer (Beamer)" org-beamer-export-as-latex)
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index a2db938..1798acb 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -96,7 +96,6 @@
     (underline . org-html-underline)
     (verbatim . org-html-verbatim)
     (verse-block . org-html-verse-block))
-  :export-block "HTML"
   :filters-alist '((:filter-options . org-html-infojs-install-script)
 		   (:filter-final-output . org-html-final-function))
   :menu-entry
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 297b563..6eb47db 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -90,7 +90,6 @@
     ;; Pseudo objects and elements.
     (latex-math-block . org-latex-math-block)
     (latex-matrices . org-latex-matrices))
-  :export-block '("LATEX" "TEX")
   :menu-entry
   '(?l "Export to LaTeX"
        ((?L "As LaTeX buffer" org-latex-export-as-latex)
@@ -364,9 +363,9 @@ For example, when this variable is non-nil, a headline like this:
      :CUSTOM_ID: sec:foo
      :END:
   This is section [[#sec:foo]].
-  #+BEGIN_LATEX
+  #+BEGIN_EXPORT latex
   And this is still section \\ref{sec:foo}.
-  #+END_LATEX
+  #+END_EXPORT
 
 will be exported to LaTeX as:
 
diff --git a/lisp/ox-man.el b/lisp/ox-man.el
index a5d0d49..23ad7d1 100644
--- a/lisp/ox-man.el
+++ b/lisp/ox-man.el
@@ -98,7 +98,6 @@
     (underline . org-man-underline)
     (verbatim . org-man-verbatim)
     (verse-block . org-man-verse-block))
-  :export-block "MAN"
   :menu-entry
   '(?M "Export to MAN"
        ((?m "As MAN file" org-man-export-to-man)
diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index 602c149..8b28c3b 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -55,7 +55,6 @@ This variable can be set to either `atx' or `setext'."
 ;;; Define Back-End
 
 (org-export-define-derived-backend 'md 'html
-  :export-block '("MD" "MARKDOWN")
   :filters-alist '((:filter-parse-tree . org-md-separate-elements))
   :menu-entry
   '(?m "Export to Markdown"
diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el
index 75353a0..fcffce1 100644
--- a/lisp/ox-odt.el
+++ b/lisp/ox-odt.el
@@ -83,7 +83,6 @@
     (underline . org-odt-underline)
     (verbatim . org-odt-verbatim)
     (verse-block . org-odt-verse-block))
-  :export-block "ODT"
   :filters-alist '((:filter-parse-tree
 		    . (org-odt--translate-latex-fragments
 		       org-odt--translate-description-lists
diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el
index c8c6554..b37f376 100644
--- a/lisp/ox-texinfo.el
+++ b/lisp/ox-texinfo.el
@@ -78,7 +78,6 @@
     (timestamp . org-texinfo-timestamp)
     (verbatim . org-texinfo-verbatim)
     (verse-block . org-texinfo-verse-block))
-  :export-block "TEXINFO"
   :filters-alist
   '((:filter-headline . org-texinfo--filter-section-blank-lines)
     (:filter-parse-tree . org-texinfo--normalize-headlines)
diff --git a/lisp/ox.el b/lisp/ox.el
index 80cbc37..fd74929 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -965,10 +965,6 @@ BACKEND is a structure with `org-export-backend' type."
   (let ((parent (org-export-backend-parent backend)))
     (when (and parent (not (org-export-get-backend parent)))
       (error "Cannot use unknown \"%s\" back-end as a parent" parent)))
-  ;; Register dedicated export blocks in the parser.
-  (dolist (name (org-export-backend-blocks backend))
-    (add-to-list 'org-element-block-name-alist
-		 (cons name 'org-element-export-block-parser)))
   ;; If a back-end with the same name as BACKEND is already
   ;; registered, replace it with BACKEND.  Otherwise, simply add
   ;; BACKEND to the list of registered back-ends.
@@ -1095,14 +1091,6 @@ back-end.
 BODY can start with pre-defined keyword arguments.  The following
 keywords are understood:
 
-  :export-block
-
-    String, or list of strings, representing block names that
-    will not be parsed.  This is used to specify blocks that will
-    contain raw code specific to the back-end.  These blocks
-    still have to be handled by the relative `export-block' type
-    translator.
-
   :filters-alist
 
     Alist between filters and function, or list of functions,
@@ -1172,23 +1160,19 @@ keywords are understood:
     `org-export-options-alist' for more information about
     structure of the values."
   (declare (indent 1))
-  (let (blocks filters menu-entry options)
+  (let (filters menu-entry options)
     (while (keywordp (car body))
       (let ((keyword (pop body)))
-	(cl-case keyword
-	  (:export-block (let ((names (pop body)))
-			   (setq blocks (if (consp names) (mapcar 'upcase names)
-					  (list (upcase names))))))
+	(pcase keyword
 	  (:filters-alist (setq filters (pop body)))
 	  (:menu-entry (setq menu-entry (pop body)))
 	  (:options-alist (setq options (pop body)))
-	  (t (error "Unknown keyword: %s" keyword)))))
+	  (_ (error "Unknown keyword: %s" keyword)))))
     (org-export-register-backend
      (org-export-create-backend :name backend
 				:transcoders transcoders
 				:options options
 				:filters filters
-				:blocks blocks
 				:menu menu-entry))))
 
 (defun org-export-define-derived-backend (child parent &rest body)
@@ -1200,14 +1184,6 @@ the parent back-end.
 BODY can start with pre-defined keyword arguments.  The following
 keywords are understood:
 
-  :export-block
-
-    String, or list of strings, representing block names that
-    will not be parsed.  This is used to specify blocks that will
-    contain raw code specific to the back-end.  These blocks
-    still have to be handled by the relative `export-block' type
-    translator.
-
   :filters-alist
 
     Alist of filters that will overwrite or complete filters
@@ -1244,25 +1220,21 @@ The back-end could then be called with, for example:
 
   (org-export-to-buffer \\='my-latex \"*Test my-latex*\")"
   (declare (indent 2))
-  (let (blocks filters menu-entry options transcoders)
+  (let (filters menu-entry options transcoders)
     (while (keywordp (car body))
       (let ((keyword (pop body)))
-	(cl-case keyword
-	  (:export-block (let ((names (pop body)))
-			   (setq blocks (if (consp names) (mapcar 'upcase names)
-					  (list (upcase names))))))
+	(pcase keyword
 	  (:filters-alist (setq filters (pop body)))
 	  (:menu-entry (setq menu-entry (pop body)))
 	  (:options-alist (setq options (pop body)))
 	  (:translate-alist (setq transcoders (pop body)))
-	  (t (error "Unknown keyword: %s" keyword)))))
+	  (_ (error "Unknown keyword: %s" keyword)))))
     (org-export-register-backend
      (org-export-create-backend :name child
 				:parent parent
 				:transcoders transcoders
 				:options options
 				:filters filters
-				:blocks blocks
 				:menu menu-entry))))
 
 
@@ -3242,10 +3214,12 @@ storing and resolving footnotes.  It is created automatically."
 			value)
 		       (prog1 (match-string 1 value)
 			 (setq value (replace-match "" nil nil value)))))
-		 (env (cond ((string-match "\\<example\\>" value)
-			     'literal)
-			    ((string-match "\\<src\\(?: +\\(.*\\)\\)?" value)
-			     'literal)))
+		 (env (cond
+		       ((string-match "\\<example\\>" value) 'literal)
+		       ((string-match "\\<export\\(?: +\\(.*\\)\\)?" value)
+			'literal)
+		       ((string-match "\\<src\\(?: +\\(.*\\)\\)?" value)
+			'literal)))
 		 ;; Minimal level of included file defaults to the child
 		 ;; level of the current headline, if any, or one.  It
 		 ;; only applies is the file is meant to be included as
@@ -3257,12 +3231,11 @@ storing and resolving footnotes.  It is created automatically."
 			     (setq value (replace-match "" nil nil value)))
 			 (get-text-property (point)
 					    :org-include-induced-level))))
-		 (src-args (and (eq env 'literal)
-				(match-string 1 value)))
+		 (args (and (eq env 'literal) (match-string 1 value)))
 		 (block (and (string-match "\\<\\(\\S-+\\)\\>" value)
 			     (match-string 1 value))))
 	    ;; Remove keyword.
-	    (delete-region (point) (progn (forward-line) (point)))
+	    (delete-region (point) (line-beginning-position 2))
 	    (cond
 	     ((not file) nil)
 	     ((not (file-readable-p file))
@@ -3276,10 +3249,8 @@ storing and resolving footnotes.  It is created automatically."
 	      (cond
 	       ((eq env 'literal)
 		(insert
-		 (let ((ind-str (make-string ind ? ))
-		       (arg-str (if (stringp src-args)
-				    (format " %s" src-args)
-				  ""))
+		 (let ((ind-str (make-string ind ?\s))
+		       (arg-str (if (stringp args) (format " %s" args) ""))
 		       (contents
 			(org-escape-code-in-string
 			 (org-export--prepare-file-contents file lines))))
@@ -3287,7 +3258,7 @@ storing and resolving footnotes.  It is created automatically."
 			   ind-str block arg-str contents ind-str block))))
 	       ((stringp block)
 		(insert
-		 (let ((ind-str (make-string ind ? ))
+		 (let ((ind-str (make-string ind ?\s))
 		       (contents
 			(org-export--prepare-file-contents file lines)))
 		   (format "%s#+BEGIN_%s\n%s%s#+END_%s\n"
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index 508a3ed..b0643a8 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -1058,9 +1058,9 @@ content\"
 (ert-deftest test-ob/org-babel-remove-result--results-html ()
   "Test `org-babel-remove-result' with :results html."
   (test-ob-verify-result-and-removed-result
-   "#+BEGIN_HTML
+   "#+BEGIN_EXPORT html
 <head><body></body></head>
-#+END_HTML"
+#+END_EXPORT"
 
    "* org-babel-remove-result
 #+begin_src emacs-lisp :results html
@@ -1072,11 +1072,11 @@ content\"
 (ert-deftest test-ob/org-babel-remove-result--results-latex ()
   "Test `org-babel-remove-result' with :results latex."
   (test-ob-verify-result-and-removed-result
-   "#+BEGIN_LaTeX
+   "#+BEGIN_EXPORT latex
 Line 1
 Line 2
 Line 3
-#+END_LaTeX"
+#+END_EXPORT"
 
    "* org-babel-remove-result
 #+begin_src emacs-lisp :results latex
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index 89cb1bd..1abdd9d 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -829,31 +829,27 @@ Some other text
   "Test `export-block' parser."
   ;; Standard test.
   (should
-   (org-test-with-temp-text "#+BEGIN_LATEX\nText\n#+END_LATEX"
-     (org-element-map
-      (let ((org-element-block-name-alist
-	     '(("LATEX" . org-element-export-block-parser))))
-	(org-element-parse-buffer))
-      'export-block 'identity)))
+   (eq 'export-block
+       (org-test-with-temp-text "#+BEGIN_EXPORT LATEX\nText\n#+END_EXPORT"
+	 (org-element-type (org-element-at-point)))))
+  (should
+   (equal "LATEX"
+	  (org-test-with-temp-text "#+BEGIN_EXPORT LATEX\nText\n#+END_EXPORT"
+	    (org-element-property :type (org-element-at-point)))))
   ;; Ignore case.
   (should
-   (let ((org-element-block-name-alist
-	  '(("LATEX" . org-element-export-block-parser))))
-     (org-test-with-temp-text "#+begin_latex\nText\n#+end_latex"
-       (org-element-map (org-element-parse-buffer) 'export-block 'identity))))
+   (eq 'export-block
+       (org-test-with-temp-text "#+begin_export latex\nText\n#+end_export"
+	 (org-element-type (org-element-at-point)))))
   ;; Ignore incomplete block.
   (should-not
-   (let ((org-element-block-name-alist
-	  '(("LATEX" . org-element-export-block-parser))))
-     (org-test-with-temp-text "#+BEGIN_LATEX"
-       (org-element-map (org-element-parse-buffer) 'export-block
-	 'identity nil t))))
+   (eq 'export-block
+       (org-test-with-temp-text "#+BEGIN_EXPORT"
+	 (org-element-type (org-element-at-point)))))
   ;; Handle non-empty blank line at the end of buffer.
   (should
-   (let ((org-element-block-name-alist
-	  '(("LATEX" . org-element-export-block-parser))))
-     (org-test-with-temp-text "#+BEGIN_LATEX\nC\n#+END_LATEX\n "
-       (= (org-element-property :end (org-element-at-point)) (point-max))))))
+   (org-test-with-temp-text "#+BEGIN_EXPORT latex\nC\n#+END_EXPORT\n "
+     (= (org-element-property :end (org-element-at-point)) (point-max)))))
 
 
 ;;;; Export Snippet
@@ -2638,8 +2634,8 @@ CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] =>  0:01"))))
 (ert-deftest test-org-element/export-block-interpreter ()
   "Test export block interpreter."
   (should (equal (org-test-parse-and-interpret
-		  "#+BEGIN_HTML\nTest\n#+END_HTML")
-		 "#+BEGIN_HTML\nTest\n#+END_HTML\n")))
+		  "#+BEGIN_EXPORT HTML\nTest\n#+END_EXPORT")
+		 "#+BEGIN_EXPORT HTML\nTest\n#+END_EXPORT\n")))
 
 (ert-deftest test-org-element/fixed-width-interpreter ()
   "Test fixed width interpreter."
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index d619ec8..cac0adf 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -1005,10 +1005,10 @@ text
   ;; Inclusion within an html export-block.
   (should
    (equal
-    "#+BEGIN_HTML\n<p>HTML!</p>\n#+END_HTML\n"
+    "#+BEGIN_EXPORT html\n<p>HTML!</p>\n#+END_EXPORT\n"
     (org-test-with-temp-text
 	(format
-	 "#+INCLUDE: \"%s/examples/include.html\" HTML"
+	 "#+INCLUDE: \"%s/examples/include.html\" EXPORT html"
 	 org-test-dir)
       (org-export-expand-include-keyword)
       (buffer-string))))
@@ -1400,15 +1400,7 @@ Footnotes[fn:2], foot[fn:test], digit only[3], and [fn:inline:anonymous footnote
 	    (org-export-define-backend 'test
 	      '((headline . my-headline-test))
 	      :menu-entry '(?k "Test Export" test))
-	    (org-export-backend-menu (org-export-get-backend 'test)))))
-  ;; Export Blocks.
-  (should
-   (equal '(("TEST" . org-element-export-block-parser))
-	  (let (org-export-registered-backends org-element-block-name-alist)
-	    (org-export-define-backend 'test
-	      '((headline . my-headline-test))
-	      :export-block '("test"))
-	    org-element-block-name-alist))))
+	    (org-export-backend-menu (org-export-get-backend 'test))))))
 
 (ert-deftest test-org-export/define-derived-backend ()
   "Test `org-export-define-derived-backend' specifications."
-- 
2.6.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [RFC] Change in export block syntax
  2015-10-26 14:09 [RFC] Change in export block syntax Nicolas Goaziou
@ 2015-10-26 16:32 ` Eric S Fraga
  0 siblings, 0 replies; 2+ messages in thread
From: Eric S Fraga @ 2015-10-26 16:32 UTC (permalink / raw)
  To: Org Mode List

On Monday, 26 Oct 2015 at 15:09, Nicolas Goaziou wrote:
> As a solution, export blocks are explicitly marked as such at the syntax
> level to disambiguate their parsing from special blocks.

I like your proposal (although I will have to change practically every
significant org file I have...).  It does make sense to disambiguate
between export and special blocks.

thanks,
eric
-- 
: Eric S Fraga (0xFFFCF67D), Emacs 24.5.1, Org release_8.3.2-215-gb4af3f

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-10-26 17:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-26 14:09 [RFC] Change in export block syntax Nicolas Goaziou
2015-10-26 16:32 ` Eric S Fraga

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).