alphapapa / org-ql

A searching tool for Org-mode, including custom query languages, commands, saved searches and agenda-like views, etc.
GNU General Public License v3.0
1.35k stars 104 forks source link

Specifying an initial input of org-ql-completing-read #332

Open akirak opened 1 year ago

akirak commented 1 year ago

Hello,

Would you add support for an initial input parameter to org-ql-completing-read? That is, I want to specify the initial input of completing-read called inside the function.

I use the function to find a link target in org-mode. It would be convenient if the word at point (if any) were provided as the initial input. A query prefix is unsuitable here, because I sometimes have to moderate the text.

I don't think it would be difficult to extend the API. What do you think?

alphapapa commented 1 year ago

Hi Akira,

Sure, I think it would just be a matter of adding a :initial-input argument to org-ql-completing-read and then passing it to completing-read.

Also, I'd be interested to know more about the way you intend to use it in your function. I wonder if you have something mind similar to what I recently pushed in this WIP branch: https://github.com/alphapapa/org-ql/commit/7537e71afd9eff961685284f47f8bf34737cc1c3 It lets you find links in Org files using "smart" Org QL matching against link content and the outline path to links' containing entries, and then open a link directly, without having to view its Org entry and activate it from there.

akirak commented 1 year ago

know more about the way you intend to use it in your function

I have an extensive set of transient commands for Org: octopus.el which is part of org-dog repository. org-dog lets you define contexts, so you can associate emacs-lisp.org with emacs-lisp-mode buffers and project1.org with ~/work/group/project1/ and so on according to file name conventions. With octopus, you can access the major-mode Org file with m and the project Org file with p. It's not on MELPA, but it's super efficient. It's my current solution for contextual note-taking and task management.

So I have octopus-insert-link transient command which lets the user select an Org file and insert a link to one of the nodes in the file. Contexts doesn't make much sense here, as I usually just select the current Org file with \, but it provides an infix that enables org-super-link functionality.

One use case of the initial input is as follows: I select a word or phrase in an Org file and replace it with a link to a corresponding Org entry. Another situation is that I replace the target of a bracket link to another entry. The initial input support would save the effort of typing the word. It's trivial, but I frequently encounter a situation like this.

It lets you find links in Org files using "smart" Org QL matching against link content and the outline path to links' containing entries, and then open a link directly, without having to view its Org entry and activate it from there.

That would be nice, but I already have a transient command for that. octopus-find-node. It lets you choose a verb via an infix and run an action on a node in a file. I have the following verb for opening a link:

(defun akirak-org-ql-open-link (files)
  "Open a link at a heading from FILES."
  (require 'org-ql-completing-read)
  (unless akirak-org-ql-link-query
    (setq akirak-org-ql-link-query
          (format "heading-regexp:%s "
                  ;; org-link-any-re contains a space, which makes it unsuitable
                  ;; for use in non-sexp org-ql queries.
                  (rx-to-string `(or (and "http" (?  "s") ":")
                                     (regexp ,org-link-bracket-re))))))
  (if-let (marker (org-ql-completing-read files
                    :query-prefix (concat akirak-org-ql-default-query-prefix
                                          akirak-org-ql-link-query)))
      (org-with-point-at marker
        (org-back-to-heading)
        (org-match-line org-complex-heading-regexp)
        (goto-char (match-beginning 4))
        (org-open-at-point))
    (duckduckgo (car minibuffer-history))))

It's different from your function, but it works for my use case. Nonetheless, your org-ql-open-link function would help other users, and, even though I have my own implementation, I may switch to yours once it is on master. Your packages are always carefully thought and well done. After all, org-ql-completing-read is great.

akirak commented 7 months ago

Hi, I am thinking about this feature again. The above use case was overwhelming, but basically I want to pass a selected text from org-mode as an initial input and choose an entry matching the text. Then I'll replace the original text with a link to the entry. What do you think?

alphapapa commented 7 months ago

Hi, I am thinking about this feature again. The above use case was overwhelming, but basically I want to pass a selected text from org-mode as an initial input and choose an entry matching the text. Then I'll replace the original text with a link to the entry. What do you think?

Well, that could be done with Embark now, too, but if it's something you do often, it could be done as a single command.

akirak commented 7 months ago

@alphapapa Thanks. I will try it out.