emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [RFC] [PATCH] [parser] org-element.el: Handle block parameters
@ 2013-10-28 19:04 Aaron Ecay
  2013-10-29  8:20 ` Nicolas Goaziou
  0 siblings, 1 reply; 8+ messages in thread
From: Aaron Ecay @ 2013-10-28 19:04 UTC (permalink / raw)
  To: emacs-orgmode

* lisp/org-element.el (org-element-center-block-parser,
org-element-quote-block-parser, org-element-special-block-parser,
org-element-verse-block-parser): Add :parameters to return value
(org-element-center-block-interpreter, org-element-quote-block-interpreter,
org-element-special-block-interpreter,
org-element-verse-block-interpreter): Interpret :parameters if present
* testing/lisp/test-org-element.el (test-org-element/center-block-parser,
test-org-element/example-block-parser,
test-org-element/quote-block-parser,
test-org-element/special-block-parser,
test-org-element/special-block-parser,
test-org-element/verse-block-parser,
test-org-element/center-block-interpreter,
test-org-element/quote-block-interpreter,
test-org-element/special-block-interpreter,
test-org-element/example-block-interpreter,
test-org-element/verse-block-interpreter): Update tests to check
:parameters

This brings the parser in line with the Org Syntax as documented on
Worg: <http://orgmode.org/worg/dev/org-syntax.html#Greater_Blocks>.
---

This does not handle paramters for export blocks (#+begin_latex et
al.) or comment blocks, but these would be trivial to add if needed.

 lisp/org-element.el              | 49 ++++++++++++++++++++++++-------
 testing/lisp/test-org-element.el | 63 +++++++++++++++++++++++++++++++++-------
 2 files changed, 92 insertions(+), 20 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index 254af3c..c9ac9a5 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -494,7 +494,7 @@ their value.

 Return a list whose CAR is `center-block' and CDR is a plist
 containing `:begin', `:end', `:contents-begin', `:contents-end',
-`:post-blank' and `:post-affiliated' keywords.
+`:parameters', `:post-blank' and `:post-affiliated' keywords.

 Assume point is at the beginning of the block."
   (let ((case-fold-search t))
@@ -505,6 +505,8 @@ Assume point is at the beginning of the block."
       (let ((block-end-line (match-beginning 0)))
 	(let* ((begin (car affiliated))
 	       (post-affiliated (point))
+               (params (progn (looking-at "[ \t]*#\\+BEGIN_CENTER\\(?: +\\(.*\\)\\)?")
+			      (match-string 1)))
 	       ;; Empty blocks have no contents.
 	       (contents-begin (progn (forward-line)
 				      (and (< (point) block-end-line)
@@ -522,6 +524,7 @@ Assume point is at the beginning of the block."
 		       :end end
 		       :contents-begin contents-begin
 		       :contents-end contents-end
+		       :parameters params
 		       :post-blank (count-lines pos-before-blank end)
 		       :post-affiliated post-affiliated)
 		 (cdr affiliated))))))))
@@ -529,7 +532,11 @@ Assume point is at the beginning of the block."
 (defun org-element-center-block-interpreter (center-block contents)
   "Interpret CENTER-BLOCK element as Org syntax.
 CONTENTS is the contents of the element."
-  (format "#+BEGIN_CENTER\n%s#+END_CENTER" contents))
+  (format "#+BEGIN_CENTER%s\n%s#+END_CENTER"
+          (if (org-element-property :parameters center-block)
+              (concat " " (org-element-property :parameters center-block))
+            "")
+	  contents))


 ;;;; Drawer
@@ -1338,7 +1345,7 @@ their value.

 Return a list whose CAR is `quote-block' and CDR is a plist
 containing `:begin', `:end', `:contents-begin', `:contents-end',
