emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [patch] Formatting of {{{DATE}}}
@ 2015-02-08 21:16 Rasmus
  2015-02-08 23:37 ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Rasmus @ 2015-02-08 21:16 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi,

I'd quite like to be able to pass a formatting argument to {{{date}}},
much like {{{time(FMT)}}}.  This patch allows this.  I think macros don't
normally have optional arguments, but I find it OK here since it's time
and modification-time works anyway...

On the other hand there might be a good reason that I have overlooked for
why this isn't already accepting a formatting argument.

Any objections?

—Rasmus

-- 
Send from my Emacs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-ox.el-Allow-date-formatting.patch --]
[-- Type: text/x-diff, Size: 1309 bytes --]

From f8de6c716e892e159f80d40d91737ff8ac983877 Mon Sep 17 00:00:00 2001
From: Rasmus <rasmus@gmx.us>
Date: Sun, 8 Feb 2015 21:34:43 +0100
Subject: [PATCH 2/2] * ox.el: Allow {{{date}}} formatting

* ox.el (org-export-as): Allow {{{date}}} to take formatting-argument.

With optional argument, {{{date(FMT)}}} works like {{{time(FMT)}}} if
\#+DATE is a timestamp.
---
 lisp/ox.el | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lisp/ox.el b/lisp/ox.el
