Skip to content

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

@TristanCacqueray

Description

@TristanCacqueray

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.

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions