Bill Wishon | 1 May 03:20 2012

[PATCH] fix hook calling in org-export-remove-or-extract-drawers

* lisp/org-exp.el (org-export-remove-or-extract-drawers): Changed funcall to run-hook-with-args-until-success to properly run the org-export-format-drawer-function hook.

The problem was that funcall was being executed on the hook (list of functions) instead of running the hook with run-hook-with-args-until-success, which tries to run potentially a list of hooks until one returns non-nil.

~>Bill

Bastien | 1 May 12:01 2012
Picon

Re: [PATCH] fix hook calling in org-export-remove-or-extract-drawers

Hi Bill,

Thanks for the patch.  Please don't attach patches using
application/octet-stream, patchwork don't catch those -- see 

  http://orgmode.org/worg/org-contribute.html#sec-4-3

Bill Wishon <bill <at> wishon.org> writes:

> * lisp/org-exp.el (org-export-remove-or-extract-drawers): Changed
> funcall to run-hook-with-args-until-success to properly run the
> org-export-format-drawer-function hook.
>
> The problem was that funcall was being executed on the hook (list of
> functions) instead of running the hook with
> run-hook-with-args-until-success, which tries to run potentially a
> list of hooks until one returns non-nil.

I don't really understand why `run-hook-with-args-until-success' is
needed here.  Or `org-export-format-drawer-function' returns a string,
or it returns nil, in case we fall back on `org-export-format-drawer'.

Maybe I miss something?

--

-- 
 Bastien

Bill Wishon | 1 May 16:46 2012

Re: [PATCH] fix hook calling in org-export-remove-or-extract-drawers

Hi Bastien,

I'll try to find a different mail client next time.

On Tue, May 1, 2012 at 3:01 AM, Bastien <bzg <at> gnu.org> wrote:
I don't really understand why `run-hook-with-args-until-success' is
needed here.  Or `org-export-format-drawer-function' returns a string,
or it returns nil, in case we fall back on `org-export-format-drawer'.

My thought was that you could have multiple hooks in org-export-format-drawer-function and each one could be checking for things like "is this html export", "is the drawer name == PROPERTIES" and could decide to take action and return a string, or perhaps take no action, return nil, and let another hook have a shot at the drawer.  The other thing with funcall here is that if you use add-hook to add your function to that hook it creates a list of functions, and when funcall is called on a list of functions instead of an individual function it is an error.

Best,
~>Bill
Bastien | 1 May 19:58 2012
Picon

Re: [PATCH] fix hook calling in org-export-remove-or-extract-drawers

Hi Bill,

Bill Wishon <bill <at> wishon.org> writes:

> My thought was that you could have multiple hooks in
> org-export-format-drawer-function and each one could be checking for
> things like "is this html export", "is the drawer name == PROPERTIES"
> and could decide to take action and return a string, or perhaps take
> no action, return nil, and let another hook have a shot at the
> drawer.

Well, you can implement such checks within the same function :)

We would need to rename `org-export-format-drawer-function' to 
suggest it can be a list of functions -- I don't want to go into
this direction right now, I need to double-check what the new
exporter (contrib/lisp/org-export.el) does wrt this.

Nicolas, how the new exporter handle this?

> The other thing with funcall here is that if you use
> add-hook to add your function to that hook it creates a list of
> functions, and when funcall is called on a list of functions instead
> of an individual function it is an error.

Yes, `org-export-format-drawer-function' supports only one function.

--

-- 
 Bastien

Bill Wishon | 1 May 20:02 2012

Re: [PATCH] fix hook calling in org-export-remove-or-extract-drawers



On Tue, May 1, 2012 at 10:58 AM, Bastien <bzg <at> gnu.org> wrote:
We would need to rename `org-export-format-drawer-function' to
suggest it can be a list of functions

Maybe this is a non-issue then.  I had assumed it was a hook because it was on the page describing org-mode hooks, but your right that it doesn't end in -hook and therefore I shouldn't have been using add-hook to add my function to it but rather just set it to a single function.  Perhaps to make it clearer the worg page on hooks could have a section for the non-hook hooks.
Nicolas Goaziou | 1 May 20:18 2012
Picon

Re: [PATCH] fix hook calling in org-export-remove-or-extract-drawers

Hello,

Bastien <bzg <at> gnu.org> writes:

>> My thought was that you could have multiple hooks in
>> org-export-format-drawer-function and each one could be checking for
>> things like "is this html export", "is the drawer name == PROPERTIES"
>> and could decide to take action and return a string, or perhaps take
>> no action, return nil, and let another hook have a shot at the
>> drawer.
>
> Well, you can implement such checks within the same function :)
>
> We would need to rename `org-export-format-drawer-function' to 
> suggest it can be a list of functions -- I don't want to go into
> this direction right now, I need to double-check what the new
> exporter (contrib/lisp/org-export.el) does wrt this.
>
> Nicolas, how the new exporter handle this?

There is no global `org-export-format-drawer-function' variable, and
each back-end may provide it. I think the "big four" does it.

Though, it's more a convenience variable provided for compatibility with
legacy exporter. There are other, and more standard, ways to achieve the
same result in the new export engine (filters being one).

Filters are lists of functions, by the way.

Regards,

--

-- 
Nicolas Goaziou

Bill Wishon | 1 May 20:29 2012

Re: [PATCH] fix hook calling in org-export-remove-or-extract-drawers



On Tue, May 1, 2012 at 11:18 AM, Nicolas Goaziou <n.goaziou <at> gmail.com> wrote:
There are other, and more standard, ways to achieve the
same result in the new export engine (filters being one).

What I was trying to achieve when I got into trying out the org-export-format-drawer-function was to try and customize the look of the properties drawers when they're exported to html.  By default they are exported as pre formatted text with the class=example.  What would be the right way to reformat this during output so that I could present this in another format, say a table or bullet list?

~>Bill

Nicolas Goaziou | 2 May 14:35 2012
Picon

Re: [PATCH] fix hook calling in org-export-remove-or-extract-drawers

Bill Wishon <bill <at> wishon.org> writes:

> What I was trying to achieve when I got into trying out the
> org-export-format-drawer-function was to try and customize the look of the
> properties drawers when they're exported to html.  By default they are
> exported as pre formatted text with the class=example.  What would be the
> right way to reformat this during output so that I could present this in
> another format, say a table or bullet list?

This is an area I'm still working on in the next export engine.

Filters allow to modify output from a back-end. But back-ends ignore
properties drawers. Therefore, filters aren't useful in this case, since
there's no output to modify in the first place.

Though, you can provide a function telling a back-end how to export
a property drawer. As every call-back function, it must accept three
arguments: the parsed drawer, its contents (nil in this case) and
a plist containing export directives (named the communication channel).

For now, you have to follow strict naming conventions (but I'll remove
them) and call it org-BACKEND-ELEMENT. Here BACKEND is `e-html' and
element `property-drawer'.

Also, all properties in the drawer are stored in an alist under
`:properties' attribute.

So `org-e-html-property-drawer' might look like the following:

#+begin_src emacs-lisp
(defun org-e-html-property-drawer (p-drawer contents info)
  (format "<dl>\n%s\n</dl>"
          (mapconcat
           (lambda (prop)
             (format "<dt>%s</dt><dd>%s</dd>" (car prop) (cdr prop)))
           (org-element-property :properties p-drawer) "\n")))
#+end_src

Now every call to `e-html' back-end will change property drawers into
a description list.

This isn't good enough though, because once this function has been
defined, there's no clean way back and it will affect all HTML export in
the same session. I'm working on providing a way to fix it.

Regards,

--

-- 
Nicolas Goaziou


Gmane