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

Refile and capture to result of a query #177

Open
Zetagon opened this issue Jan 2, 2021 · 5 comments
Open

Refile and capture to result of a query #177

Zetagon opened this issue Jan 2, 2021 · 5 comments

Comments

@Zetagon
Copy link

Zetagon commented Jan 2, 2021

I'm not sure if this is in the scope of this project so I'm opening this issue to ask about that.

I have written a first implementation for refiling and capturing to the result of an org-ql query. This is useful for people who want more precise refiling or capturing. You can find the implementation here: https://github.com/Zetagon/literate-dotfiles/blob/master/config.org#refiling .

The code is probably not pull request ready, but if you'd like I can prepare a pull request. Otherwise I'll just leave it here in case somebody in the future looks for this functionality.

@alphapapa
Copy link
Owner

There are many possibilities like this that could be enabled by an org-ql query. How best to integrate them is the question. In the future, some kind of org-ql-tools package might be called for. In the meantime, examples like this are probably best shown in documentation.

A few notes about your code:

(defun my/org-refile-to-monthly-review ()
  (interactive)
  (my/org-refile-to-query '(parent (string-equal (org-id-get) "b5fd67ea-2459-472f-836e-deb113602913"))))

That will be a very slow query to execute, because it will have to call those functions on every heading. Org IDs are properties, so use the property predicate, and it will be many times faster.

As well, it doesn't seem necessary to use a parent query. Put the ID on the heading to which you want to refile the entry, and search for it directly using property. That way the query will return one result: the heading to be refiled to.

(defun my/org-parse-headline ()
  "Parse headline at point and put in some more relevant information"
  (--> (org-element-headline-parser (line-end-position))
       (nth 1 it)
       (plist-put it :entry-text
                  (concat
                   (buffer-file-name)
                   ":"
                   (number-to-string (line-number-at-pos))
                   ":"
                   (buffer-substring (line-beginning-position)
                                     (line-end-position))))
       (plist-put it :file-name (buffer-file-name))
       (plist-put it :id (org-id-get-create))
       (plist-put it :buffer (current-buffer))))

That function should not be necessary for refiling an entry. Look at the results returned by the elements-with-markers action. All you need for the target is the marker.

@Zetagon
Copy link
Author

Zetagon commented Jan 4, 2021 via email

@alphapapa
Copy link
Owner

Ok, that makes sense. I guess I can send a PR to the examples.org file?

Before submitting a PR, please post the finished code here.

This is actually intentional but it isn't clearly communicated. The entry with the above ID has 12 subtrees, one for every month. The idea is that I can choose which of the subtrees I want to refile to.

I use that information to display text in the `completing-read' prompt. The file name and line number provides important context and keeps the entries unique. This needs to be computed for each matched entry so I think I will keep the function.

Cool, thanks.

@alphapapa
Copy link
Owner

FWIW, the refile idea should be covered by org-ql-refile:

(defun org-ql-refile (marker)

A capture command is yet to be implemented, but the Org Capture API doesn't seem naturally suited to it (e.g. there doesn't appear to be a function that takes a marker argument to say "capture to here").

@yantar92
Copy link
Contributor

yantar92 commented Mar 15, 2023 via email

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

3 participants