-`:post-blank' and `:post-affiliated' keywords.
+`:parameters', `:post-blank' and `:post-affiliated' keywords.

 Assume point is at the beginning of the block."
   (let ((case-fold-search t))
@@ -1350,6 +1357,8 @@ Assume point is at the beginning of the block."
 	(save-excursion
 	  (let* ((begin (car affiliated))
 		 (post-affiliated (point))
+                 (params (progn (looking-at "[ \t]*#\\+BEGIN_QUOTE\\(?: +\\(.*\\)\\)?")
+				(match-string 1)))
 		 ;; Empty blocks have no contents.
 		 (contents-begin (progn (forward-line)
 					(and (< (point) block-end-line)
@@ -1367,6 +1376,7 @@ Assume point is at the beginning of the block."
 			 :end end
 			 :contents-begin contents-begin
 			 :contents-end contents-end
+			 :parameters params
 			 :post-blank (count-lines pos-before-blank end)
 			 :post-affiliated post-affiliated)
 		   (cdr affiliated)))))))))
@@ -1374,7 +1384,11 @@ Assume point is at the beginning of the block."
 (defun org-element-quote-block-interpreter (quote-block contents)
   "Interpret QUOTE-BLOCK element as Org syntax.
 CONTENTS is the contents of the element."
-  (format "#+BEGIN_QUOTE\n%s#+END_QUOTE" contents))
+  (format "#+BEGIN_QUOTE%s\n%s#+END_QUOTE"
+	  (if (org-element-property :parameters quote-block)
+              (concat " " (org-element-property :parameters quote-block))
+	    "")
+	  contents))


 ;;;; Section
@@ -1421,12 +1435,14 @@ their value.

 Return a list whose CAR is `special-block' and CDR is a plist
 containing `:type', `:begin', `:end', `:contents-begin',
-`:contents-end', `:post-blank' and `:post-affiliated' keywords.
+`:contents-end', `:parameters', `:post-blank' and `:post-affiliated'
+keywords.

 Assume point is at the beginning of the block."
   (let* ((case-fold-search t)
-	 (type (progn (looking-at "[ \t]*#\\+BEGIN_\\(\\S-+\\)")
-		      (upcase (match-string-no-properties 1)))))
+	 (type (progn (looking-at "[ \t]*#\\+BEGIN_\\(\\S-+\\)\\(?: +\\(.*\\)\\)?")
+		      (upcase (match-string-no-properties 1))))
+         (params (match-string-no-properties 2)))
     (if (not (save-excursion
 	       (re-search-forward
 		(format "^[ \t]*#\\+END_%s[ \t]*$" (regexp-quote type))
@@ -1455,6 +1471,7 @@ Assume point is at the beginning of the block."
 			 :end end
 			 :contents-begin contents-begin
 			 :contents-end contents-end
+			 :parameters params
 			 :post-blank (count-lines pos-before-blank end)
 			 :post-affiliated post-affiliated)
 		   (cdr affiliated)))))))))
@@ -1463,7 +1480,12 @@ Assume point is at the beginning of the block."
   "Interpret SPECIAL-BLOCK element as Org syntax.
 CONTENTS is the contents of the element."
   (let ((block-type (org-element-property :type special-block)))
-    (format "#+BEGIN_%s\n%s#+END_%s" block-type contents block-type)))
+    (format "#+BEGIN_%s%s\n%s#+END_%s"
+	    block-type
+	    (if (org-element-property :parameters special-block)
+                (concat " " (org-element-property :parameters special-block))
+	      "")
+	    contents block-type)))


 \f
@@ -2491,7 +2513,7 @@ their value.

 Return a list whose CAR is `verse-block' and CDR is a plist
 containing `:begin', `:end', `:contents-begin', `:contents-end',
-`:post-blank' and `:post-affiliated' keywords.
+`:parameters', `:post-blank' and `:post-affiliated' keywords.

 Assume point is at beginning of the block."
   (let ((case-fold-search t))
@@ -2503,6 +2525,8 @@ Assume point is at beginning of the block."
 	(save-excursion
 	  (let* ((begin (car affiliated))
 		 (post-affiliated (point))
+                 (params (progn (looking-at "[ \t]*#\\+BEGIN_VERSE\\(?: +\\(.*\\)\\)?")
+                                (match-string 1)))
 		 (contents-begin (progn (forward-line) (point)))
 		 (pos-before-blank (progn (goto-char contents-end)
 					  (forward-line)
@@ -2516,6 +2540,7 @@ Assume point is at beginning of the block."
 			 :end end
 			 :contents-begin contents-begin
 			 :contents-end contents-end
+			 :parameters params
 			 :post-blank (count-lines pos-before-blank end)
 			 :post-affiliated post-affiliated)
 		   (cdr affiliated)))))))))
