shg / org-inline-pdf.el

Inline PDF previewing for Org
GNU General Public License v3.0
48 stars 8 forks source link

Error on loading mode: Invalid function: org-babel-temp-directory #10

Closed onlycparra closed 11 months ago

onlycparra commented 1 year ago

In Doom Emacs, I proceed to install the package with:

;; packages.el

(package! org-inline-pdf :recipe (:host github :repo "shg/org-inline-pdf.el"))

Then close all instances of emacs, run doom sync, open my org file with a link to pdf [[myfile.pdf]] and try to load the mode M-x org-inline-pdf-mode.

I get the error byte-code: Invalid function: org-babel-temp-directory

Doom and Org Versions

GNU Emacs     v28.2
Doom core     v3.0.0-pre
Doom modules  v23.03.0-pre
Org mode version 9.7 (9.7-??-d6f3aed7b @ /home/username/.config/emacs/.local/straight/build-28.2/org/)
shg commented 1 year ago

Thank you for the report.

It seems like org-inline-pdf.el is byte-compiled before org is loaded. Could you try re-byte-compiling org-inline-pdf.el after M-: (require 'ob-core) RET? Or you may execute doom build (I don't use Doom Emacs and do not understand what it actually does though).

onlycparra commented 1 year ago

I run

doom build

and I get this in the output (among some previous and following similar lines):

  > Building which-key...
  > Building compat...
  > Building tldr...
  > Building org-inline-pdf...
  > Building org-inline-pdf > Building org...
  > Building org-inline-pdf...
  > Building vertico...
  > Building orderless...
  > Building consult...

Apparently It gets that it needs org before org-inline-pdf, so it builds org it first. Whet that is done, it goes back to org-inline-pdf

After building, I close all instances of emacs and run doom sync.

Finally, I open a .org file that links to a .pdf file. M-x org-inline-pdf-mode RET and I get the same error:

byte-code: Invalid function: org-babel-temp-directory
shg commented 1 year ago

Thank you testing. Could you try the following steps? Please translate appropriately for Doom Emacs if any.

  1. M-: (require 'ob-core) RET
  2. Open the directory in which org-inline-pdf.el is installed with dired
  3. Delete org-inline-pdf.elc
  4. Byte-compile org-inline-pdf.el manually by pressing b
  5. `M-x load-libary RET org-inline-pdf RET

And check if you get the same error here?

onlycparra commented 1 year ago

Alright. I followed your steps. Thanks for formatting them in "foolproof mode". I am new to doom emacs, actually :)

  1. I found the installed libraries with this in my shell:

    find ~ -name org-inline-pdf.elc 2>/dev/null
  2. The files ended up being in:

    /home/username/.config/emacs/.local/straight/build-28.2/org-inline-pdf/org-inline-pdf.elc
  3. In emacs: run M-: (require 'ob-core) RET

  4. Open the directory:

    C-x C-f /home/username/.config/emacs/.local/straight/build-28.2/org-inline-pdf/ RET
  5. Delete the elc file: M-x delete-file RET org-inline-pdf.elc RET

  6. Byte-compile el file: M-x byte-compile-file RET org-inline-pdf.el RET I obtained this warning:

    Compiling file /home/username/.config/emacs/.local/straight/build-28.2/org-inline-pdf/org-inline-pdf.el at Sun Aug  6 22:03:13 2023
    org-inline-pdf.el:122:5: Warning: Use keywords rather than deprecated positional arguments to `define-minor-mode'
  7. Load the library: M-x load-library RET org-inline-pdf RET

  8. Open a .org file and add a link [[file:image.pdf]] to it.

  9. Run M-x org-inline-pdf-mode

I obtain an inline preview of the .pdf file replacing the previously mentioned link. I close all instances of emacs, and reopen the .org file. The results are the same. I still can see the image.

If there is a doom versed person out there, please comment here to know how to make this work without manual intervention.

Finally, thanks, @shg for your help :grin:

shg commented 1 year ago

No problem. And thank you for testing. I will also test it on Doom Emacs when I have time.

uliw commented 1 year ago

After upgrading to 29, this problem happens with vanilla emacs as well

shg commented 1 year ago

@uliw Thank you for the report. I'm actually using 29 as well and I haven't confirmed the issue yet. However, I have thought of a possible cause and am testing it.

In the meantime, package-recompile-all may fix the issue if you haven't done it yet, it's a command available from 29.

uliw commented 1 year ago

As far as I can tell, the problem arises with native compilation on startup. But calling package-recompile-all seems to fix the issue

shg commented 1 year ago

I have also been using Emacs with native compilation on and am unsure if it is related, but thanks for the suggestion.

shg commented 1 year ago

@onlycparra @uliw Although I haven't successfully reproduced the issue in my environment, maybe the commit I just made solves the problem. I appreciate if you can test it when you have time. It's already on MELPA.

uliw commented 1 year ago

Upgrade from working installation went without a hitch. Deleting the eln file, and restarting also worked. So at least for my case, this seems fixed. thx!

onlycparra commented 1 year ago
$ doom sync -u
(...)
   ✓ (28/136) org-inline-pdf.el: cd61240 -> 4a4a299 [3 commit(s)]
        897ab7a Bump version to 0.4b
        97e021e Define org-inline-pdf-cache-directory variable for user customization
        504dab8 Define org-inline-pdf-cache-directory function
(...)
    > (Re)building packages...
(...)
      > Building org-inline-pdf...
(...)

The .elc file was re-created.

$ date --rfc-3339=seconds && stat -c%w /home/username/.config/emacs/.local/straight/build-28.2/org-inline-pdf/org-inline-pdf.elc
2023-08-09 12:53:31-04:00
2023-08-09 12:48:53.495500236 -0400

Then, after killing all instances of emacs, I open my .org file with the link. In emacs:

M-x org-inline-pdf-mode RET

And I get the same error.

org-inline-pdf-cache-directory: Invalid function: org-babel-temp-directory

Following https://github.com/shg/org-inline-pdf.el/issues/10#issuecomment-1667019552 again, fixes the issue.

shg commented 1 year ago

@uliw @onlycparra Thank you for taking your time for testing.

@onlycparra I made an additional fix and put it in a branch.

https://github.com/shg/org-inline-pdf.el/tree/cachedir

I appreciate if you can test this. To replicate the same situation in which you encountered the reported error, I think it should be installed using Doom Emacs's package installation mechanism, which I do not know. I think there should be a way to install a local package from file.

shg commented 1 year ago

@onlycparra The update is merged to main branch and will be available on MELPA soon.

onlycparra commented 11 months ago

Sorry for disappearing. I think it is working correctly now.