6

Similar to this thread and this one, I want to show an agenda view with all items marked as "DONE" in the last two weeks, but without the lines Clocked: (1:00) DONE Some task (because for that I only care about the totals and use a clock-report dynamic block). I would also like to restrict to second-level items only.

I tried this code and succeeded in restricting to second-level headings only:

(add-to-list 'org-agenda-custom-commands
             '("W" "Weekly review"
               agenda ""
               ((org-agenda-span 'week)
                (org-agenda-start-on-weekday 1)
                (org-agenda-start-with-log-mode nil)
                (org-agenda-skip-function
                 '(org-agenda-skip-entry-if 'notregexp "^\\*\\* DONE "))
                 )))

If I set org-agenda-start-with-log-mode to t, then Clocked: ... lines show, e.g.:

Monday     30 September 2019 W40
  gtd:        10:49-10:59 Clocked:   (0:10) DONE some task
  gtd:        10:50...... Closed:     DONE Some other task

If I set it to nil, then Closed: ... lines do not show.

Also, if I set org-agenda-span to 14, to include the past 14 days, it shows 14 days starting from today.

How can I include only Closed: ... lines, and list tasks in the past?

2 Answers 2

6

To include only Closed: ... use:

(org-agenda-start-with-log-mode '(closed))

To show the past 14 days offset the start day:

(org-agenda-start-day "-14d")

This results in:

(with-eval-after-load 'org-agenda
  (add-to-list 'org-agenda-custom-commands
               '("W" "Weekly review"
                 agenda ""
                 ((org-agenda-start-day "-14d")
                  (org-agenda-span 14)
                  (org-agenda-start-on-weekday 1)
                  (org-agenda-start-with-log-mode '(closed))
                  (org-agenda-skip-function
                   '(org-agenda-skip-entry-if 'notregexp "^\\*\\* DONE "))))))

The statement is wrapped inside with-eval-after-load to make sure that this doesn't throw an error if org-agenda is not yet loaded.

You might also want to include archived items with:

(org-agenda-archives-mode t)

Note: Use C-h v to describe a variable like org-agenda-start-with-log-mode to see the possibilities or M-x custmoize-variable to customize it (this shows all possibilities in the customize interface).

1

I used Hubsian's suggested solution, however, found that the org-agenda-custom-commands variable appears to only be created after the agenda is opened for the first time in an emacs session. This causes an error when loading emacs after closing and reopening:

Symbol's value as variable is void: org-agenda-custom-commands

So instead, I've modified it to create the variable (and keep the "Agenda and all TODOs item that is created with you first open the agenda dispatcher with C-c a):

(setq org-agenda-custom-commands
             '(("W" "Weekly review"
                agenda ""
                ((org-agenda-start-day "-14d")
                 (org-agenda-span 14)
                 (org-agenda-start-on-weekday 1)
                 (org-agenda-start-with-log-mode '(closed))
                 (org-agenda-archives-mode t)
                 (org-agenda-skip-function '(org-agenda-skip-entry-if 'notregexp "^\\*\\* DONE "))))
               ("n" "Agenda and all TODOs"
                agenda ""
                ((alltodo "")))
              ))

setq org-agenda-custom-commands creates the variable org-agenda-custom-commands instead of appending to the existing variable by changing add-to-list to setq and removing the ' before the variable name.

Additionally, we need to wrap the Weekly review item that's being created in an additional set of parenthesis to make it a list since we're creating a new list variable and not appending new entry to an existing one. This is why there are now two ( at the start of the '(("W" "Weekly review" line and an additional at the end the last line.

Note: more information on the options available when creating custom commands can be found by running C-h v RET org-agenda-custom-commands.

Edit: formatting, better explanation and added: "Agenda and all TODOs".

5
  • Could you perhaps elaborate: say how that change made a difference?
    – Drew
    Oct 31, 2020 at 4:27
  • Yes, please clarify which part of your 9-lines of example is the one that makes the difference (and fix the alignment of your lines while you're at it).
    – Stefan
    Nov 1, 2020 at 13:02
  • Apologies, first time answering, is that better now?
    – snlawrence
    Nov 1, 2020 at 21:55
  • Indeed, my code starts with (setq org-agenda-custom-commands ...) and I never ran into this error. Nov 2, 2020 at 10:46
  • Edited my solution to address this by using with-eval-after-load.
    – Hubisan
    Jul 27 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.