Code Monkey home page Code Monkey logo

Comments (27)

nobiot avatar nobiot commented on August 23, 2024

I would like to fix this issue if I can but I am unable to reproduce it. Could you give me more detail (eg. file samples, step-by-step description, org version). I am afraid I won't be able to help you if you are using Doom or unreleased version of Org or Emacs.

from md-roam.

rickalex21 avatar rickalex21 commented on August 23, 2024

Im using vanilla Emacs. I think I know where the problem is, I've come across this issue before.
This usually happens when org code tries to execute in a non-org buffer. This is why
org-roam has this in the help page about org-roam-extensions:

org-roam-file-extensions is a variable defined in ‘org-roam.el’.

Its value is ("org" "md")
Original value was ("org")

List of file extensions to be included by Org-Roam.
While a file extension different from ".org" may be used, the
file still needs to be an ‘org-mode’ file, and it is the user’s
responsibility to ensure that.

In your docs you suggested that we use md? In this variable org-roam-file-extensions, if you remove md
from the list, org roam now works fine with no errors. This would explain the error caused
in #80 .

REPRODUCE

  1. Make sure no markdown files are open, kill all buffers except your current one, a non markdown file.
  2. open up a markdown file
  3. Start typing and saving eventually you will get an error because org funcs are being executed in a markdown file.

SOLUTION

If the problem is that org roam is executing code in the markdown file because of a variable...

