From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Adam Porter <adam@alphapapa.net>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] org-agenda: Add 'none setting for org-agenda-overriding-header
Date: Sat, 02 Sep 2017 09:49:03 +0200 [thread overview]
Message-ID: <87wp5h1qxc.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <87efrphle7.fsf@alphapapa.net> (Adam Porter's message of "Fri, 01 Sep 2017 21:41:52 -0500")
Hello,
Adam Porter <adam@alphapapa.net> writes:
> You're right, that's why IIRC I used cl-defmacro originally. The
> issue here seems to be using the keyword argument. It seemed like a
> good idea to specify it with the ":default: keyword argument for two
> reasons:
>
> 1. To make it explicitly clear that the body of code passed to the
> macro is only the default header, not necessarily the one that will be
> used.
>
> 2. To make it easier to add other arguments in the future.
This is an internal macro. We can add anything without problem in the
future. For now, I really think `defmacro' is enough.
>>> + ;; Format week number span
>>> + (cond ((< (- d2 d1) 350)
>>> + (if (= w1 w2)
>>> + (format " (W%02d)" w1)
>>> + (format " (W%02d-W%02d)" w1 w2)))
>>> + (t ""))
>>
>> (cond ((<= 350 (- d2 d1)) "")
>> ((= w1 w2) (format " (W%02d)" w1))
>> (t (format " (W%02d-W%02d)" w1 w2)))
>
> I see. That doesn't seem to be exactly the same logic as the nested if,
Why do you think it isn't equivalent?
>>> - (let ((n 0) s)
>>> - (mapc (lambda (x)
>>> - (setq s (format "(%d)%s" (setq n (1+ n)) x))
>>> - (if (> (+ (current-column) (string-width s) 1) (frame-width))
>>> - (insert "\n "))
>>> - (insert " " s))
>>> - kwds))
>>> + (cl-loop for keyword in kwds
>>> + and num from 1
>>> + for string = (format "(%d)%s" num keyword)
>>> + when (> (+ (current-column) (string-width string) 1)
>>> + (window-width))
>>> + do (insert "\n ")
>>> + do (insert " " string))
>>
>> Ouch. Why `cl-loop' over `dolist'? Also it looks wrong since the last
>> `do' is not always executed? (or is it?).
>
> Yes, it is always executed: the "when" only applies to the next clause,
> and I tested it to be sure, both by executing it and expanding the
> macro. I've used cl-loop a lot lately, so it is familiar to me.
This looks too much magical to me. Both `do' are treated differently.
>> I know there is more than one way to skin a cat, but I'd rather use
>> a straightforward one:
>>
>> (let ((n 0))
>> (dolist (k kwds)
>> (let ((s (format "(%d)%s" (cl-incf n) k)))
>> (when (> (+ (current-column) (string-width s) 1) (frame-width))
>> (insert "\n "))
>> (insert " " s))))
>
> I guess this is a matter of style, as I prefer the cl-loop version,
> which doesn't hide the incrementing in the format call
You must be kidding. `cl-loop' hides a lot of things. In any case, you
can increment the counter above the `s' binding if you want to.
> and avoids another level of nesting just for the counter variable. :)
> But if you want me to use the dolist instead, it's up to you.
I'd rather have `dolist' yes. That's more basic and therefore, easier to
understand.
Thank you.
Regards,
--
Nicolas Goaziou
next prev parent reply other threads:[~2017-09-02 7:49 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-16 4:20 [PATCH] org-agenda: Add 'none setting for org-agenda-overriding-header Adam Porter
2017-08-17 14:25 ` Nicolas Goaziou
2017-08-17 19:57 ` Adam Porter
2017-08-18 9:07 ` Nicolas Goaziou
2017-08-20 2:47 ` Adam Porter
2017-08-20 8:25 ` Nicolas Goaziou
2017-08-23 1:41 ` Adam Porter
2017-08-23 2:32 ` Adam Porter
2017-08-23 8:48 ` Nicolas Goaziou
2017-09-02 2:41 ` Adam Porter
2017-09-02 7:49 ` Nicolas Goaziou [this message]
2017-09-03 1:44 ` Adam Porter
2017-09-06 11:17 ` Nicolas Goaziou
2017-09-06 23:00 ` Adam Porter
2017-09-10 12:32 ` Nicolas Goaziou
2017-09-06 23:06 ` Adam Porter
2017-08-23 8:37 ` Nicolas Goaziou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wp5h1qxc.fsf@nicolasgoaziou.fr \
--to=mail@nicolasgoaziou.fr \
--cc=adam@alphapapa.net \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.