@@ -2523,7 +2548,11 @@ Assume point is at beginning of the block."
 (defun org-element-verse-block-interpreter (verse-block contents)
   "Interpret VERSE-BLOCK element as Org syntax.
 CONTENTS is verse block contents."
-  (format "#+BEGIN_VERSE\n%s#+END_VERSE" contents))
+  (format "#+BEGIN_VERSE%s\n%s#+END_VERSE"
+          (if (org-element-property :parameters verse-block)
+              (concat " " (org-element-property :parameters verse-block))
+            "")
+	  contents))


 \f
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index 4f08e3e..7d29f3e 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -277,7 +277,14 @@ Some other text
   (should-not
    (org-test-with-temp-text "#+BEGIN_CENTER"
      (org-element-map
-      (org-element-parse-buffer) 'center-block 'identity nil t))))
+      (org-element-parse-buffer) 'center-block 'identity nil t)))
+  ;; Parameters
+  (should (equal (org-element-property
+		  :parameters
+		  (org-test-with-temp-text
+		      "#+BEGIN_CENTER param\nText\n#+END_CENTER"
+		    (org-element-at-point)))
+		 "param")))


 ;;;; Clock
@@ -1535,7 +1542,14 @@ Outside list"
   (should-not
    (org-test-with-temp-text "#+BEGIN_QUOTE"
      (org-element-map
-      (org-element-parse-buffer) 'quote-block 'identity nil t))))
+      (org-element-parse-buffer) 'quote-block 'identity nil t)))
+  ;; Parameters
+  (should (equal (org-element-property
+		  :parameters
+		  (org-test-with-temp-text
+		      "#+BEGIN_QUOTE param\nText\n#+END_QUOTE"
+		    (org-element-at-point)))
+                 "param")))


 ;;;; Quote Section
@@ -1616,8 +1630,14 @@ Outside list"
 	  (org-test-with-temp-text "#+BEGIN_SPECIAL*\nContents\n#+END_SPECIAL*"
 	    (let ((element (org-element-at-point)))
 	      (list (org-element-type element)
-		    (org-element-property :type element)))))))
-
+		    (org-element-property :type element))))))
+  ;; Parameters
+  (should (equal (org-element-property
+		  :parameters
+		  (org-test-with-temp-text
+		      "#+BEGIN_SPECIAL param\nText\n#+END_SPECIAL"
+		    (org-element-at-point)))
+		 "param")))

 ;;;; Src Block

@@ -1916,8 +1936,14 @@ Outside list"
   (should-not
    (org-test-with-temp-text "#+BEGIN_VERSE"
      (org-element-map
-	 (org-element-parse-buffer) 'verse-block 'identity nil t))))
-
+	 (org-element-parse-buffer) 'verse-block 'identity nil t)))
+  ;; Parameters
+  (should (equal (org-element-property
+		  :parameters
+		  (org-test-with-temp-text
+		      "#+BEGIN_VERSE param\nText\n#+END_VERSE"
+		    (org-element-at-point)))
+		 "param")))

 \f
 ;;; Test Interpreters.
