How to to get [[Title of the target note]] working with inline autocomplete in Org-roam

Hi all. I’m having trouble having any sort of completion working at all.

As far as I understood, I should be able to at least use M-x completion-at-point to manually trigger a completion, but this is not working for me. So the C-M-i keybinding does nothing for me.

I also tried calling that function inside double brackets [[someth|]], and it does not work either.

Company itself does give me completions for normal words.

Below is my relevant company config:

  (use-package company
    :ensure t
    :init
    (add-hook 'after-init-hook 'global-company-mode)
    :config
    (add-to-list 'company-frontends 'company-tng-frontend)
    (add-to-list 'company-backends 'company-capf) ; for org-roam completion
    (setq company-dabbrev-downcase nil)
    (setq company-dabbrev-ignore-case nil)
    (setq company-idle-delay 1)
    (setq company-auto-commit nil)
    (setq company-minimum-prefix-length 2)
  )

And my roam config:

(use-package org-roam
    :ensure t
    :custom
    (org-roam-directory "~/Notebooks/org/roam")
    :config
    (org-roam-db-autosync-mode)
    (setq org-roam-completion-everywhere t)
    ;(setq org-roam-completion-system 'ivy)
    ;(setq org-roam-link-title-format "@%s")
    (define-key org-roam-mode-map [mouse-1] #'org-roam-buffer-visit-thing)
    (org-roam-setup)
    :bind (("C-c n l" . org-roam-buffer-toggle)
            ("C-c n f" . org-roam-node-find)
            ("C-c n g" . org-roam-graph)
            ("C-c n i" . org-roam-node-insert)
            :map org-mode-map
            ("C-M-i" . completion-at-point)
))

I only recently upgraded to v2. Is there anything specific related to the v1-v2 changes?
Please help!

I suggest check these…

My guess is company-dabbrev is called before Org-roam is, and Company does not call capf for Org-roam. If this is the case, I don’t know if Company can support two backends run consecutively (I don’t even know if that produces one big list in a pop-up or two separate ones). My guess, in this case, would be you would need to turn off company-dabbrev.

Or use Corfu for one, and Company for the other.

Thanks for the info.

The company-backends value is:

(company-bbdb company-semantic company-cmake company-capf company-clang company-files
	      (company-dabbrev-code company-gtags company-etags company-keywords)
	      company-oddmuse company-dabbrev)

That of org-roam-completion-functions is:

(org-roam-complete-link-at-point org-roam-complete-everywhere)

I can confirm that company-mode is on.

I also tried setting only one backend for company, by (setq company-backends '(company-capf)). But still gets nothing.

Hang on!
I think I get the problem. I wasn’t editing a file in side the roam directory. I thought it would also work if I link into the roam directory.

Now both org-roam-complete-link-at-point and org-roam-complete-everywhere work as expected.

Sorry for the noise.

How does company work when dabbrev and capf are both set like in your org-roam files?

According to the docstring of company-backends:

Only one backend is used at a time. The choice depends on the order of
the items in this list, and on the values they return in response to the
‘prefix’ command (see below). But a backend can also be a “grouped”
one (see below).

So I guess it is because the order.

I said last night that it didn’t work for me because I wasn’t editing a file inside the roam folder. It turns out it wasn’t quite right. I noticed that I have to open a roam file using the C-c n f (org-roam-node-find) function for the completions to work. If I open the very same file, for instance, from the command line (emacs ./org/roam/somefile.org), or using emacs find-file, no roam completions work.

Any idea why?

I think :bind in use-package deferrs loading of Org-roam (see this part in the Use-package README).

defers loading of ace-jump-mode until you actually use it

So when you launch Emacs “from the command line (emacs ./org/roam/somefile.org)”, org-roam has not been loaded yet. Try it yourself again. You would still see some commands in M-x because you would have autoloaded them, but you should see a limited number of these compared to when you have loaded the library.

In the case of find-file, the behaviour should also depend on whether or org-roam has already been loaded or not. My guess is that when you tested find-file, it was probably right after you launched Emacs, thus org-roam had not been loaded.

In general, once org-roam has been loaded, there should be no differecet between find-file and org-roam-node-find for the behaviour of Company.

Indeed! Thanks for helping.