Re: [O] [RFC] Simplify attributes syntax
Nicolas Goaziou n.goaz...@gmail.com writes: The following patch simplifies syntax for attributes. From the developer POV, each non-nil value is now read as a string by `org-export-read-attribute'. I looked at your patch but I'm not sure of the implications. In particular I'm unsure if I need to change anything in ox-taskjuggler.el. Is line 402 in org-taskjuggler--build-attributes maybe suspicious? (intern (upcase (format :%s attribute))) Thanks Christian -- Christian Egli Swiss Library for the Blind, Visually Impaired and Print Disabled Grubenstrasse 12, CH-8045 Zürich, Switzerland
Re: [O] [RFC] Simplify attributes syntax
Hello, Christian Egli christian.e...@sbs.ch writes: Nicolas Goaziou n.goaz...@gmail.com writes: The following patch simplifies syntax for attributes. From the developer POV, each non-nil value is now read as a string by `org-export-read-attribute'. I looked at your patch but I'm not sure of the implications. In particular I'm unsure if I need to change anything in ox-taskjuggler.el. Is line 402 in org-taskjuggler--build-attributes maybe suspicious? (intern (upcase (format :%s attribute))) No it isn't. The change only affects attributes obtained with `org-export-read-attribute' function, which isn't used in ox-taskjuggler.el. Regards, -- Nicolas Goaziou
Re: [O] [RFC] Simplify attributes syntax
Follow up: The following patch simplifies syntax for attributes. From the user POV, it removes necessity to quote or escape characters. For example, these are now valid: #+attr_latex: :font \footnotesize :align |l|c|c| #+attr_foo: :prop var=value :another-prop nil From the developer POV, each non-nil value is now read as a string by `org-export-read-attribute'. So: #+attr_something: :width 70 will be read as: '(:width 70) This patch is now applied in master. Please modify syntax for attributes accordingly. In particular, double quotes are not needed anymore for multiple words, unless you really want them to appear in the value: #+attr_something: :prop this is a long value :prop2 value Regards, -- Nicolas Goaziou
Re: [O] [RFC] Simplify attributes syntax
Hi Nicolas, Nicolas Goaziou n.goaz...@gmail.com writes: From the user POV, it removes necessity to quote or escape characters. For example, these are now valid: #+attr_latex: :font \footnotesize :align |l|c|c| #+attr_foo: :prop var=value :another-prop nil From the developer POV, each non-nil value is now read as a string by `org-export-read-attribute'. So: #+attr_something: :width 70 will be read as: '(:width 70) Great, thanks! If there's no major problem with it, I'll apply it before Monday. Though, I think ox-odt needs double-checking. How can we help with the double-checking? Thanks, -- Bastien
Re: [O] [RFC] Simplify attributes syntax
Hello, Bastien b...@altern.org writes: Nicolas Goaziou n.goaz...@gmail.com writes: If there's no major problem with it, I'll apply it before Monday. Though, I think ox-odt needs double-checking. How can we help with the double-checking? Just test features using attributes (in particular :width number attributes). Or just double-check the code (though Jambunathan should be more at ease with this): I did some blind replacement, but I may have missed something. Regards, -- Nicolas Goaziou
Re: [O] [RFC] Simplify attributes syntax
Hi Nicolas, I think this patch is a welcome simplification. Would it be possible to merge the code that is used for reading babel header args (things like “:results output :file foo.txt”) with the code from the exporter? Unless they are parsed by the same code, the two syntaxes will differ in subtle and headache-inducing ways (for users and developers). Both methods as it stands have their pros and cons. org-export-read-attribute seems* to give the wrong result for the case of #+ATTR_FOO: :key one :two three - (:key \one :two three\) Whereas org-babel-parse-header-arguments (returning an alist, not a plist) gives correctly ((:key . one :two three)) OTOH :key (one :two) makes o-b-parse-header-arguments give an error because it tries to read (one :two) as elisp, and “one” isn’t an elisp function. For o-x-read-attribute we correctly(?) get (:key (one :two)). o-b-parse-header-arguments can cope with :key '(one :two three) (note the single quote to not barf on the lisp-like syntax) giving ((:key one :two three)) – which is a notational variant of ((:key . (one :two three))) – whereas o-x-read-attribute gives (:key '(one :two three)) In this last case I think that either value is arguably correct – but it should be consistently one and not the other. * For testing, I extracted the following function from org-export-read-attribute. #+begin_src emacs-lisp (defun o-test (value) (let ((s value) result) (while (string-match \\(?:^\\|[ \t]+\\)\\(:[-a-zA-Z0-9_]+\\)\\([ \t]+\\|$\\) s) (let ((value (substring s 0 (match-beginning 0 (push (and (not (member value '(nil ))) value) result)) (push (intern (match-string 1 s)) result) (setq s (substring s (match-end 0 ;; Ignore any string before the first property with `cdr'. (cdr (nreverse (cons (and (org-string-nw-p s) (not (equal s nil)) s) result ) #+end_src -- Aaron Ecay
Re: [O] [RFC] Simplify attributes syntax
Hello, Aaron Ecay aarone...@gmail.com writes: I think this patch is a welcome simplification. Would it be possible to merge the code that is used for reading babel header args (things like “:results output :file foo.txt”) with the code from the exporter? It is probably possible, but that's way beyond the scope of this patch. Note that the needs are very different for each reader. Export reader must be very simple (no escaping character) and only needs to read strings. OTOH Babel reader has to determine the type of data it reads (list, number...). Unless they are parsed by the same code, the two syntaxes will differ in subtle and headache-inducing ways (for users and developers). It can be troublesome for users in some corner cases (I think Babel reader uses none or no where Export reader expects nil). I doubt it will be for developers, who should know which reader they are working with. I could replace nil - nil with no - nil in the Export reader, but I don't like this solution. In English, there are no, No, NO, None, NONE, none... but in Elisp, there is only nil. Regards, -- Nicolas Goaziou
[O] [RFC] Simplify attributes syntax
Hello, The following patch simplifies syntax for attributes. From the user POV, it removes necessity to quote or escape characters. For example, these are now valid: #+attr_latex: :font \footnotesize :align |l|c|c| #+attr_foo: :prop var=value :another-prop nil From the developer POV, each non-nil value is now read as a string by `org-export-read-attribute'. So: #+attr_something: :width 70 will be read as: '(:width 70) If there's no major problem with it, I'll apply it before Monday. Though, I think ox-odt needs double-checking. Regards, -- Nicolas Goaziou From e3a89f40f497297fd7c0ffe9273ede724684b4b9 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou n.goaz...@gmail.com Date: Sat, 9 Mar 2013 00:58:31 +0100 Subject: [PATCH 1/2] ox: Simplify syntax for attributes * lisp/ox.el (org-export-read-attribute): Do not use `read' to read attributes. Instead, extract keywords and values from it, which means each value will be a string when non-nil. * contrib/lisp/ox-groff.el (org-groff-link--inline-image): Use new attribute syntax. Small refactoring. * lisp/ox-ascii.el (org-ascii-horizontal-rule): Use new attribute syntax. * lisp/ox-beamer.el (org-beamer-plain-list): Use new attribute syntax. * lisp/ox-html.el (org-html--textarea-block): Use new attribute syntax. * lisp/ox-latex.el (org-latex--inline-image, org-latex--org-table, org-latex--math-table): Use new attribute syntax. * lisp/ox-man.el (org-man-table--org-table): Use new attribute syntax. Small refactoring. * lisp/ox-odt.el (org-odt-link--inline-image, org-odt-table-cell): Use new attribute syntax. * testing/lisp/test-ox.el: Add tests. This patch introduces two changes. To begin with, it removes the need for quoting and escaping characters. Also, all non-nil values are stored as strings. As an exception nil is stored as nil. --- contrib/lisp/ox-groff.el | 45 ++--- lisp/ox-ascii.el | 4 +++- lisp/ox-beamer.el| 6 +++--- lisp/ox-html.el | 6 +++--- lisp/ox-latex.el | 47 +++ lisp/ox-man.el | 30 -- lisp/ox-odt.el | 22 +++--- lisp/ox.el | 19 --- testing/lisp/test-ox.el | 25 +++-- 9 files changed, 108 insertions(+), 96 deletions(-) diff --git a/contrib/lisp/ox-groff.el b/contrib/lisp/ox-groff.el index 96a688a..5e64023 100644 --- a/contrib/lisp/ox-groff.el +++ b/contrib/lisp/ox-groff.el @@ -1209,11 +1209,11 @@ used as a communication channel. (expand-file-name raw-path (attr (org-export-read-attribute :attr_groff link)) (placement - (case (plist-get attr :position) -('center ) -('left -L) -('right -R) -(t ))) + (let ((pos (plist-get attr :position))) + (cond ((string= pos 'center) ) + ((string= pos 'left) -L) + ((string= pos 'right) -R) + (t (width (or (plist-get attr :width) )) (height (or (plist-get attr :height) )) (caption (and (not (plist-get attr :disable-caption)) @@ -1223,7 +1223,7 @@ used as a communication channel. (concat (cond ((and org-groff-raster-to-ps -(or (string-match .\.png$ path) +(or (string-match .\.png$ path) (string-match .\.jpg$ path))) (let ((eps-path (concat path .eps))) (shell-command (format org-groff-raster-to-ps path eps-path)) @@ -1658,37 +1658,20 @@ This function assumes TABLE has `org' as its `:type' attribute. (lines (org-split-string contents \n)) (attr-list - (let (result-list) -(dolist (attr-item - (list - (if (plist-get attr :expand) - expand nil) - - (case (plist-get attr :placement) -('center center) -('left nil) -(t - (if org-groff-tables-centered - center ))) - - (case (plist-get attr :boxtype) -('box box) -('doublebox doublebox) -('allbox allbox) -('none nil) -(t box - - (if (not (null attr-item)) - (add-to-list 'result-list attr-item))) -result-list)) + (delq nil + (list (and (plist-get attr :expand) expand) + (let ((placement (plist-get attr :placement))) + (cond ((string= placement 'center) center) + ((string= placement 'left) nil) + (t (if org-groff-tables-centered center + (or (plist-get attr :boxtype) box (title-line (plist-get attr :title-line)) (long-cells (plist-get attr :long-cells)) (table-format
Re: [O] [RFC] Simplify attributes syntax
Aloha Nicolas, Nicolas Goaziou n.goaz...@gmail.com writes: Hello, The following patch simplifies syntax for attributes. From the user POV, it removes necessity to quote or escape characters. For example, these are now valid: #+attr_latex: :font \footnotesize :align |l|c|c| #+attr_foo: :prop var=value :another-prop nil From the user POV +1. Tom -- Thomas S. Dye http://www.tsdye.com