@@ -1960,7 +1986,10 @@ Outside list"
   "Test center block interpreter."
   (should
    (equal (org-test-parse-and-interpret "#+BEGIN_CENTER\nTest\n#+END_CENTER")
-	  "#+BEGIN_CENTER\nTest\n#+END_CENTER\n")))
+	  "#+BEGIN_CENTER\nTest\n#+END_CENTER\n"))
+  (should
+   (equal (org-test-parse-and-interpret "#+BEGIN_CENTER param\nTest\n#+END_CENTER")
+          "#+BEGIN_CENTER param\nTest\n#+END_CENTER\n")))

 (ert-deftest test-org-element/drawer-interpreter ()
   "Test drawer interpreter."
@@ -2108,13 +2137,19 @@ Outside list"
   "Test quote block interpreter."
   (should (equal (org-test-parse-and-interpret
 		  "#+BEGIN_QUOTE\nTest\n#+END_QUOTE")
-		 "#+BEGIN_QUOTE\nTest\n#+END_QUOTE\n")))
+		 "#+BEGIN_QUOTE\nTest\n#+END_QUOTE\n"))
+  (should (equal (org-test-parse-and-interpret
+                  "#+BEGIN_QUOTE param\nTest\n#+END_QUOTE")
+                 "#+BEGIN_QUOTE param\nTest\n#+END_QUOTE\n")))

 (ert-deftest test-org-element/special-block-interpreter ()
   "Test special block interpreter."
   (should (equal (org-test-parse-and-interpret
 		  "#+BEGIN_SPECIAL\nTest\n#+END_SPECIAL")
-		 "#+BEGIN_SPECIAL\nTest\n#+END_SPECIAL\n")))
+		 "#+BEGIN_SPECIAL\nTest\n#+END_SPECIAL\n"))
+  (should (equal (org-test-parse-and-interpret
+                  "#+BEGIN_SPECIAL param\nTest\n#+END_SPECIAL")
+                 "#+BEGIN_SPECIAL param\nTest\n#+END_SPECIAL\n")))

 (ert-deftest test-org-element/babel-call-interpreter ()
   "Test babel call interpreter."
@@ -2180,6 +2215,11 @@ CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] =>  0:01"))
    (equal (org-test-parse-and-interpret
 	   "#+BEGIN_EXAMPLE -n -k\n(+ 1 1)\n#+END_EXAMPLE")
 	  "#+BEGIN_EXAMPLE -n -k\n(+ 1 1)\n#+END_EXAMPLE\n"))
+  ;; With arbitrary parameter
+  (should
+   (equal (org-test-parse-and-interpret
+           "#+BEGIN_EXAMPLE param\n(+ 1 1)\n#+END_EXAMPLE")
+          "#+BEGIN_EXAMPLE param\n(+ 1 1)\n#+END_EXAMPLE\n"))
   ;; Preserve code escaping.
   (should
    (equal (org-test-parse-and-interpret
@@ -2408,7 +2448,10 @@ DEADLINE: <2012-01-01> SCHEDULED: <2012-01-01> CLOSED: [2012-01-01]\n"))))
   "Test verse block interpretation."
   (should
    (equal (org-test-parse-and-interpret "#+BEGIN_VERSE\nTest\n#+END_VERSE")
-	  "#+BEGIN_VERSE\nTest\n#+END_VERSE\n")))
+	  "#+BEGIN_VERSE\nTest\n#+END_VERSE\n"))
+  (should
+   (equal (org-test-parse-and-interpret "#+BEGIN_VERSE param\nTest\n#+END_VERSE")
+          "#+BEGIN_VERSE param\nTest\n#+END_VERSE\n")))

 (ert-deftest test-org-element/bold-interpreter ()
   "Test bold interpreter."
--
1.8.4.1

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

* Re: [RFC] [PATCH] [parser] org-element.el: Handle block parameters
  2013-10-28 19:04 [RFC] [PATCH] [parser] org-element.el: Handle block parameters Aaron Ecay
@ 2013-10-29  8:20 ` Nicolas Goaziou
  2013-10-30  4:28   ` Aaron Ecay
  0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2013-10-29  8:20 UTC (permalink / raw)
  To: Aaron Ecay; +Cc: emacs-orgmode

Hello,

Aaron Ecay <aaronecay@gmail.com> writes:

Thanks for the patch.

> This brings the parser in line with the Org Syntax as documented on
> Worg: <http://orgmode.org/worg/dev/org-syntax.html#Greater_Blocks>.

Besides this reason (which could also be solved by updating Org Syntax
document), do you have a need for this extension?

> This does not handle paramters for export blocks (#+begin_latex et
> al.) or comment blocks, but these would be trivial to add if needed.

Syntax for parameters is different for these blocks, and is already
handled.

Now some comments about the code.

> +               (params (progn (looking-at "[ \t]*#\\+BEGIN_CENTER\\(?: +\\(.*\\)\\)?")

I suggest changing the regexp into

  "[ \t]*#\\+BEGIN_CENTER\\(?: +\\(.*\\)[ \t]*\\)?"

in order to trim parameters, if any.

> +			      (match-string 1)))

It's better to use `org-match-string-no-properties' since you don't need
properties.

> +  (format "#+BEGIN_CENTER%s\n%s#+END_CENTER"
> +          (if (org-element-property :parameters center-block)
> +              (concat " " (org-element-property :parameters center-block))
> +            "")
> +	  contents))

