reddit / emacs

File mode specification error: Failed to define function org

One_Two8847 · 2022-02-26 15:20
This issue really has me scratching my head: I have swtiched to using straight.el because org-mode was complaining about switching repos and I really enjoy the flexibility if offers in selecting pacakages from sources such as Github. Recently, however, I have noticed that when I load any file .org file I get the following message: ``` File mode specification error: (error Autoloading file /home/thomas/.emacs.d/straight/build/org/org.elc failed to define function org) ``` This error occurs every time an org file is loaded. I have found I can suppress the error by simply commenting out the line ``(org-agenda-files `("~/Dropbox/gtd"))`` in my init.el file. This works well, however, my favorite feature of org-mode is the agenda and this essentially breaks that feature. I cannot for the life of me figure out why setting this variable raises this error. Below is the full configuration I use for org-mode with straight.el and use-package in my init.el file. I included the whole thing in case there is some conflict with how the variables are loaded. ``` (use-package org :straight (org :host github :repo "emacs-straight/org-mode" :branch "main") :mode ("\\.org\\'" . org-mode) :bind ("C-c c" . org-capture) ("C-c a" . org-agenda) ("C-c l" . org-store-link) :hook (org-mode . #'turn-on-flyspell) (org-mode . #'toggle-truncate-lines) :custom (org-directory "~/Dropbox/gtd") (org-agenda-start-on-weekday nil) (org-agenda-files `("~/Dropbox/gtd")) (org-default-notes-file (concat org-directory "/inbox.org")) (org-refile-targets '((org-agenda-files :maxlevel . 3))) (org-refile-use-outline-path 'file) (org-outline-path-complete-in-steps nil) (org-refile-allow-creating-parent-nodes (quote confirm)) (org-log-into-drawer t) (org-todo-keywords '((sequence "TODO(t)" "WAITING(w)" "|" "DONE(d)" "CANCELLED(c)"))) (org-tags-exclude-from-inheritance '("project")) (org-stuck-projects '("+project/-MAYBE-DONE" ("NEXT" "TODO") nil "\\<IGNORE\\>")) (org-latex-pdf-process '("pdflatex -interaction nonstopmode -output-directory %o %f" "biber %b" "pdflatex -interaction nonstopmode -output-directory %o %f" "pdflatex -interaction nonstopmode -output-directory %o %f")) (org-tags-column 0) (org-startup-indented t) (org-src-tab-acts-natively t) (org-todo-keyword-faces '(("TODO" . org-warning) ("WAITING" . "yellow") ("CANCELED" . (:foreground "blue" :weight bold)) ("DONE" . org-done))) (org-plantuml-jar-path (expand-file-name "~/.emacs.d/plantuml/plantuml.jar")) :config (add-to-list 'org-src-lang-modes '("plantuml" . plantuml)) (org-babel-do-load-languages 'org-babel-load-languages '((awk . t) (calc . t) (css . t) (emacs-lisp . t) (eshell . t) (gnuplot . t) (dot . t) (latex . t) (ledger . t) (octave . t) (plantuml . t) (R . t) (sed . t) (shell . t)))) ``` Another issue that I have noticed that my init.org no longer tangles to init.el on saving automatically.but only works when called directly with org-babel-tangle. A minor inconvenience. I thought that changing straight to use the built-in org-mode might fix this error but that had no effect either. Any ideas?
EcstaticBill2638 · 2022-02-26 15:35
Oh man, I had the same issue a while ago, I'm trying to remember what fixed it. Have you tried using the default straight recipe for org? That works well for me. If something's gone wrong with the build deleting the straight directory might fix it.
nv-elisp · 2022-02-26 16:06
Org requires :pre-build steps which are not present in your recipe. Straight provides recipes for Org and org-contrib which takes care of this. You also want to ensure that the call to `(straight-use-package 'org) ` (directly or via use-package expansion) happens prior to Org being loaded or any other package which requires Org being installed.
One_Two8847 · 2022-02-26 20:45
Interesting. I had tried intially using >(use-package org > :straight t > ...) before the custom recipe above, but that still gave the same error. Using your suggestion >(straight-use-package 'org) fixed the error. I was hoping to just recycle my old `use-package` declarations as I was hoping to defer loading of org until it was called upon. I even tried >(use-package org > :straight (org :type git > :repo "https://git.savannah.gnu.org/git/emacs/org-mode.git" > :local-repo "org" > :depth full :pre-build (straight-recipes-org-elpa--build) > :build (:not autoloads) > :files (:defaults "lisp/*.el" ("etc/styles/" "etc/styles/*"))) >... ) But that still didn't quite work. I might just let it be, however, because after the change, `emacs-init-time` is still just a little over 3 seconds. Thanks for the help!
One_Two8847 · 2022-02-26 22:30
Update: So it seemed that deferring loading of org-mode was the issue. After removing all the `:mode`, `:bind`, and, and `:hook` statements in `use-package` and rewriting them under `:config` it seems to work as expected without any error messages. Perhaps deferring the package loading is preventing `straight.el` from loading the `:pre-build` code?
nv-elisp · 2022-02-27 00:13
> Perhaps deferring the package loading is preventing straight.el from loading the :pre-build code? That shouldn't be the case. The way a use-package declaration expands with straight integration is essentially: (progn (straight-use-package 'package) ;; The rest of the use-package expansion) The call to `straight-use-package` happens first. It's hard to say exactly what could have caused your issue without seeing your init file.
yantar92 · 2022-02-27 05:09
What you see is a common issue. Such things often happen when you have some other package loading built-in version of Org partially then followed by trying to loaded a newer version. So, when your org statement is deferred, you are at the risk.