emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [Exporter] Export of property drawers
@ 2013-05-09 16:46 Alexander Baier
  2013-05-09 18:13 ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander Baier @ 2013-05-09 16:46 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

i want to export property drawers of an org-file to ASCII.  How do I do
this?  I got the impression, that the exporter does not touch the
properties drawers.  So I started to fiddle with the exporter but got no
satisfying results out of it.

This is what i tried so far:

The elisp i wrote in this process:
===============================================================================
(defun org-tut-ascii-translater-property-drawer (drawer backend info)
  (let ((prop (org-element-property :properties drawer)))
    (format "%S" prop))) ;; i just wanted to see, if anything arrives here

(org-export-define-derived-backend 'my-ascii 'ascii
  :translate-alist '((template .
                      org-tut-ascii-translater-property-drawer)))
===============================================================================

This are my ERT-tests:
===============================================================================
(ert-deftest org-tut-export-test ()
  (with-temp-buffer
    (org-mode)
    (let ((org-export-show-temporary-export-buffer nil))
      (insert (org-tut-test-contents))
      (org-export-to-buffer 'my-ascii "*Org ASCII Export*" nil nil t nil)
      (should (eql (org-tut-result)
                   (with-current-buffer "*Org ASCII Export*"
                     (buffer-substring-no-properties
                      (point-min) (point-max)))))
      )
    )
  )

(defun org-tut-test-contents ()
  nil
  "* Alex
  :PROPERTIES:
  :MATNR:    1234567
  :END:
** Task 1
*** Subtask 1.1
    :PROPERTIES:
    :POINTS:   5
    :END:
")

(defun org-tut-result ()
  nil
  "1 Alex
======
Matnr=1234567

1.1 Task 1 
~~~~~~~~~~

1.1.1 Subtask 1.1
-----------------
Points: 5
")
===============================================================================

Upon exporting I only get the headlines, without any properties related
stuff.

If you need any further info, I will gladly provide it.

Regards,
Alex

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

* Re: [Exporter] Export of property drawers
  2013-05-09 16:46 [Exporter] Export of property drawers Alexander Baier
@ 2013-05-09 18:13 ` Nicolas Goaziou
  2013-05-09 20:01   ` Christian Moe
  2013-05-10 13:14   ` Alexander Baier
  0 siblings, 2 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2013-05-09 18:13 UTC (permalink / raw)
  To: Alexander Baier; +Cc: emacs-orgmode

Hello,

Alexander Baier <lexi.baier@gmail.com> writes:

> i want to export property drawers of an org-file to ASCII.  How do I do
> this?  I got the impression, that the exporter does not touch the
> properties drawers.  So I started to fiddle with the exporter but got no
> satisfying results out of it.

You can either define a new back-end, as you did, or defadvice the
current one.
>
> This is what i tried so far:
>
> The elisp i wrote in this process:
> ===============================================================================
> (defun org-tut-ascii-translater-property-drawer (drawer backend info)
>   (let ((prop (org-element-property :properties drawer)))
>     (format "%S" prop))) ;; i just wanted to see, if anything arrives
> here

There is no `:properties' attribute for property drawers. Also you are
mixing translators and filters: arguments for translators are ELEMENT
CONTENTS INFO. Use, for example:

 (defun my-ascii-property-drawer (drawer contents info)
   contents)


> (org-export-define-derived-backend 'my-ascii 'ascii
>   :translate-alist '((template .
>                       org-tut-ascii-translater-property-drawer)))

Replace `template' with `property-drawer'. You also need to define
a translator for `node-property' elements, e.g.,

  (defun my-ascii-node-property (node-prop contents info)
    (concat (org-element-property :key node-prop)
            ": "
            (org-element-property :value node-prop)))

and

  (org-export-define-derived-backend 'my-ascii 'ascii
    :translate-alist '((property-drawer . my-ascii-property-drawer)
                       (node-property . my-ascii-node-property)))


Regards,

-- 
Nicolas Goaziou

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

* Re: [Exporter] Export of property drawers
  2013-05-09 18:13 ` Nicolas Goaziou
@ 2013-05-09 20:01   ` Christian Moe
  2013-05-10  8:17     ` Nicolas Goaziou
  2013-05-10 13:14   ` Alexander Baier
  1 sibling, 1 reply; 6+ messages in thread
From: Christian Moe @ 2013-05-09 20:01 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Alexander Baier, emacs-orgmode


Hi,

Nicolas, do I understand correctly that the contents of a property
drawer will not export? 

Back before I switched to the new exporter, all
I had to do to export properties was to add

#+OPTIONS: d:t 

but I notice this doesn't work, nor does d:(PROPERTIES).

Properties are sometimes used to make simple databases of useful
stuff. (I compiled a bunch of research notes like that just before
before switching to the new exporter!) It would be nice to have an easy
way to print them without having to figure out how to do it with filters
or defadvices.

Yours,
Christian



Nicolas Goaziou writes:

> Hello,
>
> Alexander Baier <lexi.baier@gmail.com> writes:
>
>> i want to export property drawers of an org-file to ASCII.  How do I do
>> this?  I got the impression, that the exporter does not touch the
>> properties drawers.  So I started to fiddle with the exporter but got no
>> satisfying results out of it.
>
> You can either define a new back-end, as you did, or defadvice the
> current one.
>>
>> This is what i tried so far:
>>
>> The elisp i wrote in this process:
>> ===============================================================================
>> (defun org-tut-ascii-translater-property-drawer (drawer backend info)
>>   (let ((prop (org-element-property :properties drawer)))
>>     (format "%S" prop))) ;; i just wanted to see, if anything arrives
>> here
>
> There is no `:properties' attribute for property drawers. Also you are
> mixing translators and filters: arguments for translators are ELEMENT
> CONTENTS INFO. Use, for example:
>
>  (defun my-ascii-property-drawer (drawer contents info)
>    contents)
>
>
>> (org-export-define-derived-backend 'my-ascii 'ascii
>>   :translate-alist '((template .
>>                       org-tut-ascii-translater-property-drawer)))
>
> Replace `template' with `property-drawer'. You also need to define
> a translator for `node-property' elements, e.g.,
>
>   (defun my-ascii-node-property (node-prop contents info)
>     (concat (org-element-property :key node-prop)
>             ": "
>             (org-element-property :value node-prop)))
>
> and
>
>   (org-export-define-derived-backend 'my-ascii 'ascii
>     :translate-alist '((property-drawer . my-ascii-property-drawer)
>                        (node-property . my-ascii-node-property)))
>
>
> Regards,

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

* Re: [Exporter] Export of property drawers
  2013-05-09 20:01   ` Christian Moe
