emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] fix hook calling in org-export-remove-or-extract-drawers
@ 2012-05-01  1:20 Bill Wishon
  2012-05-01 10:01 ` Bastien
  0 siblings, 1 reply; 8+ messages in thread
From: Bill Wishon @ 2012-05-01  1:20 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 400 bytes --]

* 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

[-- Attachment #1.2: Type: text/html, Size: 422 bytes --]

[-- Attachment #2: 0001-Capture-Fix-call-to-org-export-format-drawer-functio.patch --]
[-- Type: application/octet-stream, Size: 1387 bytes --]

From 73df0bdec7289271f4084b91ff633e3537a44df1 Mon Sep 17 00:00:00 2001
From: William Wishon <bill@wishon.org>
Date: Mon, 30 Apr 2012 17:56:18 -0700
Subject: [PATCH] Capture: Fix call to org-export-format-drawer-function hook

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

Modified by William Wishon

TINYCHANGE
---
 lisp/org-exp.el |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index 9aac321..796a86c 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -1519,9 +1519,9 @@ EXP-DRAWERS will be removed."
 	 (delete-region beg (point))
 	 (when (or (eq exp-drawers t)
 		   (member name exp-drawers))
-	   (setq content (funcall (or org-export-format-drawer-function
-				      'org-export-format-drawer)
-				  name content))
+	   (setq content (or (run-hook-with-args-until-success
+			      'org-export-format-drawer-function name content)
+				      (org-export-format-drawer name content)))
 	   (insert content)))))))
 
 (defun org-export-format-drawer (name content)
-- 
1.7.10.msysgit.1


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

* Re: [PATCH] fix hook calling in org-export-remove-or-extract-drawers
  2012-05-01  1:20 [PATCH] fix hook calling in org-export-remove-or-extract-drawers Bill Wishon
@ 2012-05-01 10:01 ` Bastien
  2012-05-01 14:46   ` Bill Wishon
  0 siblings, 1 reply; 8+ messages in thread
From: Bastien @ 2012-05-01 10:01 UTC (permalink / raw)
  To: Bill Wishon; +Cc: emacs-orgmode

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@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

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

* Re: [PATCH] fix hook calling in org-export-remove-or-extract-drawers
  2012-05-01 10:01 ` Bastien
@ 2012-05-01 14:46   ` Bill Wishon
  2012-05-01 17:58     ` Bastien
  0 siblings, 1 reply; 8+ messages in thread
From: Bill Wishon @ 2012-05-01 14:46 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 922 bytes --]

Hi Bastien,

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

On Tue, May 1, 2012 at 3:01 AM, Bastien <bzg@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

[-- Attachment #2: Type: text/html, Size: 1246 bytes --]

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

* Re: [PATCH] fix hook calling in org-export-remove-or-extract-drawers
  2012-05-01 14:46   ` Bill Wishon
@ 2012-05-01 17:58     ` Bastien
  2012-05-01 18:02       ` Bill Wishon
  2012-05-01 18:18       ` Nicolas Goaziou
  0 siblings, 2 replies; 8+ messages in thread
From: Bastien @ 2012-05-01 17:58 UTC (permalink / raw)
  To: Bill Wishon; +Cc: emacs-orgmode

Hi Bill,

Bill Wishon <bill@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

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

* Re: [PATCH] fix hook calling in org-export-remove-or-extract-drawers
  2012-05-01 17:58     ` Bastien
@ 2012-05-01 18:02       ` Bill Wishon
  2012-05-01 18:18       ` Nicolas Goaziou
  1 sibling, 0 replies; 8+ messages in thread
From: Bill Wishon @ 2012-05-01 18:02 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 547 bytes --]

On Tue, May 1, 2012 at 10:58 AM, Bastien <bzg@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.

[-- Attachment #2: Type: text/html, Size: 822 bytes --]

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

* Re: [PATCH] fix hook calling in org-export-remove-or-extract-drawers
  2012-05-01 17:58     ` Bastien
  2012-05-01 18:02       ` Bill Wishon
@ 2012-05-01 18:18       ` Nicolas Goaziou
  2012-05-01 18:29         ` Bill Wishon
  1 sibling, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2012-05-01 18:18 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode, Bill Wishon

Hello,

Bastien <bzg@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

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

* Re: [PATCH] fix hook calling in org-export-remove-or-extract-drawers
  2012-05-01 18:18       ` Nicolas Goaziou
@ 2012-05-01 18:29         ` Bill Wishon
  2012-05-02 12:35           ` Nicolas Goaziou
  0 siblings, 1 reply; 8+ messages in thread
From: Bill Wishon @ 2012-05-01 18:29 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Bastien, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 604 bytes --]

On Tue, May 1, 2012 at 11:18 AM, Nicolas Goaziou <n.goaziou@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

[-- Attachment #2: Type: text/html, Size: 895 bytes --]

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

* Re: [PATCH] fix hook calling in org-export-remove-or-extract-drawers
  2012-05-01 18:29         ` Bill Wishon
@ 2012-05-02 12:35           ` Nicolas Goaziou
  0 siblings, 0 replies; 8+ messages in thread
From: Nicolas Goaziou @ 2012-05-02 12:35 UTC (permalink / raw)
  To: Bill Wishon; +Cc: Bastien, emacs-orgmode

Bill Wishon <bill@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

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

end of thread, other threads:[~2012-05-02 12:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-01  1:20 [PATCH] fix hook calling in org-export-remove-or-extract-drawers Bill Wishon
2012-05-01 10:01 ` Bastien
2012-05-01 14:46   ` Bill Wishon
2012-05-01 17:58     ` Bastien
2012-05-01 18:02       ` Bill Wishon
2012-05-01 18:18       ` Nicolas Goaziou
2012-05-01 18:29         ` Bill Wishon
2012-05-02 12:35           ` 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).