meedstrom / org-node

GNU General Public License v3.0
74 stars 2 forks source link

org-node-backlink-fix-all error - Symbol's value as variable is void: org-file-buffer-created #12

Closed semilin closed 2 months ago

semilin commented 2 months ago

This error occurs when running org-node-backlink-fix-all. Not very helpful backtrace:

Debugger entered--Lisp error: (void-variable org-file-buffer-created)
  org-node-backlink-fix-all()
  funcall-interactively(org-node-backlink-fix-all)
  command-execute(org-node-backlink-fix-all record)
  execute-extended-command(nil "org-node-backlink-fix-all" nil)
  funcall-interactively(execute-extended-command nil "org-node-backlink-fix-all" nil)
  command-execute(execute-extended-command)

For some reason, the function correctly updates the current org buffer I'm looking at, but no other files. I'm on Emacs 30.0.50 if that matters - I'll try with a stable version later.

meedstrom commented 2 months ago

Odd because if the code got to that point, it already ran org-with-file-buffer which is defined in org-macs.el, the same place where org-file-buffer-created is defined...

I put a require org-macs at the top, does it work?

semilin commented 2 months ago

I get the same error, but I realized that the error actually occurs during native compilation. I get these errors when starting emacs and loading org-node.

⛔ Warning (comp): org-node.el:692:13: Warning: the function ‘wgrep-finish-edit’ is not known to be defined.
⛔ Warning (comp): org-node.el:686:11: Warning: the function ‘wgrep-change-to-wgrep-mode’ is not known to be defined.
⛔ Warning (comp): org-node.el:436:19: Warning: the function ‘bol’ is not known to be defined.
⛔ Warning (comp): org-node.el:432:19: Warning: the function ‘eol’ is not known to be defined.
⛔ Warning (comp): org-node.el:245:24: Warning: the function ‘org-roam-capture-’ is not known to be defined.
⛔ Warning (comp): org-node.el:95:32: Warning: the function ‘org-roam-node-create’ is not known to be defined.
⛔ Warning (comp): org-node.el:90:22: Warning: the function ‘org-roam-node-slug’ is not known to be defined.
⛔ Warning (comp): org-node.el:81:10: Warning: the function ‘org-with-file-buffer’ is not known to be defined.
⛔ Warning (comp): org-node.el:73:4: Warning: the function ‘org-super-links-convert-link-to-super’ is not known to be defined.
⛔ Warning (comp): org-node.el:65:29: Warning: the function ‘prompt’ is not known to be defined.
⛔ Warning (comp): org-node-common.el:504:4: Warning: the function ‘org-node-cache-mode’ is not known to be defined.
⛔ Warning (comp): org-node-common.el:493:14: Warning: the function ‘org-node-backlink-mode’ is not known to be defined.
⛔ Warning (comp): org-node-common.el:472:14: Warning: the function ‘org-node-insert-heading’ is not known to be defined.
⛔ Warning (comp): org-node-common.el:462:14: Warning: the function ‘org-node-cache-rescan-file’ is not known to be defined.
⛔ Warning (comp): org-node-common.el:97:35: Warning: the function ‘org-node-new-file’ is not known to be defined.
⛔ Warning (comp): org-node-common.el:85:31: Warning: the function ‘org-node-slugify-as-url’ is not known to be defined.
⛔ Warning (comp): org-node-backlink.el:271:25: Warning: the function ‘org-transclusion-mode’ is not known to be defined.
⛔ Warning (comp): org-node-cache.el:82:21: Warning: the function ‘org-node-cache--collect’ is not known to be defined.
⛔ Warning (comp): org-node-cache.el:27:45: Warning: the function ‘org-node-cache--handle-delete’ is not known to be defined.
⛔ Warning (comp): org-node-backlink.el:235:18: Warning: the function ‘org-element-property’ is not known to be defined.
⛔ Warning (comp): org-node-backlink.el:74:14: Warning: the function ‘org-with-file-buffer’ is not known to be defined.
^
⛔ Warning (comp): org-node-roam.el:222:30: Warning: the function ‘org-roam-db’ is not known to be defined.
⛔ Warning (comp): org-node-roam.el:222:4: Warning: the function ‘emacsql-with-transaction’ is not known to be defined.
⛔ Warning (comp): org-node-roam.el:220:4: Warning: the function ‘org-roam-db--close’ is not known to be defined.
⛔ Warning (comp): org-node-roam.el:219:4: Warning: the function ‘org-roam-db-clear-all’ is not known to be defined.
⛔ Warning (comp): org-node-roam.el:143:6: Warning: the function ‘org-roam-db-query’ is not known to be defined.
⛔ Warning (comp): org-node-roam.el:119:32: Warning: the function ‘org-roam-org-ref-path-to-keys’ is not known to be defined.
⛔ Warning (comp): org-node-roam.el:100:34: Warning: the function ‘org-element-property’ is not known to be defined.
⛔ Warning (comp): org-node-roam.el:98:19: Warning: the function ‘org-element-map’ is not known to be defined.
⛔ Warning (comp): org-node-roam.el:77:32: Warning: the function ‘org-roam-reflink-create’ is not known to be defined.
⛔ Warning (comp): org-node-roam.el:52:17: Warning: the function ‘org-roam-backlink-create’ is not known to be defined.
⛔ Warning (comp): org-node-roam.el:45:21: Warning: the function ‘org-roam-node-id’ is not known to be defined.
⛔ Warning (comp): org-node-roam.el:15:4: Warning: the function ‘org-roam-node-create’ is not known to be defined.

