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

Add a order-by function for org-clock (my solution in here) #405

Open
ag91 opened this issue Feb 3, 2024 · 1 comment
Open

Add a order-by function for org-clock (my solution in here) #405

ag91 opened this issue Feb 3, 2024 · 1 comment

Comments

@ag91
Copy link

ag91 commented Feb 3, 2024

OS/platform

Ubuntu

Emacs version and provenance

28.1

Org version and provenance

9.6.17

org-ql package version and provenance

20240113.647 melpa

Description

Hello, thanks again for the package!

I just wanted to query headings by the most recent I worked on. I automatically start org-clock when I navigate to a heading, so I wanted to use that as recency sorting.
Since your package is so configurable, I made my own comparing function to do the job:

(defun my/org-ql-compare-org-clocks (a b)
    "Compare Org heading A with B using their last clock out time."
    (flet ((get-clockout-time (h)
                              (with-current-buffer (marker-buffer (org-element-property :org-marker h))
                                (save-excursion
                                  (goto-char (marker-position (org-element-property :org-marker h)))
                                  (org-clock-get-last-clock-out-time)))) )
      (ignore-errors (time-less-p (get-clockout-time b)
                   (get-clockout-time a)))))

I thought that maybe other users of org-clock would find it useful, so I wanted to share it here.
Feel free to add it to the package, if you think is general enough.

Etc.

No response

@alphapapa
Copy link
Owner

Hi,

Thanks for sharing that. A couple of thoughts:

  1. You could use org-with-point-at to save a few lines of code.
  2. When org-ql gains support for matching timestamp ranges, this would likely become unnecessary (i.e. sorting by the latest timestamp in an entry would probably be sufficient, even if not identical in all cases).
  3. It might be more performant to bind the results of get-clockout-time and check (and time-a time-b (time-less-p time-b time-a)) than to use ignore-errors around it, but I haven't tested it.

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