Skip to content

support custom minibuffer matching function#2177

Merged
jethrokuan merged 2 commits intoorg-roam:mainfrom
cuttlefisch:main
May 28, 2022
Merged

support custom minibuffer matching function#2177
jethrokuan merged 2 commits intoorg-roam:mainfrom
cuttlefisch:main

Conversation

@cuttlefisch
Copy link
Copy Markdown
Contributor

@cuttlefisch cuttlefisch commented Apr 28, 2022

Motivation for this change

Added support for custom completion-read predicate to the
org-rom-node-find function.

The org-roam-node-find function relies on org-roam-node-read,
which already provides the require-match argument to support this
behavior.

This PR adds an optional argument to org-roam-node-find which is
passed to the embedded org-roam-node-read call in order to support
custom completion-read predicates when searching for nodes in the
minibuffer.

Example Usage

Case-insensitive search in the minibuffer:

(defun case-insensitive-matchp (nodes string)
  "Check if the interactive prompt contains a case insensitive
substring of an Org Roam node title."
  (interactive)
  (lambda (needle haystack) (cl-search (downcase needle) (downcase haystack))) nodes)

(defun my-org-roam-node-find ()
  "Wrapper to run case-insensitive search for Org Roam node
titles."
  (interactive)
  (org-roam-node-find nil nil nil #'case-insensitive-matchp))

@jethrokuan jethrokuan merged commit ed7d4f0 into org-roam:main May 28, 2022
@russmatney
Copy link
Copy Markdown
Contributor

I tried to make this work today, but I don't understand how this could ever work - it seems to pass the pred into org-roam-node-read as the sort-fn? Maybe a merge changed those args up? I can't figure it out. Just wanted to call it out, as it was confusing and might be worth cleaning up.

I tried to make pred work as an additional org-roam-node-find arg (maybe those should switch to &key args at some point?), but I don't understand completing-read well enough... ultimately I found this vertico documentation. The very last code block in that section offers:

(setq read-file-name-completion-ignore-case t
      read-buffer-completion-ignore-case t
      completion-ignore-case t)

I was able to get case-insensitive completion by wrapping org-roam-node-find and org-roam-node-insert with a let, like:

;;;###autoload
(defun russ/org-roam-find-file ()
  ""
  (interactive)
  (let ((completion-ignore-case t))
    (org-roam-node-find
     nil nil (lambda (node)
               (= 0 (org-roam-node-level node))))))

;;;###autoload
(defun russ/org-roam-insert-file ()
  ""
  (interactive)
  (let ((completion-ignore-case t))
    (org-roam-node-insert
     (lambda (node)
       (= 0 (org-roam-node-level node))))))

Not sure if that applies to all completion frameworks though - it seems worth supporting a passed completion-predicate like this PR intended.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants