nobiot / md-roam

Use Org-roam with markdown files by adding Md-roam as a plug-in. Mix org and markdown files in a single Org-roam database.
GNU General Public License v3.0
332 stars 15 forks source link

Range error while trying to implement the package in Doom Emacs #87

Closed hyperfocus1337 closed 2 weeks ago

hyperfocus1337 commented 2 weeks ago

Amazing idea, thanks for your contribution.

Managed to find and create markdown notes using org-roam-capture, but unfortunately it is not yet fully functional.

I noticed my error aligns with https://github.com/nobiot/md-roam/issues/82, it shows org-roam-complete-everywhere().

Is there anyway to disable completions while using this package? I can do without them... just want the error to disappear so your package becomes usable.

Full backtrace:

⛔ Warning (org-element): ‘org-element-at-point’ cannot be used in non-Org buffer #<buffer 20241003180802-asdfasdfsadfasdsd.md> (markdown-mode)
⛔ Warning (org-element): org-element--cache: Org parser error in 20241003180802-asdfasdfsadfasdsd.md::241. Resetting.
 The error was: (error "rx ‘**’ range error")
 Backtrace:
"  backtrace-to-string(nil)
  org-element-at-point()
  org-in-src-block-p()
  org-roam-complete-everywhere()
  corfu--capf-wrapper(org-roam-complete-everywhere)
  run-hook-wrapped(corfu--capf-wrapper org-roam-complete-everywhere)
  corfu--auto-complete-deferred((#<window 3 on 20241003180802-asdfasdfsadfasdsd.md> #<buffer 20241003180802-asdfasdfsadfasdsd.md> 161 241))
  apply(corfu--auto-complete-deferred (#<window 3 on 20241003180802-asdfasdfsadfasdsd.md> #<buffer 20241003180802-asdfasdfsadfasdsd.md> 161 241))
  timer-event-handler([t 26366 54759 127264 nil corfu--auto-complete-deferred ((#<window 3 on 20241003180802-asdfasdfsadfasdsd.md> #<buffer 20241003180802-asdfasdfsadfasdsd.md> 161 241)) nil 999999 nil])
"
 Please report this to Org mode mailing list (M-x org-submit-bug-report).

Using the following code to install:

(package! md-roam :recipe (:host github
                           :repo "nobiot/md-roam"))

Using the following code to configure:

(use-package! md-roam
  :after org-roam
  :config
  (set-company-backend! 'markdown-mode 'company-capf) ; add company-capf as company backend in markdown buffers
  (setq org-roam-file-extensions '("org" "md")) ; enable Org-roam for a markdown files
  (md-roam-mode 1) ; md-roam-mode needs to be active before org-roam-db-sync
  (org-roam-db-autosync-mode 1)
  (setq org-roam-capture-templates
        '(("d" "default" plain "%?"
           :target (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n#+filetags: ${filetags}\n")
           :unnarrowed t)))
  (add-to-list 'org-roam-capture-templates
               '("m" "Markdown" plain ""
                 :target (file+head "%<%Y%m%d%H%M%S>-${slug}.md" "---\ntitle: ${title}\nid: %<%Y%m%d%H%M%S>\ntags:\n- \n---\n")
                 :unnarrowed t)
  (map! :map doom-leader-map "n r o" (λ! (let* ((full-path (buffer-file-name))
                                                (pattern "/notes/\\(.*?\\)\\.md$")
                                                (vault-name "notebook")
                                                obsidian-uri match)
                                                (when (and full-path (string-match pattern full-path))
                                                  (setq match (match-string 1 full-path))
                                                  (setq obsidian-uri (format "obsidian://open?vault=%s&file=%s" vault-name match))
                                                (start-process "open-obsidian" nil "open" obsidian-uri)))))))

Hoping I can be pushed in the right direction, many thanks for any help provided.

hyperfocus1337 commented 2 weeks ago

As was mentioned earlier in https://github.com/nobiot/md-roam/issues/81#issuecomment-1913264726, setting the following makes the range error disappear.

(setq org-roam-completion-everywhere nil)

Make sure it's embedded into (use-package! md-roam), like so:

(use-package! md-roam
  :after org-roam
  :config
  (set-company-backend! 'markdown-mode 'company-capf) ; add company-capf as company backend in markdown buffers
  (setq org-roam-completion-everywhere nil)
  (setq org-roam-file-extensions '("org" "md")) ; enable Org-roam for a markdown files
  (md-roam-mode 1) ; md-roam-mode needs to be active before org-roam-db-sync
  (org-roam-db-autosync-mode 1)
  (setq org-roam-capture-templates
        '(("d" "default" plain "%?"
           :target (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n#+filetags: ${filetags}\n")
           :unnarrowed t)))
  (add-to-list 'org-roam-capture-templates
               '("m" "Markdown" plain ""
                 :target (file+head "%<%Y%m%d%H%M%S>-${slug}.md" "---\ntitle: ${title}\nid: %<%Y%m%d%H%M%S>\ntags:\n- \n---\n")
                 :unnarrowed t)
  (map! :map doom-leader-map "n r o" (λ! (let* ((full-path (buffer-file-name))
                                                (pattern "/notes/\\(.*?\\)\\.md$")
                                                (vault-name "notebook")
                                                obsidian-uri match)
                                                (when (and full-path (string-match pattern full-path))
                                                  (setq match (match-string 1 full-path))
                                                  (setq obsidian-uri (format "obsidian://open?vault=%s&file=%s" vault-name match))
                                                (start-process "open-obsidian" nil "open" obsidian-uri)))))))

This fixes the range error. Closing this issue.