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

Refreshing after a query fails #475

Closed
jwiegley opened this issue Nov 6, 2024 · 9 comments
Closed

Refreshing after a query fails #475

jwiegley opened this issue Nov 6, 2024 · 9 comments

Comments

@jwiegley
Copy link

jwiegley commented Nov 6, 2024

OS/platform

macOS

Emacs version and provenance

29.4 macport build via Nix

Emacs command

emacs

Org version and provenance

9.7.13, pulled from Org releases and built with Nix

org-ql package version and provenance

0.9-pre, from nixpkgs

Actions taken

Use this function to perform a query, which works:

(defun org-config-show-filetagged-tasks (tag)
  "Report items pending review after one second."
  (interactive "sTag: ")
  (org-ql-search (org-agenda-files)
    '(and (todo)
          (save-excursion
            (goto-char (point-min))
            (re-search-forward (concat "#\\+filetags:.*:" tag ":") 4096 t)))
    :sort '(scheduled todo)))

Then, hit g to refresh the results buffer.

Observed results

I get this error:

byte-compile-log-warning: Invalid Org QL query: "Invalid Org QL query: \"reference to free variable ‘tag’\", :warning", :error

Expected results

I expected it to refresh the buffer.

Backtrace

Interestingly enough, `debug-on-error` does not catch this error.

Etc.

No response

@alphapapa
Copy link
Owner

Hi John,

I think this is because the query sexp is internally byte-compiled in a lambda, but not as a closure, so it doesn't capture the value of tag in the outer function. I think to fix it you just need to backquote the query sexp and unquote that variable, so its value gets inlined.

@jwiegley
Copy link
Author

jwiegley commented Nov 7, 2024

ah! that makes so much sense

@alphapapa
Copy link
Owner

Also, I think you could test for that filetag in a way that would be a bit more robust and likely friendly to caching...let me see...

@jwiegley
Copy link
Author

jwiegley commented Nov 7, 2024

Yes, that fixed it, thank you so much.

@jwiegley jwiegley closed this as completed Nov 7, 2024
@alphapapa
Copy link
Owner

This seems to work:

(org-ql--value-at
 (point-min) (lambda ()
               (org-entry-get nil "filetags" t)))

org-ql--value-at caches per buffer, as long as the buffer isn't modified. And org-entry-get gets the entry from a document-level :PROPERTIES: drawer. But it does not get it from the #+filetags: header, so you would need to switch from #+filetags: to

:PROPERTIES:
:filetags: 
:END:

But there should also be a function that works with the #+ headers...

@alphapapa
Copy link
Owner

The keywords are in the variable org-options-keywords, but the only function I can find is in org-export, which you might not want to use. Anyway, hope this helps somehow.

@jwiegley
Copy link
Author

jwiegley commented Nov 7, 2024

I definitely don't want to define these properties at the entry level, but only in the #+filetags...

@alphapapa
Copy link
Owner

I definitely don't want to define these properties at the entry level, but only in the #+filetags...

I mean in a document-level properties drawer, not within an entry. Those are still relatively new in Org, so maybe you didn't notice the feature yet. :) (Though I'm only guessing that setting that property in the document-level drawer has the same effect...)

@jwiegley
Copy link
Author

jwiegley commented Nov 7, 2024

Ah, I see. Actually, I currently use BOTH file properties (for file-level ID), and #+filetags, etc. It's nice in a ways because the title and filetags aren't hidden from view due to their being in a property drawer...

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

No branches or pull requests

2 participants