8000 Fix: prevent preamble evaluation breaking completion framework by chasecaleb · Pull Request #285 · alphapapa/org-ql · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix: prevent preamble evaluation breaking completion framework #285

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

Closed

Conversation

chasecaleb
Copy link

Hi @alphapapa,

I encountered an issue using the heading predicate with org-ql-find interactively. Typing h: throws an error which isn't caught, so in my case as a vertico user it prevents any more completion updates from displaying (i.e. typing into the completion minibuffer no longer updates the completions results list). I think this is an issue with org-ql, not vertico, because org-ql should either prevent the error or catch it.


Reproduction

  1. M-x org-ql-find
  2. Type h:
  3. Trigger completion (automatic in my case with vertico, TAB for default Emacs completion)

Result: backtrace that ends with

  error("Unknown rx symbol `%s'" nil)
  rx--translate-symbol(nil)
  rx--translate(nil)
  rx--translate-seq((bol (1+ "*") (1+ blank) (0+ nonl) nil))
  rx--translate-form((seq bol (1+ "*") (1+ blank) (0+ nonl) nil))
  rx--translate((seq bol (1+ "*") (1+ blank) (0+ nonl) nil))
  rx-to-string((seq bol (1+ "*") (1+ blank) (0+ nonl) nil) no-group)
  #f(compiled-function (strings) #<bytecode -0x5838b1a9927114e>)(nil)
  #f(compiled-function (element) #<bytecode -0x1eae36f5c2ca9854>)((heading))
  mapcar(#f(compiled-function (element) #<bytecode -0x1eae36f5c2ca9854>) ((heading)))
  org-ql--query-preamble((heading))

Alternative reproduction method: run the following elisp snippet and observe the backtrace.

(let* ((query '(heading))
       (normalized (org-ql--normalize-query query))
       (preamble (org-ql--query-preamble normalized)))
  (list :query query
        :normalized normalized
        :preamble preamble))

Fix

I made two different commits with different solutions:

  1. 83cc00a fixes the heading preamble specifically.
  2. 62f4e0b adds error handling to prevent any preamble errors from propagating up.

You could use both commits or just one of them depending on what solution seems preferable to you. Let me know if you would prefer a different solution too.

@alphapapa
Copy link
Owner
alphapapa commented Jun 25, 2022

Hi Caleb,

Thanks for your thorough investigation. The problem is that the predicate has no argument when the query is given for preamble expansion.

This isn't unique to the heading predicate, of course, so what's probably needed is to check in org-ql-find for any predicates that have no argument, and avoid executing the query if that is so. But, of course, some predicates may require no argument (e.g. the todo: predicate), so those should be excepted from the check.

So what's probably really needed is for the org-ql-defpred macro to set an additional property for each predicate specifying whether it requires arguments, and then org-ql-find could determine whether any given predicates require arguments, and avoid running the query if any that do require them have none. Ideally there would be a predicate function, like org-ql--query-arguments-satisfied-p, that would take a sexp query as its argument and return non-nil if all of the predicates in the query that require arguments have some (it wouldn't need to validate them any further than that they exist).

That's a bit more involved, but it's probably The Right Way(TM) to fix it.

By the way, I'm considering publishing org-ql on GNU ELPA, in which case major code contributions would require FSF copyright assignment, like Emacs itself. So before you write any more code, you should keep that in mind.

Thanks.

@alphapapa alphapapa self-assigned this Jun 25, 2022
@alphapapa alphapapa added the bug label Jun 25, 2022
@alphapapa alphapapa added this to the 0.7 milestone Jun 25, 2022
@alphapapa
Copy link
Owner

By the way, while I see the same error you see when I just type h: as the query in org-ql-find, and I also use Vertico, it does not seem to prevent Vertico from working and presenting query results, e.g. if I continue typing an argument like h:emacs.

@chasecaleb
Copy link
Author

That's a bit more involved, but it's probably The Right Way(TM) to fix it.

Yeah, that sounds like a reasonable solution to me.

By the way, I'm considering publishing org-ql on GNU ELPA, in which case major code contributions would require FSF copyright assignment, like Emacs itself. So before you write any more code, you should keep that in mind.

Thanks for the heads up. Unfortunately I'll have to pass on implementing your Right Way solution then, because I don't want to go through the rigamarole involved. I think you should still be able to merge whichever parts of this PR that you're interested in, if any, since it's short enough to meet FSF's trivial change exception.

If you get a chance you might want to call this out in your readme or in a CONTRIBUTING.org file too.

By the way, while I see the same error you see when I just type h: as the query in org-ql-find, and I also use Vertico, it does not seem to prevent Vertico from working and presenting query results, e.g. if I continue typing an argument like h:emacs.

Now that's interesting... Do you know what commit or version of Vertico you're using? I'd like to try with the same one t 8000 o see what's going on. I'm on minad/vertico@afd1e1b, which is in between tags 0.24 and 0.25 (the main branch is currently equivalent to 0.25, for context).

@alphapapa
Copy link
Owner

That's a bit more involved, but it's probably The Right Way(TM) to fix it.

Yeah, that sounds like a reasonable solution to me.

I thought about it some more a few days ago (when I wasn't in front of a keyboard), and IIRC even that wasn't the best solution. So we'll see.

By the way, I'm considering publishing org-ql on GNU ELPA, in which case major code contributions would require FSF copyright assignment, like Emacs itself. So before you write any more code, you should keep that in mind.

Thanks for the heads up. Unfortunately I'll have to pass on implementing your Right Way solution then, because I don't want to go through the rigamarole involved. I think you should still be able to merge whichever parts of this PR that you're interested in, if any, since it's short enough to meet FSF's trivial change exception.

The eventual solution (if I write one) probably won't involve any of that code, but thanks for the offer. (This is why I generally recommend filing an issue before sending a PR, to avoid writing code that doesn't get used--unless you want the coding exercise, that is.)

If you get a chance you might want to call this out in your readme or in a CONTRIBUTING.org file too.

This is a very recent idea, brought to my attention by another user and contributor, so I haven't made it official yet. If and when I do, it will be documented.

By the way, while I see the same error you see when I just type h: as the query in org-ql-find, and I also use Vertico, it does not seem to prevent Vertico from working and presenting query results, e.g. if I continue typing an argument like h:emacs.

Now that's interesting... Do you know what commit or version of Vertico you're using? I'd like to try with the same one to see what's going on. I'm on minad/vertico@afd1e1b, which is in between tags 0.24 and 0.25 (the main branch is currently equivalent to 0.25, for context).

According to Emacs, I'm currently using Vertico 0.14, originally installed from GNU ELPA. I didn't realize it was so far out-of-date, but of course, it works fine, so why upgrade... :)

@alphapapa alphapapa closed this in 9190818 Dec 10, 2022
@alphapapa
Copy link
Owner
alphapapa commented Dec 10, 2022

Hi Caleb,

I've pushed a fix for this problem. I decided to go over all of the predicates and make sure each one that needed to handle nil arguments worked correctly. In my tests with org-ql-find, this problem seems to be resolved. Please let me know if it is for you as well.

Thanks for your help with this issue.

@chasecaleb
Copy link
Author

Tested and verified this fix works, no need for my workaround anymore. Thank you!

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

Successfully merging this pull request may close these issues.

2 participants
0