From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: SUMMARY: [Feature Request] Make property-drawers exportable Date: Wed, 25 Sep 2013 22:57:22 +0200 Message-ID: <87pprwzkjx.fsf@gmail.com> References: <8738shvzaj.fsf@gmail.com> <87ppvkiz8b.fsf@gmail.com> <87vc5cviu6.fsf@gmail.com> <871u80imo6.fsf@gmail.com> <33429FE3-CAA5-4F58-8536-135F96CA9C11@gmail.com> <406B4BB5-5A38-44EB-AC97-DEA17644164C@gmail.com> <3EAEACD0-1B99-40B7-8A5D-AE491C9F8528@gmail.com> <87a9j115m0.fsf@gmail.com> <39CF3890-4884-4894-8670-627AC5B4E935@gmail.com> <874n9914ld.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34344) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOw97-0005Ir-5s for emacs-orgmode@gnu.org; Wed, 25 Sep 2013 16:57:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VOw90-00035P-En for emacs-orgmode@gnu.org; Wed, 25 Sep 2013 16:57:17 -0400 Received: from mail-wi0-x233.google.com ([2a00:1450:400c:c05::233]:61462) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOw90-000353-0O for emacs-orgmode@gnu.org; Wed, 25 Sep 2013 16:57:10 -0400 Received: by mail-wi0-f179.google.com with SMTP id hm2so259081wib.6 for ; Wed, 25 Sep 2013 13:57:09 -0700 (PDT) In-Reply-To: (Carsten Dominik's message of "Wed, 25 Sep 2013 14:26:24 +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: Carsten Dominik Cc: Thorsten Jolitz , emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Carsten Dominik writes: > Not really. It would simplify processing to have the list instead > of a string, but indeed, a filter can accomplish all of it. Here is a first patch. It doesn't handle export back-ends in contrib. Regards, -- Nicolas Goaziou --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-ox-Add-a-defcustom-to-export-properties-drawers.patch >From c48974d10e0d57b6332fcfed384a49ee530ea04a Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Wed, 25 Sep 2013 21:27:29 +0200 Subject: [PATCH] ox: Add a defcustom to export properties drawers * lisp/ox.el (org-export-with-drawers): Improve docstring. (org-export-with-properties): New variable (org-export--skip-p): Handle new variable. (org-export-options-alist): Install new variable. * lisp/ox-ascii.el (org-ascii-node-property, org-ascii-property-drawer): New functions. * lisp/ox-html.el (org-html-node-property): New function. (org-html-property-drawer): Export property drawers as "pre" blocks. * lisp/ox-latex.el (org-latex-property-drawer, org-latex-node-property): New functions. * lisp/ox-man.el (org-man-node-property, org-man-property-drawer): New functions. * lisp/ox-md.el (org-md-node-property, org-md-property-drawer): New functions. * lisp/ox-odt.el (org-odt-node-property): New function. (org-odt-property-drawer): Export property drawers as fixed width blocks. * lisp/ox-texinfo.el (org-texinfo-node-property): New function. (org-texinfo-property-drawer): Export property drawers as verbatim blocks. * testing/lisp/test-ox.el: Add tests. --- lisp/ox-ascii.el | 23 +++++++++++++++++++++++ lisp/ox-html.el | 21 ++++++++++++++++----- lisp/ox-latex.el | 25 ++++++++++++++++++++++++- lisp/ox-man.el | 19 ++++++++++++++++++- lisp/ox-md.el | 24 ++++++++++++++++++++++++ lisp/ox-odt.el | 23 ++++++++++++++++++----- lisp/ox-texinfo.el | 21 ++++++++++++++++----- lisp/ox.el | 28 +++++++++++++++++++++++++--- testing/lisp/test-ox.el | 19 +++++++++++++++++++ 9 files changed, 183 insertions(+), 20 deletions(-) diff --git a/lisp/ox-ascii.el b/lisp/ox-ascii.el index 74a7c64..e0a3fa9 100644 --- a/lisp/ox-ascii.el +++ b/lisp/ox-ascii.el @@ -81,10 +81,12 @@ (latex-fragment . org-ascii-latex-fragment) (line-break . org-ascii-line-break) (link . org-ascii-link) + (node-property . org-ascii-node-property) (paragraph . org-ascii-paragraph) (plain-list . org-ascii-plain-list) (plain-text . org-ascii-plain-text) (planning . org-ascii-planning) + (property-drawer . org-ascii-property-drawer) (quote-block . org-ascii-quote-block) (quote-section . org-ascii-quote-section) (radio-target . org-ascii-radio-target) @@ -1440,6 +1442,18 @@ INFO is a plist holding contextual information." (unless org-ascii-links-to-notes (format " (%s)" raw-link)))))))) +;;;; Node Properties + +(defun org-ascii-node-property (node-property contents info) + "Transcode a NODE-PROPERTY element from Org to ASCII. +CONTENTS is nil. INFO is a plist holding contextual +information." + (format "%s:%s" + (org-element-property :key node-property) + (let ((value (org-element-property :value node-property))) + (if value (concat " " value) "")))) + + ;;;; Paragraph (defun org-ascii-paragraph (paragraph contents info) @@ -1509,6 +1523,15 @@ channel." " ")) +;;;; Property Drawer + +(defun org-ascii-property-drawer (property-drawer contents info) + "Transcode a PROPERTY-DRAWER element from Org to ASCII. +CONTENTS holds the contents of the drawer. INFO is a plist +holding contextual information." + (org-string-nw-p contents)) + + ;;;; Quote Block (defun org-ascii-quote-block (quote-block contents info) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 14b31b2..66862bc 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -76,6 +76,7 @@ (latex-fragment . org-html-latex-fragment) (line-break . org-html-line-break) (link . org-html-link) + (node-property . org-html-node-property) (paragraph . org-html-paragraph) (plain-list . org-html-plain-list) (plain-text . org-html-plain-text) @@ -2782,6 +2783,17 @@ INFO is a plist holding contextual information. See ;; No path, only description. Try to do something useful. (t (format "%s" desc))))) +;;;; Node Property + +(defun org-html-node-property (node-property contents info) + "Transcode a NODE-PROPERTY element from Org to HTML. +CONTENTS is nil. INFO is a plist holding contextual +information." + (format "%s:%s" + (org-element-property :key node-property) + (let ((value (org-element-property :value node-property))) + (if value (concat " " value) "")))) + ;;;; Paragraph (defun org-html-paragraph (paragraph contents info) @@ -2930,11 +2942,10 @@ channel." (defun org-html-property-drawer (property-drawer contents info) "Transcode a PROPERTY-DRAWER element from Org to HTML. -CONTENTS is nil. INFO is a plist holding contextual -information." - ;; The property drawer isn't exported but we want separating blank - ;; lines nonetheless. - "") +CONTENTS holds the contents of the drawer. INFO is a plist +holding contextual information." + (and (org-string-nw-p contents) + (format "
\n%s
" contents))) ;;;; Quote Block diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index e1173ef..196e50f 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -63,11 +63,12 @@ (latex-fragment . org-latex-latex-fragment) (line-break . org-latex-line-break) (link . org-latex-link) + (node-property . org-latex-node-property) (paragraph . org-latex-paragraph) (plain-list . org-latex-plain-list) (plain-text . org-latex-plain-text) (planning . org-latex-planning) - (property-drawer . (lambda (&rest args) "")) + (property-drawer . org-latex-property-drawer) (quote-block . org-latex-quote-block) (quote-section . org-latex-quote-section) (radio-target . org-latex-radio-target) @@ -1837,6 +1838,18 @@ INFO is a plist holding contextual information. See (t (format org-latex-link-with-unknown-path-format desc))))) +;;;; Node Property + +(defun org-latex-node-property (node-property contents info) + "Transcode a NODE-PROPERTY element from Org to LaTeX. +CONTENTS is nil. INFO is a plist holding contextual +information." + (format "%s:%s" + (org-element-property :key node-property) + (let ((value (org-element-property :value node-property))) + (if value (concat " " value) "")))) + + ;;;; Paragraph (defun org-latex-paragraph (paragraph contents info) @@ -1961,6 +1974,16 @@ information." "\\\\")) +;;;; Property Drawer + +(defun org-latex-property-drawer (property-drawer contents info) + "Transcode a PROPERTY-DRAWER element from Org to LaTeX. +CONTENTS holds the contents of the drawer. INFO is a plist +holding contextual information." + (and (org-string-nw-p contents) + (format "\\begin{verbatim}\n%s\\end{verbatim}" contents))) + + ;;;; Quote Block (defun org-latex-quote-block (quote-block contents info) diff --git a/lisp/ox-man.el b/lisp/ox-man.el index a160e4c..760e264 100644 --- a/lisp/ox-man.el +++ b/lisp/ox-man.el @@ -76,11 +76,12 @@ (keyword . org-man-keyword) (line-break . org-man-line-break) (link . org-man-link) + (node-property . org-man-node-property) (paragraph . org-man-paragraph) (plain-list . org-man-plain-list) (plain-text . org-man-plain-text) (planning . org-man-planning) - (property-drawer . (lambda (&rest args) "")) + (property-drawer . org-man-property-drawer) (quote-block . org-man-quote-block) (quote-section . org-man-quote-section) (radio-target . org-man-radio-target) @@ -663,6 +664,16 @@ INFO is a plist holding contextual information. See ;; No path, only description. Try to do something useful. (t (format "\\fI%s\\fP" desc))))) +;;;; Node Property + +(defun org-man-node-property (node-property contents info) + "Transcode a NODE-PROPERTY element from Org to Man. +CONTENTS is nil. INFO is a plist holding contextual +information." + (format "%s:%s" + (org-element-property :key node-property) + (let ((value (org-element-property :value node-property))) + (if value (concat " " value) "")))) ;;; Paragraph @@ -722,6 +733,12 @@ contextual information." ;;; Property Drawer +(defun org-man-property-drawer (property-drawer contents info) + "Transcode a PROPERTY-DRAWER element from Org to Man. +CONTENTS holds the contents of the drawer. INFO is a plist +holding contextual information." + (and (org-string-nw-p contents) + (format ".RS\n.nf\n%s\n.fi\n.RE" contents))) ;;; Quote Block diff --git a/lisp/ox-md.el b/lisp/ox-md.el index feb611c..1114c50 100644 --- a/lisp/ox-md.el +++ b/lisp/ox-md.el @@ -82,9 +82,11 @@ This variable can be set to either `atx' or `setext'." (item . org-md-item) (line-break . org-md-line-break) (link . org-md-link) + (node-property . org-md-node-property) (paragraph . org-md-paragraph) (plain-list . org-md-plain-list) (plain-text . org-md-plain-text) + (property-drawer . org-md-property-drawer) (quote-block . org-md-quote-block) (quote-section . org-md-example-block) (section . org-md-section) @@ -334,6 +336,18 @@ a communication channel." (format "[%s](%s)" contents path))))))) +;;;; Node Property + +(defun org-md-node-property (node-property contents info) + "Transcode a NODE-PROPERTY element into Markdown syntax. +CONTENTS is nil. INFO is a plist holding contextual +information." + (format "%s:%s" + (org-element-property :key node-property) + (let ((value (org-element-property :value node-property))) + (if value (concat " " value) "")))) + + ;;;; Paragraph (defun org-md-paragraph (paragraph contents info) @@ -382,6 +396,16 @@ contextual information." text) +;;;; Property Drawer + +(defun org-md-property-drawer (property-drawer contents info) + "Transcode a PROPERTY-DRAWER element into Markdown format. +CONTENTS holds the contents of the drawer. INFO is a plist +holding contextual information." + (and (org-string-nw-p contents) + (replace-regexp-in-string "^" " " contents))) + + ;;;; Quote Block (defun org-md-quote-block (quote-block contents info) diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el index ae9e473..57a9b6e 100644 --- a/lisp/ox-odt.el +++ b/lisp/ox-odt.el @@ -59,6 +59,7 @@ (latex-fragment . org-odt-latex-fragment) (line-break . org-odt-line-break) (link . org-odt-link) + (node-property . org-odt-node-property) (paragraph . org-odt-paragraph) (plain-list . org-odt-plain-list) (plain-text . org-odt-plain-text) @@ -2868,6 +2869,18 @@ INFO is a plist holding contextual information. See "Emphasis" desc))))) +;;;; Node Property + +(defun org-odt-node-property (node-property contents info) + "Transcode a NODE-PROPERTY element from Org to ODT. +CONTENTS is nil. INFO is a plist holding contextual +information." + (org-odt--encode-plain-text + (format "%s:%s" + (org-element-property :key node-property) + (let ((value (org-element-property :value node-property))) + (if value (concat " " value) ""))))) + ;;;; Paragraph (defun org-odt--format-paragraph (paragraph contents default center quote) @@ -3005,11 +3018,11 @@ channel." (defun org-odt-property-drawer (property-drawer contents info) "Transcode a PROPERTY-DRAWER element from Org to ODT. -CONTENTS is nil. INFO is a plist holding contextual -information." - ;; The property drawer isn't exported but we want separating blank - ;; lines nonetheless. - "") +CONTENTS holds the contents of the drawer. INFO is a plist +holding contextual information." + (and (org-string-nw-p contents) + (format "%s" + contents))) ;;;; Quote Block diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el index d289e60..c834087 100644 --- a/lisp/ox-texinfo.el +++ b/lisp/ox-texinfo.el @@ -89,6 +89,7 @@ (keyword . org-texinfo-keyword) (line-break . org-texinfo-line-break) (link . org-texinfo-link) + (node-property . org-texinfo-node-property) (paragraph . org-texinfo-paragraph) (plain-list . org-texinfo-plain-list) (plain-text . org-texinfo-plain-text) @@ -1294,6 +1295,17 @@ are generated directly." ;;(org-texinfo--build-detailed-menu parse top info) (org-texinfo--build-menu parse 1 info 'detailed))))) +;;;; Node Property + +(defun org-texinfo-node-property (node-property contents info) + "Transcode a NODE-PROPERTY element from Org to Texinfo. +CONTENTS is nil. INFO is a plist holding contextual +information." + (format "%s:%s" + (org-element-property :key node-property) + (let ((value (org-element-property :value node-property))) + (if value (concat " " value) "")))) + ;;; Paragraph (defun org-texinfo-paragraph (paragraph contents info) @@ -1398,11 +1410,10 @@ information." (defun org-texinfo-property-drawer (property-drawer contents info) "Transcode a PROPERTY-DRAWER element from Org to Texinfo. -CONTENTS is nil. INFO is a plist holding contextual -information." - ;; The property drawer isn't exported but we want separating blank - ;; lines nonetheless. - "") +CONTENTS holds the contents of the drawer. INFO is a plist +holding contextual information." + (and (org-string-nw-p contents) + (format "@verbatim\n%s@end verbatim" contents))) ;;; Quote Block diff --git a/lisp/ox.el b/lisp/ox.el index 6c59368..7e1d932 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -128,6 +128,7 @@ (:with-latex nil "tex" org-export-with-latex) (:with-planning nil "p" org-export-with-planning) (:with-priority nil "pri" org-export-with-priority) + (:with-properties nil "prop" org-export-with-properties) (:with-smart-quotes nil "'" org-export-with-smart-quotes) (:with-special-strings nil "-" org-export-with-special-strings) (:with-statistics-cookies nil "stat" org-export-with-statistics-cookies) @@ -396,10 +397,11 @@ This option can also be set on with the CREATOR keyword." "Non-nil means export contents of standard drawers. When t, all drawers are exported. This may also be a list of -drawer names to export. If that list starts with `not', only -drawers with such names will be ignored. +drawer names to export, as strings. If that list starts with +`not', only drawers with such names will be ignored. -This variable doesn't apply to properties drawers. +This variable doesn't apply to properties drawers. See +`org-export-with-properties' instead. This option can also be set with the OPTIONS keyword, e.g. \"d:nil\"." @@ -557,6 +559,19 @@ e.g. \"pri:t\"." :group 'org-export-general :type 'boolean) +(defcustom org-export-with-properties nil + "Non-nil means export contents of properties drawers. + +When t, all properties are exported. This may also be a list of +properties to export, as strings. + +This option can also be set with the OPTIONS keyword, +e.g. \"prop:t\"." + :group 'org-export-general + :version "24.4" + :package-version '(Org . "8.2") + :type 'boolean) + (defcustom org-export-with-section-numbers t "Non-nil means add section numbers to headlines when exporting. @@ -2072,7 +2087,14 @@ a tree with a select tag." (not (eq todo-type with-tasks))) (and (consp with-tasks) (not (member todo with-tasks)))))))) ((latex-environment latex-fragment) (not (plist-get options :with-latex))) + (node-property + (let ((properties-set (plist-get options :with-properties))) + (cond ((null properties-set) t) + ((consp properties-set) + (not (member-ignore-case (org-element-property :key blob) + properties-set)))))) (planning (not (plist-get options :with-planning))) + (property-drawer (not (plist-get options :with-properties))) (statistics-cookie (not (plist-get options :with-statistics-cookies))) (table-cell (and (org-export-table-has-special-column-p diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el index 54248cb..47c68d7 100644 --- a/testing/lisp/test-ox.el +++ b/testing/lisp/test-ox.el @@ -479,6 +479,25 @@ Paragraph" (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]" (org-export-as (org-test-default-backend) nil nil nil '(:with-planning nil)))))) + ;; Property Drawers. + (should + (equal "* H1\n" + (org-test-with-temp-text + "* H1\n :PROPERTIES:\n :PROP: value\n :END:" + (org-export-as (org-test-default-backend) + nil nil nil '(:with-properties nil))))) + (should + (equal "* H1\n:PROPERTIES:\n:PROP: value\n:END:\n" + (org-test-with-temp-text + "* H1\n :PROPERTIES:\n :PROP: value\n :END:" + (org-export-as (org-test-default-backend) + nil nil nil '(:with-properties t))))) + (should + (equal "* H1\n:PROPERTIES:\n:B: 2\n:END:\n" + (org-test-with-temp-text + "* H1\n :PROPERTIES:\n :A: 1\n :B: 2\n:END:" + (org-export-as (org-test-default-backend) + nil nil nil '(:with-properties ("B")))))) ;; Statistics cookies. (should (equal "" -- 1.8.4 --=-=-=--