A `let' would be nicer.

  (let ((parameters (org-element-property :parameters center-block)))
    (if parameters (concat " " parameters) ""))
> +                 (params (progn (looking-at "[ \t]*#\\+BEGIN_QUOTE\\(?: +\\(.*\\)\\)?")
> +				(match-string 1)))

Ditto.

> +  (format "#+BEGIN_QUOTE%s\n%s#+END_QUOTE"
> +	  (if (org-element-property :parameters quote-block)
> +              (concat " " (org-element-property :parameters quote-block))
> +	    "")

Ditto

> +	 (type (progn (looking-at "[ \t]*#\\+BEGIN_\\(\\S-+\\)\\(?: +\\(.*\\)\\)?")
> +		      (upcase (match-string-no-properties 1))))

Ditto.

> +         (params (match-string-no-properties 2)))

Use `org-match-string-no-properties' here, for compatibility with XEmacs.

> +    (format "#+BEGIN_%s%s\n%s#+END_%s"
> +	    block-type
> +	    (if (org-element-property :parameters special-block)
> +                (concat " " (org-element-property :parameters special-block))
> +	      "")

See above.

> +                 (params (progn (looking-at "[ \t]*#\\+BEGIN_VERSE\\(?: +\\(.*\\)\\)?")
> +                                (match-string 1)))

See above.

> +  (format "#+BEGIN_VERSE%s\n%s#+END_VERSE"
> +          (if (org-element-property :parameters verse-block)
> +              (concat " " (org-element-property :parameters verse-block))
> +            "")

See above.


Regards,

-- 
Nicolas Goaziou

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

* Re: [RFC] [PATCH] [parser] org-element.el: Handle block parameters
  2013-10-29  8:20 ` Nicolas Goaziou
@ 2013-10-30  4:28   ` Aaron Ecay
  2013-10-30  8:01     ` Nicolas Goaziou
  0 siblings, 1 reply; 8+ messages in thread
From: Aaron Ecay @ 2013-10-30  4:28 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

Hi Nicolas,

2013ko urriak 29an, Nicolas Goaziou-ek idatzi zuen:

[...]

>> This brings the parser in line with the Org Syntax as documented on
>> Worg: <http://orgmode.org/worg/dev/org-syntax.html#Greater_Blocks>.
> 
> Besides this reason (which could also be solved by updating Org Syntax
> document), do you have a need for this extension?

I have several export filters which translate special blocks into latex
code (doing some tedious string munging in elisp, such that a simple
latex block is not warranted; I also have the eventual goal of making
them cross-backend, which will involve a different bit of tedious
munging).  These filters take arguments in the #+begin_foo line.

I also think it would be nice for the org code following this paragraph
to be translated to output that makes sense for each backend, with the
quote’s author formatted nicely (on a new line preceded by a dash,
aligned to the right margin in text/html, using the csquotes package in
latex, etc.).  This patch would enable such a functionality.

#+begin_quote Chico Marx
Why a duck?
#+end_quote

If these seem like compelling use cases, then I will make the
adjustments you proposed to the code (which all look correct).

Thanks,

-- 
Aaron Ecay

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

* Re: [RFC] [PATCH] [parser] org-element.el: Handle block parameters
  2013-10-30  4:28   ` Aaron Ecay
@ 2013-10-30  8:01     ` Nicolas Goaziou
  2013-10-30 22:23       ` Aaron Ecay
  0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2013-10-30  8:01 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

Aaron Ecay <aaronecay@gmail.com> writes:

> I have several export filters which translate special blocks into latex
> code (doing some tedious string munging in elisp, such that a simple
> latex block is not warranted; I also have the eventual goal of making
> them cross-backend, which will involve a different bit of tedious
> munging).  These filters take arguments in the #+begin_foo line.

IIRC, I already suggested a solution with Babel for this problem.
There's no need to complicate core Org syntax for such a specific case.

> I also think it would be nice for the org code following this paragraph
> to be translated to output that makes sense for each backend, with the
> quote’s author formatted nicely (on a new line preceded by a dash,
> aligned to the right margin in text/html, using the csquotes package in
> latex, etc.).  This patch would enable such a functionality.
>
> #+begin_quote Chico Marx
> Why a duck?
> #+end_quote

Well actually, this kind of syntax is confusing at best. Something like
the following could be used instead:

  #+begin_quote :author Chico Marx

Actually, there are two points to consider:

  1. Providing something like :author implies that all back-ends in core
     and contrib and the manual have to be updated accordingly.

  2. "parameters" is too vague to be useful. It needs to be parsed
     further, which means that we must define explicitly use cases and
     keywords. Thus, I don't think adding "parameters" to every block is
     a good move if we don't know beforehand how they will be used.

     Though, it is possible to extend the syntax to well-defined
     specific cases. :author may be one of them, there are certainly
     others.


Regards,

-- 
Nicolas Goaziou

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

* Re: [RFC] [PATCH] [parser] org-element.el: Handle block parameters
  2013-10-30  8:01     ` Nicolas Goaziou
@ 2013-10-30 22:23       ` Aaron Ecay
  2013-10-31 11:00         ` Nicolas Goaziou
  0 siblings, 1 reply; 8+ messages in thread
From: Aaron Ecay @ 2013-10-30 22:23 UTC (permalink / raw)
  To: Nicolas Goaziou, emacs-orgmode

Hi Nicolas,

2013ko urriak 30an, Nicolas Goaziou-ek idatzi zuen:
> IIRC, I already suggested a solution with Babel for this problem.
> There's no need to complicate core Org syntax for such a specific
> case.

And I already said why I disagree that your proposal is a solution.
Special blocks are “Containers targeted at export back-ends” (according
to the manual).  Is it appropriate for such containers to have metadata
attached?  As I explain below, I think so.  Whether you approve or
disapprove of the use to which someone puts that metadata in a specific
instance is a different question, as long as we agree that the metadata
is potentially useful for some things.

> 
>> I also think it would be nice for the org code following this paragraph
>> to be translated to output that makes sense for each backend, with the
>> quote’s author formatted nicely (on a new line preceded by a dash,
>> aligned to the right margin in text/html, using the csquotes package in
>> latex, etc.).  This patch would enable such a functionality.
>> 
>> #+begin_quote Chico Marx
>> Why a duck?
>> #+end_quote
> 
> Well actually, this kind of syntax is confusing at best. Something like
> the following could be used instead:
> 
>   #+begin_quote :author Chico Marx

That is a good idea.

> 
> Actually, there are two points to consider:
> 
>   1. Providing something like :author implies that all back-ends in core
>      and contrib and the manual have to be updated accordingly.

Yes, that is desirable eventually.  I guess whoever implements :author
for quotes (maybe it will be me) will need to think about all these
things.  (Though I’m not sure that all backends have to be updated in
one fell swoop.  The old behavior is still fine as a fall-back until all
backends catch up to the new standard.  I’m thinking specifically of
backends in contrib – certainly the core exporters for html, latex, and
plain text should move in tandem.  I’m not sure there is any single
person who knows the details of all the available export formats well
enough to make a change like this across all of them.)

> 
>   2. "parameters" is too vague to be useful. It needs to be parsed
>      further, which means that we must define explicitly use cases and
>      keywords. Thus, I don't think adding "parameters" to every block is
>      a good move if we don't know beforehand how they will be used.
> 
>      Though, it is possible to extend the syntax to well-defined
>      specific cases. :author may be one of them, there are certainly
>      others.

I have the opposite view.  The parser should provide a set of convenient
tools to elisp code, which are useful for extending org’s functionality
at the elisp level.  An “if you build it they will come” approach.  One
very successful recent example of this is the attr_backend syntax.  This
allows specifying data in a very open-ended format to export backends.
I think people (including me) have been able to take advantage of this
fact to incrementally improve export backends.

Importantly, it was not necessary to define beforehand what keys and
values are available in attr_backend lines.  There is just free-form
data, which anyone’s lisp code can hook into for whatever purpose.  If
such an addition is useful and general-purpose enough, it can be added
to the official export backend; otherwise it just lives in users’
configured export filters.

Aaron

(An alternative proposal which would work just as well – better even,
insofar as it applies to things other than special blocks – would be to
provide a backend-agnostic #+attr: syntax (maybe with a different name,
to avoid clashing with export-specific #+attr_foo).  The :author
information (for example) could then be put there.  But I shaped this
proposal based on what was already present in the documentation.)

-- 
Aaron Ecay

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

* Re: [RFC] [PATCH] [parser] org-element.el: Handle block parameters
  2013-10-30 22:23       ` Aaron Ecay
@ 2013-10-31 11:00         ` Nicolas Goaziou
  2013-10-31 18:15           ` Aaron Ecay
  0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2013-10-31 11:00 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

Aaron Ecay <aaronecay@gmail.com> writes:

> 2013ko urriak 30an, Nicolas Goaziou-ek idatzi zuen:
>> IIRC, I already suggested a solution with Babel for this problem.
>> There's no need to complicate core Org syntax for such a specific
>> case.
>
> And I already said why I disagree that your proposal is a solution.
> Special blocks are “Containers targeted at export back-ends” (according
> to the manual). Is it appropriate for such containers to have metadata
> attached?  As I explain below, I think so. Whether you approve or
> disapprove of the use to which someone puts that metadata in a specific
> instance is a different question, as long as we agree that the metadata
> is potentially useful for some things.

Metadata relative to export back-ends is stuffed into #+attr_backend
keywords. There's no reason to clobber Org syntax with back-ends
metadata.

>> Actually, there are two points to consider:
>> 
>>   1. Providing something like :author implies that all back-ends in core
>>      and contrib and the manual have to be updated accordingly.
>
> Yes, that is desirable eventually.  I guess whoever implements :author
> for quotes (maybe it will be me) will need to think about all these
> things.  (Though I’m not sure that all backends have to be updated in
> one fell swoop.  The old behavior is still fine as a fall-back until all
> backends catch up to the new standard.

All backends will not magically catch-up if nobody does the job.
Creating new syntax has a cost, which is higher than simply adding a few
lines in "org-element.el".

>>   2. "parameters" is too vague to be useful. It needs to be parsed
>>      further, which means that we must define explicitly use cases and
>>      keywords. Thus, I don't think adding "parameters" to every block is
>>      a good move if we don't know beforehand how they will be used.
>> 
>>      Though, it is possible to extend the syntax to well-defined
>>      specific cases. :author may be one of them, there are certainly
>>      others.
>
> I have the opposite view.  The parser should provide a set of convenient
> tools to elisp code, which are useful for extending org’s functionality
> at the elisp level.  An “if you build it they will come” approach.

I'm trying to unify and simplify Org syntax. The simpler the better.
That doesn't mean that the syntax cannot be extended, but I'd like to
see a concrete good reason for it. "Let's do it as it might be used
later" just doesn't cut it.

Moreover, your proposal, IMO, is not well-enough defined. You merely add
a free-form string and call it "parameters". Parameters for what? Which
syntax: a plist, switches? Why cannot some parameters fit into other
affiliated keywords (e.g. HEADER)? What happens if the line is too long:
is there another location for them? What happens if they compete with
other affiliated keywords, i.e. what if I write

  #+begin_quote :caption "Something"

So, again, it is important to know what they do so we can deduce what
location is the more appropriate for them. For example, "attributes"
should be short enough to fit on a single line. Switches are good
candidates, a plist is not (see switches in example blocks, for
example), unless we limit allowed keywords in it.


Regards,

-- 
Nicolas Goaziou

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

* Re: [RFC] [PATCH] [parser] org-element.el: Handle block parameters
  2013-10-31 11:00         ` Nicolas Goaziou
@ 2013-10-31 18:15           ` Aaron Ecay
  2013-10-31 19:08             ` Nicolas Goaziou
  0 siblings, 1 reply; 8+ messages in thread
From: Aaron Ecay @ 2013-10-31 18:15 UTC (permalink / raw)
  To: Nicolas Goaziou, emacs-orgmode

Hi Nicolas,

2013ko urriak 31an, Nicolas Goaziou-ek idatzi zuen:

[...]

> Moreover, your proposal, IMO, is not well-enough defined. You merely add
> a free-form string and call it "parameters". Parameters for what? Which
> syntax: a plist, switches?

I think a plist would work fine, indeed.

> Why cannot some parameters fit into other affiliated keywords
> (e.g. HEADER)?

Very interesting.  I did not realize that #+header: could apply to
elements other than babel blocks.  (Babel blocks are all that is
documented in the manual, for example.)  But a quick experiment shows
that they can.  I think #+header with a plist can accomplish all of what
I wanted.

So, if this is a reliable component of org syntax, I will focus on
documenting it in the manual.  If you like, I will also remove the
references to block parameters on worg (or you can do it if you’d
rather, since I think you originally wrote the syntax document).

Thanks,

-- 
Aaron Ecay

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

* Re: [RFC] [PATCH] [parser] org-element.el: Handle block parameters
  2013-10-31 18:15           ` Aaron Ecay
@ 2013-10-31 19:08             ` Nicolas Goaziou
  0 siblings, 0 replies; 8+ messages in thread
From: Nicolas Goaziou @ 2013-10-31 19:08 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

Aaron Ecay <aaronecay@gmail.com> writes:

> Very interesting.  I did not realize that #+header: could apply to
> elements other than babel blocks.  (Babel blocks are all that is
> documented in the manual, for example.)  But a quick experiment shows
> that they can.  I think #+header with a plist can accomplish all of what
> I wanted.

HEADER is not parsed as a plist but as a list of strings (one per
keyword). Internally, Babel parses it differently (as an alist).

> So, if this is a reliable component of org syntax, I will focus on
> documenting it in the manual.

What feature do you want to document? At the moment, HEADER keywords are
only used on src blocks, by Babel, and this is already documented.

> If you like, I will also remove the references to block parameters on
> worg (or you can do it if you’d rather, since I think you originally
> wrote the syntax document).

Please go ahead. Thank you.


Regards,

-- 
Nicolas Goaziou

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

end of thread, other threads:[~2013-10-31 19:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-28 19:04 [RFC] [PATCH] [parser] org-element.el: Handle block parameters Aaron Ecay
2013-10-29  8:20 ` Nicolas Goaziou
2013-10-30  4:28   ` Aaron Ecay
2013-10-30  8:01     ` Nicolas Goaziou
2013-10-30 22:23       ` Aaron Ecay
2013-10-31 11:00         ` Nicolas Goaziou
2013-10-31 18:15           ` Aaron Ecay
2013-10-31 19:08             ` Nicolas Goaziou

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