index ad3742c..baaab6b 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -2872,7 +2872,18 @@ Return code as a string."
 	  (list (cons "author"
 		      (org-element-interpret-data (plist-get info :author)))
 		(cons "date"
-		      (org-element-interpret-data (plist-get info :date)))
+		      (let* ((date (plist-get info :date))
+			     (date-string (org-element-interpret-data date)))
+			;; Interpret only single time-stamps.
+			(case (and (not (cdr date))
+				   (org-element-type (car date)))
+			  (timestamp
+			   (format
+			    "(eval (if (org-element-property :args macro)
+				      (org-export-get-date info \"$1\")
+				    \"%s\"))"
+			    date-string))
+			  (t date-string))))
 		;; EMAIL is not a parsed keyword: store it as-is.
 		(cons "email" (or (plist-get info :email) ""))
 		(cons "title"
-- 
2.3.0


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

* Re: [patch] Formatting of {{{DATE}}}
  2015-02-08 21:16 [patch] Formatting of {{{DATE}}} Rasmus
@ 2015-02-08 23:37 ` Nicolas Goaziou
  2015-02-09  0:05   ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2015-02-08 23:37 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Hello,

Rasmus <rasmus@gmx.us> writes:

> I'd quite like to be able to pass a formatting argument to {{{date}}},
> much like {{{time(FMT)}}}.  This patch allows this.  I think macros don't
> normally have optional arguments, but I find it OK here since it's time
> and modification-time works anyway...
>
> On the other hand there might be a good reason that I have overlooked for
> why this isn't already accepting a formatting argument.
>
> Any objections?

I have no objection, but please document it in the manual and add
appropriate tests.

>  		(cons "date"
> -		      (org-element-interpret-data (plist-get info :date)))
> +		      (let* ((date (plist-get info :date))
> +			     (date-string (org-element-interpret-data date)))
> +			;; Interpret only single time-stamps.
> +			(case (and (not (cdr date))
> +				   (org-element-type (car date)))
> +			  (timestamp
> +			   (format
> +			    "(eval (if (org-element-property :args macro)
> +				      (org-export-get-date info \"$1\")
> +				    \"%s\"))"
> +			    date-string))
> +			  (t date-string))))

I suggest

  (cons "date"
        (format
         "(eval (if (org-string-nw-p \"$1\") %s %S))"
         "(org-export-get-date info \"$1\")"
         (or (org-element-interpret-data (plist-get info :date))
             "")))

instead.


Regards,

-- 
Nicolas Goaziou

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

* Re: [patch] Formatting of {{{DATE}}}
  2015-02-08 23:37 ` Nicolas Goaziou
@ 2015-02-09  0:05   ` Nicolas Goaziou
  2015-02-09  0:55     ` Rasmus
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2015-02-09  0:05 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Correcting myself,

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> I suggest
>
>   (cons "date"
>         (format
>          "(eval (if (org-string-nw-p \"$1\") %s %S))"
>          "(org-export-get-date info \"$1\")"
>          (or (org-element-interpret-data (plist-get info :date))
>              "")))

Please scratch that, reference to "info" will prevent us to move to use
lexical binding later. Something like this is required instead:

  (cons "date"
        (let* ((date (plist-get info :date))
               (value (or (org-element-interpret-data date) "")))
          (if (and (null (cdr date))
                   (eq (org-element-type (car date)) 'timestamp))
              (format "(eval (if (org-string-nw-p \"$1\") %s %S))"
                      (format "(org-timestamp-format '%S \"$1\")"
                              ;; Remove parent to avoid
                              ;; read error.
                              `(timestamp
                                ,(org-combine-plists
                                  (nth 1 (car date))
                                  '(:parent nil))))
                      value)
            value)))

I think the later part could use an `org-element-copy' function (to be
implemented).

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

* Re: [patch] Formatting of {{{DATE}}}
  2015-02-09  0:05   ` Nicolas Goaziou
@ 2015-02-09  0:55     ` Rasmus
  2015-02-09  8:28       ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Rasmus @ 2015-02-09  0:55 UTC (permalink / raw)
  To: emacs-orgmode

Hi Nicolas,

Thanks for the tips.

Pushed as 8f38f03.  I added a org-NEWS entry, but I don't know if it
should be there.  Feel free to let me know or remove it yourself if it
shouldn't.

BTW: when figuring out how the heck macros works I came across two other
undocumented macros, namely {{{input-file}}} and
{{{property(PROPERTY-NAME)}}}.  I also added those to the manual.

>   (cons "date"
>         (let* ((date (plist-get info :date))
>                (value (or (org-element-interpret-data date) "")))
>           (if (and (null (cdr date))
>                    (eq (org-element-type (car date)) 'timestamp))
>               (format "(eval (if (org-string-nw-p \"$1\") %s %S))"
>                       (format "(org-timestamp-format '%S \"$1\")"
>                               ;; Remove parent to avoid
>                               ;; read error.
>                               `(timestamp
>                                 ,(org-combine-plists
>                                   (nth 1 (car date))
>                                   '(:parent nil))))
>                       value)
>             value)))

Okay, that's cool.  I wasn't aware of %S.

> I think the later part could use an `org-element-copy' function (to be
> implemented).

Seems like it.  Perhaps next weekend!

—Rasmus

-- 
Lasciate ogni speranza o voi che entrate: siete nella mani di'machellaio

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

* Re: [patch] Formatting of {{{DATE}}}
  2015-02-09  0:55     ` Rasmus
@ 2015-02-09  8:28       ` Nicolas Goaziou
  0 siblings, 0 replies; 5+ messages in thread
From: Nicolas Goaziou @ 2015-02-09  8:28 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Rasmus <rasmus@gmx.us> writes:

> Pushed as f8f38f03.

Thank you.

> I added a org-NEWS entry, but I don't know if it should be there. Feel
> free to let me know or remove it yourself if it shouldn't.

That's OK.
>
> BTW: when figuring out how the heck macros works I came across two other
> undocumented macros, namely {{{input-file}}} and
> {{{property(PROPERTY-NAME)}}}.  I also added those to the manual.

Great.

>> I think the later part could use an `org-element-copy' function (to be
>> implemented).
>
> Seems like it.  Perhaps next weekend!

No worries, I'll take care of it today.


Regards,

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

end of thread, other threads:[~2015-02-09  8:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-08 21:16 [patch] Formatting of {{{DATE}}} Rasmus
2015-02-08 23:37 ` Nicolas Goaziou
2015-02-09  0:05   ` Nicolas Goaziou
2015-02-09  0:55     ` Rasmus
2015-02-09  8:28       ` 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).