[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [PATCH] Separate clocksum format for durations >= 1 day

From: Toby Cubitt
Subject: Re: [O] [PATCH] Separate clocksum format for durations >= 1 day
Date: Tue, 6 Nov 2012 13:01:32 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

On Tue, Nov 06, 2012 at 11:57:25AM +0100, Nicolas Goaziou wrote:
> Toby Cubitt <address@hidden> writes:
> >> I still think functions are the way to go. Three options in the
> >> defcustom:
> >> 
> >>   - One to provide regular time (i.e 14:40 or 3d 18:32)
> >> 
> >>   - One to provide decimal time with the highest unit available (i.e.
> >>     18,75 h or 2,5 d).
> >> 
> >>   - One free slot for an user-defined function.
> >
> > I like the flexibility of functions. But one drawback of this is that you
> > can't produce your "5 h 32 min" or "5,3 days" examples without defining a
> > new function.
> >
> > It would be nice if tweaking just the format (without
> > changing the numbers themselves) could be done by changing a simple
> > format string.
> >
> > Because the number of placeholders in a format string is fixed, I don't
> > see how to avoid the need for multiple format strings. Perhaps we need a
> > second defcustom that holds a list of format strings, to be used by the
> > functions in your first two choices.
> >
> > The first format string for durations < 1 day (or for all durations if
> > this is the only string in the list), the second for durations >= 1 day.
> > One nice thing is that this could easily be extended in the obvious way
> > if one wanted to allow different formats for durations >= 1 month or
> >>= 1 year.
> >
> > It's slightly ugly that the defaults for the format-string defcustom
> > would have to change depending on the value of the function defcustom. I
> > guess one could either have the format-string defcustom default to nil,
> > and use hard-coded defaults in the functions (which are overridden by a
> > non-nil format string value). Or put both functions and format strings
> > into a single defcustom, e.g. as a list with the function in the first
> > element.
> Actually the number of functions defined doesn't matter much. What
> matters is the number of functions exposed to the end-user, which is 0
> in this situation (or 1 if he decides to write his own). Here, all is
> solved with one defcustom.
> You don't even need to create multiple functions for that. The defcustom
> can store `regular', `decimal' symbols or a function.

Sure, I'm familiar with how defcustoms work.

> Then you can write a generic duration format function that will be used
> across code base with the following template:
> #+begin_src emacs-lisp
> (defun org-build-format-duration (n)
>   "Format duration N according to `org-duration-format' variable.
> N is the duration to display, as a number, expressed in minutes.
> Return formatted duration as a string."
>   (cond ((functionp org-duration-format) (funcall org-duration-format))
>         ((eq org-duration-format 'regular) ...)
>         ((eq org-duration-format 'decimal) ...)
>         (t (error "Invalid `org-duration-format' value"))))
> #+end_src

The issue I pointed out has nothing to do with the internal

> One variable exposed to the user. One function exposed to the developer.
> It's much simpler.

You're missing my point (which probably means I didn't explain it well).

How do I produce the format "5 h 32 min" with your defcustom, without
requiring the user to define their own function? (Assuming that 'regular
produces the current default "5:32" format.)

You still need a way to allow users to supply format strings, so they can
customize the appearance of the `regular' and `decimal' formats. Your own
"5 h 32 min" and "5,3 days" examples demonstrate this.

This either implies a second defcustom for the format strings, or it
implies storing both the format strings and choice of function choice in
the same defcustom. Furthermore, one format string isn't be enough
because you might want to different numbers of placeholders depending on
the duration (which is what my original patch allowed).

Dr T. S. Cubitt
Mathematics and Quantum Information group
Department of Mathematics
Complutense University
Madrid, Spain

email: address@hidden
web:   www.dr-qubit.org

reply via email to

[Prev in Thread] Current Thread [Next in Thread]