I'm not familiar enough with native comp and package development to know what's going wrong here. It seems like the require calls aren't working at compile time. I looked at some other org packages to see what they do, and I saw org-super-agenda.el has this:

;; I think this is the right way to do this...
(eval-when-compile
  (require 'org-macs))

I tried naively wrapping the org-macs require call in org-node.el and org-node-backlinks.el in eval-when-compile but that doesn't seem to fix the issue.

meedstrom commented 2 months ago

Mind you, those are only warnings, not errors. I don’t know why they’re appearing, but it should be ok.

After reading some StackExchange answers, it sounds like macros in particular (like org-with-file-buffer) need their location loaded/required for every file that invokes them. So my fix from earlier today should work? Does the command work?

All requires will be loaded at compile time - eval-when-compile is just a trick to avoid loading it at runtime. It sounds like require is approximately equivalent to (eval-and-compile (load …)).

On Sun, May 12, 2024 at 19:56 semi @.***> wrote:

I get the same error, but I realized that the error actually occurs during native compilation. I get these errors when starting emacs and loading org-node.

⛔ Warning (comp): org-node.el:692:13: Warning: the function ‘wgrep-finish-edit’ is not known to be defined. ⛔ Warning (comp): org-node.el:686:11: Warning: the function ‘wgrep-change-to-wgrep-mode’ is not known to be defined. ⛔ Warning (comp): org-node.el:436:19: Warning: the function ‘bol’ is not known to be defined. ⛔ Warning (comp): org-node.el:432:19: Warning: the function ‘eol’ is not known to be defined. ⛔ Warning (comp): org-node.el:245:24: Warning: the function ‘org-roam-capture-’ is not known to be defined. ⛔ Warning (comp): org-node.el:95:32: Warning: the function ‘org-roam-node-create’ is not known to be defined. ⛔ Warning (comp): org-node.el:90:22: Warning: the function ‘org-roam-node-slug’ is not known to be defined. ⛔ Warning (comp): org-node.el:81:10: Warning: the function ‘org-with-file-buffer’ is not known to be defined. ⛔ Warning (comp): org-node.el:73:4: Warning: the function ‘org-super-links-convert-link-to-super’ is not known to be defined. ⛔ Warning (comp): org-node.el:65:29: Warning: the function ‘prompt’ is not known to be defined. ⛔ Warning (comp): org-node-common.el:504:4: Warning: the function ‘org-node-cache-mode’ is not known to be defined. ⛔ Warning (comp): org-node-common.el:493:14: Warning: the function ‘org-node-backlink-mode’ is not known to be defined. ⛔ Warning (comp): org-node-common.el:472:14: Warning: the function ‘org-node-insert-heading’ is not known to be defined. ⛔ Warning (comp): org-node-common.el:462:14: Warning: the function ‘org-node-cache-rescan-file’ is not known to be defined. ⛔ Warning (comp): org-node-common.el:97:35: Warning: the function ‘org-node-new-file’ is not known to be defined. ⛔ Warning (comp): org-node-common.el:85:31: Warning: the function ‘org-node-slugify-as-url’ is not known to be defined. ⛔ Warning (comp): org-node-backlink.el:271:25: Warning: the function ‘org-transclusion-mode’ is not known to be defined. ⛔ Warning (comp): org-node-cache.el:82:21: Warning: the function ‘org-node-cache--collect’ is not known to be defined. ⛔ Warning (comp): org-node-cache.el:27:45: Warning: the function ‘org-node-cache--handle-delete’ is not known to be defined. ⛔ Warning (comp): org-node-backlink.el:235:18: Warning: the function ‘org-element-property’ is not known to be defined. ⛔ Warning (comp): org-node-backlink.el:74:14: Warning: the function ‘org-with-file-buffer’ is not known to be defined. ^ ⛔ Warning (comp): org-node-roam.el:222:30: Warning: the function ‘org-roam-db’ is not known to be defined. ⛔ Warning (comp): org-node-roam.el:222:4: Warning: the function ‘emacsql-with-transaction’ is not known to be defined. ⛔ Warning (comp): org-node-roam.el:220:4: Warning: the function ‘org-roam-db--close’ is not known to be defined. ⛔ Warning (comp): org-node-roam.el:219:4: Warning: the function ‘org-roam-db-clear-all’ is not known to be defined. ⛔ Warning (comp): org-node-roam.el:143:6: Warning: the function ‘org-roam-db-query’ is not known to be defined. ⛔ Warning (comp): org-node-roam.el:119:32: Warning: the function ‘org-roam-org-ref-path-to-keys’ is not known to be defined. ⛔ Warning (comp): org-node-roam.el:100:34: Warning: the function ‘org-element-property’ is not known to be defined. ⛔ Warning (comp): org-node-roam.el:98:19: Warning: the function ‘org-element-map’ is not known to be defined. ⛔ Warning (comp): org-node-roam.el:77:32: Warning: the function ‘org-roam-reflink-create’ is not known to be defined. ⛔ Warning (comp): org-node-roam.el:52:17: Warning: the function ‘org-roam-backlink-create’ is not known to be defined. ⛔ Warning (comp): org-node-roam.el:45:21: Warning: the function ‘org-roam-node-id’ is not known to be defined. ⛔ Warning (comp): org-node-roam.el:15:4: Warning: the function ‘org-roam-node-create’ is not known to be defined.

I'm not familiar enough with native comp and package development to know what's going wrong here. It seems like the require calls aren't working at compile time. I looked at some other org packages to see what they do, and I saw org-super-agenda.el has this:

;; I think this is the right way to do this... (eval-when-compile (require 'org-macs))

I tried naively wrapping the org-macs require call in org-node.el and org-node-backlinks.el in eval-when-compile but that doesn't seem to fix the issue.

— Reply to this email directly, view it on GitHub https://github.com/meedstrom/org-node/issues/12#issuecomment-2106329435, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQNTTFYM23AHD43YVOOUVVTZB6ULJAVCNFSM6AAAAABHSON73KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBWGMZDSNBTGU . You are receiving this because you commented.Message ID: @.***>

semilin commented 2 months ago

Huh, odd. No, the same behavior occurs. M-x org-node-backlink-fix-all prompts me if I want to edit the files, then warns me about auto git-commit systems, then Symbol's value as variable is void: org-file-buffer-created. When I run it again, it skips the prompting and errors immediately.

meedstrom commented 2 months ago

I’m not at my computer until tomorrow, but as a workaround you can replace org-file-buffer-created with (bound-and-true-p org-file-buffer-created), that should fix this issue. I’d still like to get to the bottom of this.

On Sun, May 12, 2024 at 22:35 semi @.***> wrote:

Huh, odd. No, the same behavior occurs. M-x org-node-backlink-fix-all prompts me if I want to edit the files, then warns me about auto git-commit systems, then Symbol's value as variable is void: org-file-buffer-created. When I run it again, it skips the prompting and errors immediately.

— Reply to this email directly, view it on GitHub https://github.com/meedstrom/org-node/issues/12#issuecomment-2106367349, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQNTTF7XHBFWOUJNDYFZIHDZB7HAPAVCNFSM6AAAAABHSON73KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBWGM3DOMZUHE . You are receiving this because you commented.Message ID: @.***>

semilin commented 2 months ago

Figured out the issue - the symbols really didn't exist. org-node was using Emacs's built in org version, which doesn't yet have org-file-buffer-created or org-with-file-buffer implemented. I then installed org 9.7 through elpaca, but that didn't fix the problem. I had to add (require 'org) in org-node.el and org-node-backlink.el, forcing it to use the updated org, and I can now successfully run org-node-backlink-fix-all. Probably also worth noting in the README that the package requires a more recent version of org.

meedstrom commented 2 months ago

I must admit that was not in my hypothesis space at all. Thanks for figuring it out, you rock!