nim-lang / nim-mode

An emacs major mode for the Nim programming language
137 stars 46 forks source link

org-element-at-point cannot be used in non-Org buffer #245

Closed flintforge closed 10 months ago

flintforge commented 12 months ago

Fixes "File mode specification error: (error ‘org-element-at-point’ cannot be used in non-Org buffer" (org 9.6)

Vindaar commented 11 months ago

Sorry, this has been ignored!

Can you explain how the issue is triggered that this fixes? I think I remember encountering it at some point, but don't remember what causes it.

cvanelteren commented 11 months ago

I installed this using

(package! nim-mode :recipe (:host github :repo "flintforge/nim-mode"))

but the issue still persists.

EDIT:

Also tried it with

(package! nim-mode :recipe (:host github :repo "flintforge/nim-mode" :branch "master-1"))
cvanelteren commented 11 months ago

This issue occurs for me on org 9.6.2 @Vindaar

cvanelteren commented 11 months ago

I think pull was not registered correctly. Manually inserting the line above indeed fixes the problem for me.

Vindaar commented 11 months ago

I think pull was not registered correctly. Manually inserting the line above indeed fixes the problem for me.

Great to hear!

Can you tell me (just so I understand, because I don't reproduce it here on Org 9.6.6) when this happens?

flintforge commented 11 months ago

On Org mode version 9.7-pre (release_9.6.7) (org-in-src-block-p) called out of org-mode will throw the aforementioned error from(org-element-at-point)

This is triggered in nim--common-init and is called when activating nim-mode also in #+begin_src nim blocks, in order to (modify-syntax-entry ?# "<" nim-mode-syntax-table))

A better fix in this PR instead of (eq major-mode 'org-mode)) should be (unless (derived-mode-p 'org-mode))

Vindaar commented 10 months ago

Will you update the PR using unless instead?

cvanelteren commented 10 months ago

For me this error occurs when opening any nim file. Not sure why the org functions are evoked in that case. The source blocks I haven't checked as I dont use nim + org.

flintforge commented 10 months ago

PR updated. The syntax table had to be fixed too.

before:

# generic org comment
#+begin_src nim 
  # regular comment, as in org
     #[ highlighted as a comment
      not highlighted as comment
     ]# → highlighted as comment
#+end_src

after:

#+begin_src nim 
  # comment
     #[ comment
      comment
     ]# → not a  comment
#+end_src
Vindaar commented 10 months ago

Weird, I cannot reproduce your comment behavior here either. The only thing that is wrong in Org babel blocks is that a comment doesn't highlight as such until the closing ]# is inserted for me. But neither does it after your fix.

Anyhow, I don't see any issues running your code either though. My understanding of nim-mode internals (and how it interacts with Org) is pretty limited still. But I would rather merge things quickly instead of having PRs sit here ignored. So if something breaks, just open an issue. :)