Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default date sort does not take into account the :closed property #397

Open
TristanCacqueray opened this issue Jan 9, 2024 · 5 comments
Assignees
Milestone

Comments

@TristanCacqueray
Copy link

TristanCacqueray commented Jan 9, 2024

OS/platform

Linux

Emacs version and provenance

GNU Emacs 30.0.50 built with nix

Emacs command

emacs

Org version and provenance

Org mode version 9.6.7 from nix

org-ql package version and provenance

0.7.1-pre from nix emacs-overlay

Actions taken

Custom format of a org-ql-select results

Observed results

The entries with a :closed date appears out of order

Expected results

The entries should be order similarly than in org-ql-search

Backtrace

Here is the problematic call:

(org-ql-select "~/org/projects.org"
                    '(and (done) (ts :from -3 :to today))
                    :action 'element-with-markers
                    :sort '(date reversed))

And here is a workaround:

(defun tc/compare-entry (b a)
  "Order entry A and B so that they appears from newest to oldest.
This is like org-ql--date< but considering closed date too."
  (cl-macrolet ((ts (item)
                  `(or (org-element-property :closed ,item)
                       (org-element-property :deadline ,item)
                       (org-element-property :scheduled ,item))))
    (org-ql--org-timestamp-element< (ts a) (ts b))))

(org-ql-select "~/org/projects.org"
                    '(and (done) (ts :from -3 :to today))
                    :action 'element-with-markers
                    :sort 'tc/compare-entry)

Etc.

Not sure if that is a bug of feature request.

@alphapapa alphapapa self-assigned this Jan 9, 2024
@alphapapa alphapapa added this to the 0.9 milestone Jan 9, 2024
@alphapapa
Copy link
Owner

Thanks for the request.

@TristanCacqueray
Copy link
Author

You are welcome, thank you for org-ql, it works great! By the way, I wrote a little post about this use-case here: https://tristancacqueray.github.io/blog/no-frills-daily-project-management-with-org-mode

@alphapapa
Copy link
Owner

Thanks for sharing that. I'm always glad to learn about how people are using org-ql. BTW, you might find the dynamic blocks helpful for generating and updating reports like that without having to write much custom code: https://github.com/alphapapa/org-ql/#dynamic-block

@TristanCacqueray
Copy link
Author

@alphapapa sure, here I have another use case for org-ql: https://github.com/TristanCacqueray/gnome-org-next-schedule/

@alphapapa
Copy link
Owner

@alphapapa sure, here I have another use case for org-ql: https://github.com/TristanCacqueray/gnome-org-next-schedule/

Very cool! FYI, I think you could simplify it slightly by writing the query like this:

`(and (not (done)) (not (habit)) (scheduled :from ,(ts-now))))

Note also the use of backquoting/unquoting and (ts-now), because now is not a supported value for the :from argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants