mpereira / .emacs.d

Vanilla, Evil, literate Emacs configuration
MIT License
76 stars 8 forks source link

About relative dates in org-ql and org-super-agenda #1

Open alphapapa opened 6 years ago

alphapapa commented 6 years ago

Hi there,

I saw this code in your config:

(let ((inhibit-read-only t))
  (with-current-buffer (get-buffer-create "*org-ql-complex*")
    (erase-buffer)
    (--each '(("Done today" #'closed-today)
              ("Done yesterday" #'closed-yesterday)
              ("Done this week" #'closed-this-week-before-yesterday)
              ("Done last week" #'closed-last-week)
              ("Done this month" #'closed-this-month))
      (--> (list (car it) (funcall (get-in '(1 1) it)
                                   (org-ql (org-agenda-files)
                                     (done)
                                     :sort (date)
                                     :markers t)))
           (list (car it) (--map (concat (org-ql-agenda--format-element it) "\n")
                                 (nth 1 it)))
           (insert (concat (car it) "\n" (apply #'concat (nth 1 it))) "\n")))
    (pop-to-buffer (current-buffer))))

And I saw that you wrote a little library of functions to support it. Very cool!

But I realized that that was only necessary because org-super-agenda doesn't support between dates. I have some prototype code that lets you do something like this:

(let ((org-super-agenda-groups
       '((:name "Done last week"
                :closed (between "last sunday" "last saturday"))
         (:name "Done this week"
                :closed (between "this sunday" "this saturday")))))
  (org-ql-agenda (org-agenda-files)
    (closed)
    :sort (date)))

Supporting "Done this month" would be a bit more complicated because of converting the relative date strings to absolute dates (my code uses GNU date, which doesn't support e.g. first of this month), but it should be doable.

Would you find this useful?

mpereira commented 5 years ago

Hi @alphapapa,

First of all, thanks for even spending your time going through my configuration. Sorry for the delay in replying, I haven't had much free time lately.

The code building *org-ql-complex* is based on the example you gave me a couple of months ago. I was trying to achieve with org-ql, an agenda that I built for reviewing my progress with getting things done. You can find it in my configuration, and it's essentially this:

(setq org-agenda-custom-commands
      `(("r" "Review"
         ((tags ,(mpereira/org-agenda-review-search "today" "+1d")
                ((org-agenda-prefix-format " %i %-18c%?-12t% s")
                 (org-agenda-overriding-header
                  (concat
                   "\nDone today "
                   "(" (format-time-string "%A, %B %d" (current-time)) ")\n"))))
          (tags ,(mpereira/org-agenda-review-search "-1d" "today")
                ((org-agenda-prefix-format " %i %-18c%?-12t% s")
                 (org-agenda-overriding-header
                  (concat
                   "\nDone yesterday "
                   "(" (format-time-string "%A, %B %d" (mpereira/yesterday)) ")\n"))))
          (tags ,(mpereira/org-agenda-review-search
                  (mpereira/org-agenda-date-week-start
                   (mpereira/format-calendar-date-Y-m-d
                    (mpereira/calendar-read-date "today")))
                  (mpereira/org-agenda-date-week-end
                   (mpereira/format-calendar-date-Y-m-d
                    (mpereira/calendar-read-date "today"))))
                ((org-agenda-prefix-format
                  " %-18c %(mpereira/org-agenda-review-suffix-format) ")
                 (org-agenda-show-all-dates t)
                 (org-agenda-sorting-strategy '(timestamp-down))
                 (org-agenda-overriding-header "\nDone this week\n")))
          (tags ,(mpereira/org-agenda-review-search
                  (mpereira/org-agenda-date-week-start
                   (mpereira/format-calendar-date-Y-m-d
                    (mpereira/calendar-read-date "-1w")))
                  (mpereira/org-agenda-date-week-end
                   (mpereira/format-calendar-date-Y-m-d
                    (mpereira/calendar-read-date "-1w"))))
                ((org-agenda-prefix-format
                  " %-18c %(mpereira/org-agenda-review-suffix-format) ")
                 (org-agenda-show-all-dates t)
                 (org-agenda-sorting-strategy '(timestamp-down))
                 (org-agenda-overriding-header "\nDone last week\n"))))
         ((org-agenda-block-separator ?\-)))))

which looks something like this: screencapture-file-users-murilo-emacs-d-agenda_review-html-2018-11-27-23_06_46

(It has a few bugs, but you get the idea).

In addition to using the (IMO) complex and unfriendly org agenda APIs, this agenda required a bunch of custom functions (mpereira/...). If I could do the same using the org-ql API (which is much simpler) it would be super nice.

Unfortunately I didn't have time to achieve "feature parity" with the org-ql-based agenda, but it did seem to be at least possible.

Supporting "Done this month" would be a bit more complicated because of converting the relative date strings to absolute dates (my code uses GNU date, which doesn't support e.g. first of this month), but it should be doable.

Would you find this useful?

Absolutely. What could be even more useful is making it possible to filter (and transform) entries based on functions, instead of being constrained by DSLs. Like what we were doing with closed-this-month in the code you posted, for example.

alphapapa commented 5 years ago

Well, I just happened to be browsing Emacs configs that mentioned org-ql, curious about how people were using it, and I saw your code. :)

I just pushed a commit to a branch that you may find interesting, and sort of relevant. It's mentioned here: https://github.com/alphapapa/org-ql/issues/8 I might be able to do something similar for the closed selector. Let me know what you think.

What could be even more useful is making it possible to filter (and transform) entries based on functions, instead of being constrained by DSLs.

I'm not sure what you mean. Could you give a more specific example?

Thanks.