alphapapa / org-ql

A searching tool for Org-mode, including custom query languages, commands, saved searches and agenda-like views, etc.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

helm-org-ql shows no results

landakram opened this issue Β· comments

I'm pretty sure helm-org-ql isn't working on master. I ran into the issue with some of my own code that I shamelessly lifted from you πŸ˜›

Basically, helm-org-ql--heading returns a cons cell: https://github.com/alphapapa/org-ql/blob/master/helm-org-ql.el#L217

This then get incorrectly flattened in org-ql-select: https://github.com/alphapapa/org-ql/blob/master/org-ql.el#L272

This produces an error like (wrong-type-argument listp #<marker at 77113 in some-org-file.org>) that gets swallowed by the ignore-errors here: https://github.com/alphapapa/org-ql/blob/master/helm-org-ql.el#L187

I tested this with the following init.el:

(setq user-init-file (or load-file-name (buffer-file-name)))
(setq user-emacs-directory (file-name-directory user-init-file))

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(setq package-enable-at-startup nil)
(package-initialize)
(when (not package-archive-contents)
  (package-refresh-contents))

(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

(straight-use-package 'use-package)

(use-package helm
  :straight t)

(use-package org-ql
  :straight t)

(use-package helm-org-ql
  :straight t)

And then running M-x helm-org-ql-org-directory.

In my own code, I worked around this by changing the return type of helm-org-ql--heading to be a text object, setting the point-marker as a text property and then turning it back into a cons cell inside the helm-org-ql-source candidate function: landakram/org-z@8f32cb4#diff-45a6113f0a5362216add4458e26c4de186589ee9168a3b4691dcef5255b759a6L191

Happy to make a PR here if that direction sounds good to you.

Hello, @landakram.

I'm pretty sure helm-org-ql isn't working on master.

helm-org-ql works on my machine. Both helm-org-ql-org-directory and (helm-org-ql (org-agenda-files)) work. I am using straight, and I am using org-ql on the latest master now. There must be something wrong with your config. Did you rebuild org-ql and helm-org-ql after pulling the recent version of the package?

This then get incorrectly flattened in org-ql-select

(-flatten-n 1 LIST) flattens the list only once. In this situation, it takes entries grouped by buffers (--map) and returns a flat list of entries. It is definitely a correct implementation.

I had issues with helm-org-ql on the latest commit as well.

I fixed it by replacing
(cons (concat prefix path) (point-marker))) with (list (concat prefix path) (point-marker))))
and
(let ((marker (car marker)))
before parsing in helm-org-ql-show-marker-*

Apologies, I haven't had time to come back to this issue.

@natask, yes, that would be the same bug. -flatten-n assumes that it is working with a list in the cdr position. Because it is instead passed a cons cell with a value in the cdr position, it errors with wrong-type-argument listp. You can minimally reproduce this with:

(-flatten-n 1 ("one" . "two"))

@akirak, to answer your question:

There must be something wrong with your config. Did you rebuild org-ql and helm-org-ql after pulling the recent version of the package?

I first encountered the issue during an upgrade in my own config and stepped through with edebug to discover the root cause. I then reproduced the issue with a clean config that bootstraps straight.el and the org-ql dependency from nothing. I linked the config I used in my original comment, which I ran with emacs -Q -l init.el. I just re-ran it and reproduced again.

For what it's worth, the error is swallowed by a call to ignore-errors (also linked above) so it doesn't look like an error to the user, just no results.

I'm not sure why you wouldn't be able to reproduce... unless I'm missing something or you're unwittingly using an older version like you suggested to me πŸ˜›

@landakram Thanks, I encountered the same issue, and I fixed it by replacing (-flatten-n 1) with (apply #'append) inside org-ql-select.

Does it imply this is not a bug with org-ql but with -flatten-n?

Actually, I noticed it at some point after my first comment and fixed it locally, but helm-org-ql works on another machine without the fix. It's not 100% reproducible, and I don't know why.

I've also encountered this issue. Since I'm a newbie, I spent hours trying to diagnose the cause of the problem, assuming it was due to something with my own configuration.

I replaced the line (cons (concat prefix path) (point-marker)))) with the lines

(propertize
(concat prefix path)
'point-marker
(point-marker))))

in the helm-org-ql.el file and re-evaluated the function (C-x C-e). Now all the org headings are showing, but when I make a selection I get the error wrong type argument: markerp.

This looks like a bug with dash.el, so I filed an issue here: magnars/dash.el#373

It's not 100% reproducible, and I don't know why.

That bug was not reproducible because of different versions of dash.el.

The bug has been fixed in the latest version of dash.el, so please update dash and try again. Thanks for digging into the issue!

@akirak, nice catch and thank you so much for following up there. I bumped the dash.el version to 2.18.1 here: #197. I'm glad we got to the root issue rather than a workaround on top, thank you again!

Should be fixed with #197.