This is my best guess. Figure out where or how roam is executing functions in the markdown file.
Roam was not designed to execute org functions in a markdown file but we are instructing
it to do that when we do : (setq org-roam-file-extensions '("org" "md"))

Another solution would be to create your own function that would update the roam database
by passing the org-roam-file-extensions variable?

TAGS

On another note. I don't use obsidian anymore but I have lots of files that I would like to keep
with the obsidian tags. I was wondering why did you add 1 capture group that ignores
forward slash and the letter "s"? Another thing is why not make md-roam-regex-tags-zettlr-style
more flexible by allowing users to use their own regex instead of adding a substring to remove
your # or @?

I had to modify the code to allow obsidian tags like this, more flexible. I don't understand
why the 1st capture group is needed in the code. Your code is here: line 726

;; Allow obsidian tags
(setq md-roam-regex-tags-zettlr-style "\\([[,]+[ ]?\\)\\([[:alnum:]_-]+\\)[] ]?")

;; My modified code, more flexible. Removed substring

(defun md-roam-get-tags ()
  "Get tags defined in the Zettlr style within frontmatter."
  (let ((endpoint (md-roam-get-yaml-front-matter-endpoint)))
    (cond (endpoint
           (save-excursion
             (let (tags)
               (goto-char (point-min))
               (while (re-search-forward md-roam-regex-tags-zettlr-style endpoint t)
                 (let ((tag (match-string-no-properties 2)))
                   (when tag
                     (setq tags
                           ;; Remove the first char @ or #
                           ;; (append tags (list (substring tag 1)))))))
                           ;; HACK: 12/28/2023 to allow [ tag, tag, tag] for obsidian tags.
                           (append tags (list tag))))))

from md-roam.

nobiot avatar nobiot commented on August 23, 2024

When I change to a markdown file org-roam-ui will not follow it, instead I get this error:

I don't have the error message. No error on my end. See the screen cast below I just took now. I could not include my mouse cursor in the frame, but I hope you see me opening two different markdown notes from within org-roam-ui.

Perhaps you do it different way to get the error?

Screencast.from.30-12-2023.17.31.21.mp4

from md-roam.

nobiot avatar nobiot commented on August 23, 2024

I had to modify the code to allow obsidian tags like this, more flexible. I don't understand
why the 1st capture group is needed in the code.

It's good that you have your own hack that works for you.

I tried your regexp. It does not seem to capture my tags with a "#", like this: #tag1 #tag2. These are also Obsidian tags.

To create a tag, enter a hash symbol (#) in the editor, followed by a keyword. For example, #meeting.

from md-roam.

rickalex21 avatar rickalex21 commented on August 23, 2024

Perhaps you do it different way to get the error?

If you can't reproduce then this is going to be a tough one... I will have to go back to square one.

I tried your regexp. It does not seem to capture my tags

It's not suppose to capture a hash, the idea is to let the user decide on how to capture tags.
I don't think "#" is valid in yaml as this user mentioned
here. Which would make the use of "#" in front matter less portable.

A better, more flexible, and future proof alternative would be to let the user develop their own method of obtaining tags
though md-roam-regex-tags-zettlr-style don't you think so? I think I stated using the
system of [tag1,tag2... because both Hugo and obsidian use it.

A change to md-roam-get-tags would not break anyone's code. When the update is pulled
they will get an updated default regex. Even if it did break someone's package
it wouldn't be as bad as the breaking changes that highly popular emacs packages make.

The updated defvar md-roam-regex-tags-zettlr-style regex would include "#@" . The
updated function md-roam-get-tags would be changed like this:

(when tag (append tags (list tag)))

The gist is to allow a user the flexibility to use their file tags anywhere Hugo, obsidian, emacs ...
If a user has a toolchain setup to publish with Hugo now they need to go back into the countless files and change all the tags from "#tag2 #tag3" etc... to something that is valid.

from md-roam.

nobiot avatar nobiot commented on August 23, 2024

Regarding the tag, see be9ae73.

I need '#' and/or '@' as prefix to the tag -- this is my usage and will not introduce a breaking change for my own use. If you don't use the prefix, this change will let you do so.

With regard to the main issue of the org-roam-ui error, I really can't reproduce it so I won't be able to look at it.

from md-roam.

nobiot avatar nobiot commented on August 23, 2024

Hopefully d05d867 fixes the issue of the main error. Let me know how you go. closing for now.

from md-roam.

rickalex21 avatar rickalex21 commented on August 23, 2024

Thanks for the tags update, unfortunately I am still getting this error when switching to a markdown file.

⛔ Warning (org-element): ‘org-element-at-point’ cannot be used in non-Org buffer #<buffer arch.md> (markdown-mode)

Once I disable md-roam-mode , the error goes away.

It looks like maybe your code somewhere is calling org-element-at-point or there is a function
that calls it in the markdown file? Which in org mode is valid but not elsewhere like a markdown file.
The problem could be in the line 190 containing the minor mode, but at this point I'm just speculating.

from md-roam.

nobiot avatar nobiot commented on August 23, 2024

Could you make sure you are using the latest commit please? Ensure that your Emacs is not using a stale compiled script.

If the issue still persists, perhaps you can share arch.md. I struggle to reproduce the issue. I suspect the content of your markdown file gives us a clue.

from md-roam.

rickalex21 avatar rickalex21 commented on August 23, 2024

What do you mean by stale compiled script?

It happens with any markdown file. I do this:

  1. Open an org file and and md file.
  2. Make sure org roam UI is open and follows
  3. Switch from the org file to the markdown file to see the error.

I made a video, perhaps this will help:

https://youtu.be/u7Gh6pQ-sWg?si=IskprqQvHAZDXQ7E

from md-roam.

nobiot avatar nobiot commented on August 23, 2024

Does the error happen when you don’t use org-roam-ui?

from md-roam.

nobiot avatar nobiot commented on August 23, 2024

I cannot reproduce the issue. I can switch between org and md files with org-roam-ui shown.

Please mute your speaker; there is my loud typing noise and I could not turn off the sound recording.

2024-01-16.12-48-49.mp4

What do you mean by stale compiled script?

If you compile a .el script file, you get .elc. It can stay as it is after you have updated the original .el script. In this case, the .elc is older than the updated .el (stale). You think you are running the latest commit, but in fact your Emacs is still using the old code with .elc. Please make sure you delete or update the .elc file.

from md-roam.

rickalex21 avatar rickalex21 commented on August 23, 2024

I made you a repo to reproduce the error, rename your emacs config and use this minimal config.

git clone https://github.com/rickalex21/emacs-min.git 

I have reproduced this error both on Mac and Linux. You can see the error in this video with
the emacs-min repo:

https://youtu.be/yNeny88ibIw?si=0b6UIQ_5GWHyvhqq

Not sure what your setup is but you need to view the async log, once it gets stuck somewhere
on display numbers or whatever close it and open it up again. It will continue when it left off.
Once you no longer see anything in messages an async log as far as compiling then the files have
finished compiling and you can start using emacs.

Steps to reproduce:

  1. Let emacs do all its compiling
  2. Make sure md-roam-mode is enabled c-h v md-roam-mode
  3. open both files fake.org and fake.md like in the video. :e ~/.config/emacs/org/fake.org :vs fake.md
  4. Click on fake.org
  5. M-x org-roam-ui-open The browser is now open following you.
  6. Go up between headings Org file and Testing in the fake.org to confirm it's following.
  7. Click on fake.md the error occurs:
Warning (org-element): ‘org-element-at-point’ cannot be used in non-Org buffer #<buffer fake.md> (markdown-mode)

from md-roam.

nobiot avatar nobiot commented on August 23, 2024

Can you remove evil and check if you can still repro the issue please? I cannot use vim key-bindings.

Also how do I view the async log?

from md-roam.

nobiot avatar nobiot commented on August 23, 2024

I tried your repo and commented out evil. I cannot reproduce the error...

2024-01-17.08-19-45.mp4

My Emacs version is GNU Emacs 29.1.50. Not sure if it is relevant.

I don't know how evil can be relevant here but try removing it and see if it makes any difference. Other than that, perhaps the Emacs version may be also relevant.

from md-roam.

nobiot avatar nobiot commented on August 23, 2024

Okay, finally I think I can reproduce the issue. It's probably something in org-roam-ui. I will have a quick look.

from md-roam.

nobiot avatar nobiot commented on August 23, 2024

I think it's this line in your configuration: https://github.com/rickalex21/emacs-min/blob/main/init/org-roam-init.el#L28

The call to org-element-at-point seems to be causing this error. On my end, commenting out seems to solve the problem.

Can you remove/comment it out and try again, please?

from md-roam.

rickalex21 avatar rickalex21 commented on August 23, 2024

It still does it with org-roam-node-formatter comment out. If you don't get it can you try disabling and enabling
again md-roam-mode ? I noticed that sometimes I had to do this right now to get it to error again with
my personal config but with the testing config it came up right away.

I am using:

This is GNU Emacs 29.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version
 3.24.38, cairo version 1.16.0) of 2023-08-30, modified by Debian

I presume I can boot in to void and see if I can reproduce there cause this is a pure gtk version of emacs.
Not sure if it will make a difference.

Update: Tested it on void, I'm getting the same error even with commenting. It looks like the error may have originated in org-roam-ui--update-current-node?

Debugger entered--Lisp error: (error "rx ‘**’ range error")
  error("rx `%s' range error" **)
  rx--translate-bounded-repetition(** (1 0 "*"))
  rx--translate-**((1 0 "*"))
  rx--translate-form((** 1 0 "*"))
  rx--translate((** 1 0 "*"))
  rx--translate-seq((line-start (** 1 0 "*") " "))
  rx--translate-form((seq line-start (** 1 0 "*") " "))
  rx--translate((seq line-start (** 1 0 "*") " "))
  rx-to-string((seq line-start (** 1 0 "*") " "))
  org-element-headline-parser(nil fast)
  org-element--parse-to(128)
  org-element-at-point()
  org-back-to-heading(t)
  org-back-to-heading-or-point-min(t)
  org-roam-id-at-point()
  org-roam-ui--update-current-node()

The other error:

Warning (org-element): ‘org-element-at-point’ cannot be used in non-Org buffer #<buffer fake.md> (markdown-mode)
⛔ Warning (org-element): ‘org-element-at-point’ cannot be used in non-Org buffer #<buffer fake.md> (markdown-mode)

from md-roam.

nobiot avatar nobiot commented on August 23, 2024

Can you try this fix, please? Just pushed it:
40c20d0

from md-roam.

rickalex21 avatar rickalex21 commented on August 23, 2024

Now it can follow and the node is recognized :) . However, when I try to edit the frontmatter
I am getting a new error:

⛔ Error (websocket): in callback `on-open': Wrong type argument: stringp, nil
⛔ Warning (org-element): ‘org-element-at-point’ cannot be used in non-Org buffer #<buffer fake.md> (markdown-mode)
⛔ Warning (org-element): ‘org-element-at-point’ cannot be used in non-Org buffer #<buffer fake.md> (markdown-mode)
⛔ Warning (org-element): ‘org-element-at-point’ cannot be used in non-Org buffer #<buffer fake.md> (markdown-mode)

If you want to reproduce try this. It's similar to the original one. Then edit
the front matter and the error will occur.

---
title: Test File
date: 2022-06-16T20:19:25-05:00
id: someid
draft: false
tags: [sometag,sometag2]
---

# Test

Test file.

[[linux]]

Can nodes be added in the front matter? For example:

---
nodes: [[linux]] [[code]]
---

from md-roam.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.