md-roam --format-link during org-roam-insert
oatmealm opened this issue · 16 comments
In a orfg-mode buffer (!), when I highlight some words and try to org-roam-insert
I'm getting the following error.
Debugger entered--Lisp error: (wrong-number-of-arguments (1 . 2) 3) md-roam--format-link("/home/[user]/Nextcloud/roam/יהודים_צפון_אפריקה.org" "יהודי צפון אפריקה" nil) apply(md-roam--format-link ("/home/[user]/Nextcloud/roam/יהודים_צפון_אפריקה.org" "יהודי צפון אפריקה" nil)) org-roam--format-link("/home/[user]/Nextcloud/roam/יהודים_צפון_אפריקה.org" "יהודי צפון אפריקה" nil) (insert (org-roam--format-link target-file-path link-description link-type)) (cond ((and target-file-path (file-exists-p target-file-path)) (if region-text (progn (delete-region beg end) (set-marker beg nil) (set-marker end nil))) (insert (org-roam--format-link target-file-path link-description link-type))) (t (let ((org-roam-capture--info (list (cons 'title title-with-tags) (cons 'slug (funcall org-roam-title-to-slug-function title-with-tags)))) (org-roam-capture--context 'title)) (setq org-roam-capture-additional-template-props (list :region (org-roam-shield-region beg end) :insert-at (point-marker) :link-type link-type :link-description link-description :finalize 'insert-link)) (org-roam-capture--capture)))) (let* (region-text beg end (_ (if (region-active-p) (progn (setq beg (set-marker (make-marker) (region-beginning))) (setq end (set-marker (make-marker) (region-end))) (setq region-text (buffer-substring-no-properties beg end))))) (completions (let ((it (or completions (org-roam--get-title-path-completions)))) (if filter-fn (funcall filter-fn it) it))) (title-with-tags (org-roam-completion--completing-read "File: " completions :initial-input region-text)) (res (cdr (assoc title-with-tags completions))) (title (or (plist-get res :title) title-with-tags)) (target-file-path (plist-get res :path)) (description (or description region-text title)) (link-description (org-roam--format-link-title (if lowercase (downcase description) description) link-type))) (cond ((and target-file-path (file-exists-p target-file-path)) (if region-text (progn (delete-region beg end) (set-marker beg nil) (set-marker end nil))) (insert (org-roam--format-link target-file-path link-description link-type))) (t (let ((org-roam-capture--info (list (cons ... title-with-tags) (cons ... ...))) (org-roam-capture--context 'title)) (setq org-roam-capture-additional-template-props (list :region (org-roam-shield-region beg end) :insert-at (point-marker) :link-type link-type :link-description link-description :finalize 'insert-link)) (org-roam-capture--capture)))) res) (prog1 (let* (region-text beg end (_ (if (region-active-p) (progn (setq beg (set-marker ... ...)) (setq end (set-marker ... ...)) (setq region-text (buffer-substring-no-properties beg end))))) (completions (let ((it (or completions ...))) (if filter-fn (funcall filter-fn it) it))) (title-with-tags (org-roam-completion--completing-read "File: " completions :initial-input region-text)) (res (cdr (assoc title-with-tags completions))) (title (or (plist-get res :title) title-with-tags)) (target-file-path (plist-get res :path)) (description (or description region-text title)) (link-description (org-roam--format-link-title (if lowercase (downcase description) description) link-type))) (cond ((and target-file-path (file-exists-p target-file-path)) (if region-text (progn (delete-region beg end) (set-marker beg nil) (set-marker end nil))) (insert (org-roam--format-link target-file-path link-description link-type))) (t (let ((org-roam-capture--info (list ... ...)) (org-roam-capture--context 'title)) (setq org-roam-capture-additional-template-props (list :region (org-roam-shield-region beg end) :insert-at (point-marker) :link-type link-type :link-description link-description :finalize 'insert-link)) (org-roam-capture--capture)))) res) (setq --change-group-success-- t)) (progn (activate-change-group --change-group-handle--) (prog1 (let* (region-text beg end (_ (if (region-active-p) (progn (setq beg ...) (setq end ...) (setq region-text ...)))) (completions (let ((it ...)) (if filter-fn (funcall filter-fn it) it))) (title-with-tags (org-roam-completion--completing-read "File: " completions :initial-input region-text)) (res (cdr (assoc title-with-tags completions))) (title (or (plist-get res :title) title-with-tags)) (target-file-path (plist-get res :path)) (description (or description region-text title)) (link-description (org-roam--format-link-title (if lowercase (downcase description) description) link-type))) (cond ((and target-file-path (file-exists-p target-file-path)) (if region-text (progn (delete-region beg end) (set-marker beg nil) (set-marker end nil))) (insert (org-roam--format-link target-file-path link-description link-type))) (t (let ((org-roam-capture--info ...) (org-roam-capture--context ...)) (setq org-roam-capture-additional-template-props (list :region ... :insert-at ... :link-type link-type :link-description link-description :finalize ...)) (org-roam-capture--capture)))) res) (setq --change-group-success-- t))) (unwind-protect (progn (activate-change-group --change-group-handle--) (prog1 (let* (region-text beg end (_ (if (region-active-p) (progn ... ... ...))) (completions (let (...) (if filter-fn ... it))) (title-with-tags (org-roam-completion--completing-read "File: " completions :initial-input region-text)) (res (cdr (assoc title-with-tags completions))) (title (or (plist-get res :title) title-with-tags)) (target-file-path (plist-get res :path)) (description (or description region-text title)) (link-description (org-roam--format-link-title (if lowercase ... description) link-type))) (cond ((and target-file-path (file-exists-p target-file-path)) (if region-text (progn ... ... ...)) (insert (org-roam--format-link target-file-path link-description link-type))) (t (let (... ...) (setq org-roam-capture-additional-template-props ...) (org-roam-capture--capture)))) res) (setq --change-group-success-- t))) (if --change-group-success-- (accept-change-group --change-group-handle--) (cancel-change-group --change-group-handle--))) (let ((--change-group-handle-- (prepare-change-group)) (undo-outer-limit nil) (undo-limit most-positive-fixnum) (undo-strong-limit most-positive-fixnum) (--change-group-success-- nil)) (unwind-protect (progn (activate-change-group --change-group-handle--) (prog1 (let* (region-text beg end (_ (if ... ...)) (completions (let ... ...)) (title-with-tags (org-roam-completion--completing-read "File: " completions :initial-input region-text)) (res (cdr ...)) (title (or ... title-with-tags)) (target-file-path (plist-get res :path)) (description (or description region-text title)) (link-description (org-roam--format-link-title ... link-type))) (cond ((and target-file-path ...) (if region-text ...) (insert ...)) (t (let ... ... ...))) res) (setq --change-group-success-- t))) (if --change-group-success-- (accept-change-group --change-group-handle--) (cancel-change-group --change-group-handle--)))) (unwind-protect (let ((--change-group-handle-- (prepare-change-group)) (undo-outer-limit nil) (undo-limit most-positive-fixnum) (undo-strong-limit most-positive-fixnum) (--change-group-success-- nil)) (unwind-protect (progn (activate-change-group --change-group-handle--) (prog1 (let* (region-text beg end (_ ...) (completions ...) (title-with-tags ...) (res ...) (title ...) (target-file-path ...) (description ...) (link-description ...)) (cond (... ... ...) (t ...)) res) (setq --change-group-success-- t))) (if --change-group-success-- (accept-change-group --change-group-handle--) (cancel-change-group --change-group-handle--)))) (deactivate-mark)) org-roam-insert(nil) funcall-interactively(org-roam-insert nil) call-interactively(org-roam-insert nil nil) command-execute(org-roam-insert)
I've got things set up in doom as per our previous discussion, using a local checkout of org-roam
and md-roam
installed from the repo.
#+BEGIN_SRC emacs-lisp :tangle packages.el (package! md-roam :recipe (:host github :repo "nobiot/md-roam")) #+END_SRC#+begin_src emacs-lisp
(use-package! md-roam
:config
(setq md-roam-file-extension-single "md"
;; prefer md-roam's native bibkey syntax
md-roam-use-org-extract-ref nil
;; disable Org-roam file link for Markdown files for performance.
md-roam-use-org-file-links nil
org-roam-enable-fuzzy-links t
org-roam-auto-replace-fuzzy-links nil)
(setq org-roam-title-sources '((mdtitle title mdheadline headline) (mdalias alias))
org-roam-file-extensions '("org" "md")))
#+end_src
When md-roam
is disabled things work as expected.
You may have an incompatible versions of Org-roam and Md-roam. Updating Org-roam might be the easier option. Md-roam does not have an easy versioning (you could go back in time with git, but...); I think I am implicitly assuming we are on the latest commit of Org-roam...
If version is not an issue, then I'll need to have a look.
In a orfg-mode buffer (!), when I highlight some words and try to org-roam-insert I'm getting the following error.
Just tested it on my PC (my Org-roam is at a couple of commits back); I don't get the same error.
org-roam
is up to date with origin/master (local clone) ... should I pin it to a particular commit?
Hmm. Strange. I just updated to the latest commit of Org-roam (da6af3a4688fe14bb5bcd64307b9293ae0372e73); no problem with marking some text, and then do org-roam-insert
in an org file within my org-roam-directory (with Md-roam on).
... But you may notice that the "catpure" is creating an md file; perhaps your capture template may need to be adjusted?
I need to start working 😭
As a quick work around for you to get going, you might like to remove this advice (md-roam--format-link
appears to have a mismatching signature from the input in your case, for some unknown reasons).
This is the advice md-roam is putting on Org-roam's equivalent:
(advice-add 'org-roam--format-link :before-until #'md-roam--format-link)
I can't look up the exact syntax of advice-remove
, but I suspect you could do something like:
(advice-remove 'org-roam--format-link #'md-roam--format-link)
It's strange. Your issue looks really similar to the one that was fixed some time ago...
#35
Do you have the latest doom sync
'ed?
Yes, I ran doom sync. I've removed the advice as per your recommendation, and indeed it works....!
Thanks a lot..A we can continue checking when you'll have time!
Leaving open for now.
When you have time, could you try manually delete the whole md-roam folder inside your .doom.d/.local/straigh/build folder, and sync again -- this ensures that the latest is built for Emacs to use.
With the error report above, I could only think of a possibility that your Emacs is using old Md-roam code.
This part:
Debugger entered--Lisp error: (wrong-number-of-arguments (1 . 2) 3)
md-roam--format-link("/home/[user]/Nextcloud/roam/יהודים_צפון_אפריקה.org" "יהודי צפון אפריקה" nil)
I think the error is saying that md-roam--format-link
expects two arguments (one mandatory, the other optional, with the version of Md-roam your Emacs runs now), but you pushed three (that is, the file path, description, and type=nil
). This was exactly the error the previous commit fixed a few weeks ago.
OK. I've cleaned and rebuilt. I'm still getting this error when md-roam
enabled.
Debugger entered--Lisp error: (wrong-number-of-arguments (1 . 2) 3) md-roam--format-link("/home/[user]/Nextcloud/roam/references/מקס וובר.org" "Max Weber" nil) apply(md-roam--format-link ("/home/[user]/Nextcloud/roam/references/מקס וובר.org" "Max Weber" nil)) org-roam--format-link("/home/[user]/Nextcloud/roam/references/מקס וובר.org" "Max Weber" nil) org-roam-insert(nil) funcall-interactively(org-roam-insert nil) call-interactively(org-roam-insert nil nil) command-execute(org-roam-insert)
When you open the help (C-h f
) on the md-roam--format-link
function, what does the Signature and Documentation say?
I have the following.
Signature
(md-roam--format-link TARGET &optional DESCRIPTION TYPE)
Documentation
Formats a [[wikilink]] for a given file TARGET, link DESCRIPTION and link TYPE.
Yes, different signature...
(md-roam--format-link TARGET &optional DESCRIPTION)
Installed with (doom cleaned and rebuilt many times while trying):
(package! md-roam
:recipe (:host github
:repo "nobiot/md-roam"))
Am I missing something?
org-roam
is unpinned.
(package! org-roam :pin nil)
Which is the same us unpin
AFAIK.
Could you try specifying the branch to be "main"?
I think I know what seems to be happening...
'''
;; To grab a particular branch or tag:
(package! example :recipe
(:host gitlab
:repo "username/my-example-fork"
:branch "develop"))
'''
I explicitly specifed "main", but it's interesting that when I save and re-sync doom, I don't see it rebuilding anything... so I assume it was working off the correct branch as it was?
(package! md-roam
:recipe (:host github
:repo "nobiot/md-roam"
:branch "main"))
Another thing, is the default behaviour of org-roam when md-roam
is enabled is to create .md
files? I remeber noticing that before but this time even with md-roam
enabled, .org
files are created and org-roam-insert
fail with the mentioned error....
But it seems like md-roam
is not really/fully being activated....should I see it in the enabled minor modes buffer when creating an org-roam
document using org-roam-file-file
or org-roam-capture
?
This is my current setup:
(use-package! md-roam
:config
(setq md-roam-file-extension-single "md"
;; prefer md-roam's native bibkey syntax
md-roam-use-org-extract-ref nil
;; disable Org-roam file link for Markdown files for performance.
md-roam-use-org-file-links nil))
(after! org-roam
(setq org-roam-file-extensions '("org" "md"))
(setq org-roam-title-sources '((mdtitle title mdheadline headline) (mdalias alias)))
(setq org-roam-tag-sources '(prop md-frontmatter)))
I've both tried setting up the variable with the after-hook!
and directly in the :config section.
org-roam
comes later in the config.file:
(setq org-roam-directory my/org-roam
org-roam-db-location "/home/[user]/.cache/org-roam/org-roam.db")
(after! org-roam
:config
(setq! org-roam-capture-templates
'(("d" "topic" plain #'org-roam--capture-get-point "%?"
:file-name "${slug}"
:head "#+title: ${title}\n"
:unnarrowed t))
org-roam-capture-ref-templates
'(("r" "ref" plain #'org-roam-capture--get-point "%?"
:file-name "bookmarks/${slug}"
:head "#+title: ${title}\n#+roam_key: ${ref}\n#+roam_tags: bookmark\n\n\* ${title}"
:unnarrowed t))))
(add-hook! 'kill-emacs #'org-roam-db-build-cache)
It's setup as "unpinned" but using the "+roam" flag at the moment.
it's interesting that when I save and re-sync doom, I don't see it rebuilding anything.
I would delete the current md-roam
folder in your .doom.d/.local/straight/build
manually then run doom sync again.
I don't fully understand how doom/sync behaves, but I always have failed to "override" locally build packages when a new version is available.
I'm guessing this is no longer an issue. If it still is, please reopen.