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: Sun, 20 Aug 2017 10:25:38 +0200 [thread overview]
Message-ID: <87wp5yir25.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <87pobrc5vp.fsf@alphapapa.net> (Adam Porter's message of "Sat, 19 Aug 2017 21:47:22 -0500")
Hello,
Adam Porter <adam@alphapapa.net> writes:
> Here is the new patch.
Thank you.
> I took the liberty of using a macro to replace the code that was
> duplicated in the four agenda functions. Please let me know if you
> would like any further changes.
Some comments follow.
> From 203bc583da0c482ab7092623383fe47c2d729420 Mon Sep 17 00:00:00 2001
> From: Adam Porter <adam@alphapapa.net>
> Date: Sat, 19 Aug 2017 21:26:12 -0500
> Subject: [PATCH] org-agenda: Refactor org-agenda-overriding-header code
>
> Replace org-agenda-overriding-header tests in these four functions with
> calls to a macro, eliminating the duplicate code. Also, disable the
> header when the variable is set to the empty string.
Nitpick: the paragraph above usually comes after the list of changes.
> * lisp/org-agenda.el (org-agenda--insert-overriding-header): Add macro.
> (org-agenda-list): Use macro.
> (org-search-view): Use macro.
> (org-todo-list): Use macro.
> (org-tags-view): Use macro.
Nitpick: you can only write "Use macro" once, on the last line.
> +(cl-defmacro org-agenda--insert-overriding-header (&key default)
Why `cl-defmacro'? Usually, `defmacro' is enough.
> + "Insert header into agenda view depending on value of `org-agenda-overriding-header'.
> +If the empty string, don't insert a header. If any other string,
> +insert it as a header. If nil, insert DEFAULT, which should
> +evaluate to a string."
> + (declare (debug (&key form)))
> + `(pcase org-agenda-overriding-header
> + ("" nil) ; Don't insert a header if set to empty string
> + ;; Insert user-specified string
> + ((pred stringp) (insert
> + (org-add-props (copy-sequence org-agenda-overriding-header)
> + nil 'face 'org-agenda-structure)
> + "\n"))
While we're at it,
`org-add-props' + `copy-sequence' = `propertize'
> + ;; When nil, make string automatically and insert it
> + ((pred null) (insert ,default))))
I suggest to use ,@default (and, obviously (&rest default) in the
arguments) so we are not limited to one S-exp.
> + (org-agenda--insert-overriding-header
> + :default (concat (org-agenda-span-name span)
> + "-agenda"
> + (if (< (- d2 d1) 350)
> + (if (= w1 w2)
> + (format " (W%02d)" w1)
> + (format " (W%02d-W%02d)" w1 w2))
> + "")
If you're ready for further refactoring, the nested `if' above could be
turned into a nicer `cond'.
> + (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))
> + (insert "\n"))
Same here: `mapc' + `lambda' = `dolist' to avoid funcall overhead. `s'
could be let-bound too.
All in all, the only requested change is `cl-defmacro' -> `defmacro'.
This is no blocker if you don't want/have time to do the refactoring.
Regards,
--
Nicolas Goaziou
next prev parent reply other threads:[~2017-08-20 8:25 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 [this message]
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
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=87wp5yir25.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.