@ 2013-05-10  8:17     ` Nicolas Goaziou
  2013-05-10 13:37       ` Christian Moe
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2013-05-10  8:17 UTC (permalink / raw)
  To: Christian Moe; +Cc: Alexander Baier, emacs-orgmode

Hello,

Christian Moe <mail@christianmoe.com> writes:

> Nicolas, do I understand correctly that the contents of a property
> drawer will not export?

Correct

> Back before I switched to the new exporter, all
> I had to do to export properties was to add
>
> #+OPTIONS: d:t 
>
> but I notice this doesn't work, nor does d:(PROPERTIES).

No, it won't. See docstring for `org-export-with-drawers'. Property
drawers are very different from regular drawers.

> Properties are sometimes used to make simple databases of useful
> stuff. (I compiled a bunch of research notes like that just before
> before switching to the new exporter!) It would be nice to have an easy
> way to print them without having to figure out how to do it with filters
> or defadvices.

Through macros, you can already access to specific properties, e.g.:

  {{{property(ARCHIVE)}}}

There is no function to dump the whole database in the export buffer
because it contains many Org-specific entries which are irrelevant and
because there are many ways to dump it.

That's not what you asked, but the following function:

#+begin_emacs-lisp
(defun my-database-dump (backend)
  (goto-char (point-min))
  (while (re-search-forward "^[ \t]*:PROPERTIES" nil t)
    (let ((element (org-element-at-point)))
      (when (eq (org-element-type element) 'property-drawer)
        (goto-char (org-element-property :end element))
        (insert "#+BEGIN_EXAMPLE\n"
                (buffer-substring (org-element-property :begin element)
                                  (progn (goto-char
                                          (org-element-property :end element))
                                         (skip-chars-backward " \r\t\n")
                                         (forward-line)
                                         (point)))
                "#+END_EXAMPLE\n")))))
#+end_emacs-lisp

when added to `org-export-before-parsing-hook', will wrap every property
drawer within an example block so it can appear in the export output.


Regards,

-- 
Nicolas Goaziou

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

* Re: [Exporter] Export of property drawers
  2013-05-09 18:13 ` Nicolas Goaziou
  2013-05-09 20:01   ` Christian Moe
@ 2013-05-10 13:14   ` Alexander Baier
  1 sibling, 0 replies; 6+ messages in thread
From: Alexander Baier @ 2013-05-10 13:14 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Alexander Baier, emacs-orgmode

Hello Nicolas,

thank you for the clarification and examples, they helped a lot and I
got it working as I wanted it. 

Regards,
Alex

Nicolas Goaziou <n.goaziou@gmail.com> writes:
> Hello,
>
> Alexander Baier <lexi.baier@gmail.com> writes:
>
>> i want to export property drawers of an org-file to ASCII.  How do I do
>> this?  I got the impression, that the exporter does not touch the
>> properties drawers.  So I started to fiddle with the exporter but got no
>> satisfying results out of it.
>
> You can either define a new back-end, as you did, or defadvice the
> current one.
>>
>> This is what i tried so far:
>>
>> The elisp i wrote in this process:
>> ===============================================================================
>> (defun org-tut-ascii-translater-property-drawer (drawer backend info)
>>   (let ((prop (org-element-property :properties drawer)))
>>     (format "%S" prop))) ;; i just wanted to see, if anything arrives
>> here
>
> There is no `:properties' attribute for property drawers. Also you are
> mixing translators and filters: arguments for translators are ELEMENT
> CONTENTS INFO. Use, for example:
>
>  (defun my-ascii-property-drawer (drawer contents info)
>    contents)
>
>
>> (org-export-define-derived-backend 'my-ascii 'ascii
>>   :translate-alist '((template .
>>                       org-tut-ascii-translater-property-drawer)))
>
> Replace `template' with `property-drawer'. You also need to define
> a translator for `node-property' elements, e.g.,
>
>   (defun my-ascii-node-property (node-prop contents info)
>     (concat (org-element-property :key node-prop)
>             ": "
>             (org-element-property :value node-prop)))
>
> and
>
>   (org-export-define-derived-backend 'my-ascii 'ascii
>     :translate-alist '((property-drawer . my-ascii-property-drawer)
>                        (node-property . my-ascii-node-property)))
>
>
> Regards,

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

* Re: [Exporter] Export of property drawers
  2013-05-10  8:17     ` Nicolas Goaziou
@ 2013-05-10 13:37       ` Christian Moe
  0 siblings, 0 replies; 6+ messages in thread
From: Christian Moe @ 2013-05-10 13:37 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Alexander Baier, emacs-orgmode, Christian Moe


Thanks, Nicolas,

That's very useful to know. And although "d:t" was a lot simpler, I
understand the point that people will want to customize how they want to
export their databases anyway. Your information below is enough to get
me started and may save me days of work.

Yours,
Christian

Nicolas Goaziou writes:

> Through macros, you can already access to specific properties, e.g.:
>
>   {{{property(ARCHIVE)}}}
>
> There is no function to dump the whole database in the export buffer
> because it contains many Org-specific entries which are irrelevant and
> because there are many ways to dump it.
>
> That's not what you asked, but the following function:
>
> #+begin_emacs-lisp
> (defun my-database-dump (backend)
>   (goto-char (point-min))
>   (while (re-search-forward "^[ \t]*:PROPERTIES" nil t)
>     (let ((element (org-element-at-point)))
>       (when (eq (org-element-type element) 'property-drawer)
>         (goto-char (org-element-property :end element))
>         (insert "#+BEGIN_EXAMPLE\n"
>                 (buffer-substring (org-element-property :begin element)
>                                   (progn (goto-char
>                                           (org-element-property :end element))
>                                          (skip-chars-backward " \r\t\n")
>                                          (forward-line)
>                                          (point)))
>                 "#+END_EXAMPLE\n")))))
> #+end_emacs-lisp
>
> when added to `org-export-before-parsing-hook', will wrap every property
> drawer within an example block so it can appear in the export output.
>
>
> Regards,

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

end of thread, other threads:[~2013-05-10 13:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-09 16:46 [Exporter] Export of property drawers Alexander Baier
2013-05-09 18:13 ` Nicolas Goaziou
2013-05-09 20:01   ` Christian Moe
2013-05-10  8:17     ` Nicolas Goaziou
2013-05-10 13:37       ` Christian Moe
2013-05-10 13:14   ` Alexander Baier

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