reddit / emacs

Emacs packages loading order

awannaphasch2016 · 2022-03-13 16:13
I have this scenario very often, but never bother to ask a question I have below code in my config. Simple org-roam-bibtex config. (use-package! org-roam-bibtex :after (org-roam) :hook (org-roam-mode . org-roam-bibtex-mode) :config (require 'org-ref) ;; (setq org-roam-bibtex-preformat-keywords ;; '("=key=" "title" "url" "file" "author-or-editor" "keywords")) ;; I can't find this variable in orb ;; (setq orb-preformat-keywords '("=key=" "title" "url" "file" "author-or-editor" "keywords")) (setq orb-templates '(("r" "ref" plain (function org-roam-capture--get-point) "" :file-name "${slug}" :head "#+TITLE: ${=key=}: ${title}\n#+ROAM_KEY: ${ref} - tags :: - keywords :: ${keywords} \n* ${title}\n :PROPERTIES:\n :Custom_ID: ${=key=}\n :URL: ${url}\n :AUTHOR: ${author-or-editor}\n :NOTER_DOCUMENT: %(orb-process-file-field \"${=key=}\")\n :NOTER_PAGE: \n :END:\n\n" :unnarrowed t)))) after I start emacs, orb-xxx variables are not found in describe-variables. and I need to '(require 'org-roam-bibtex)' to have orb-xxx variables loaded. What is going on here? Is there a reading material about this? I am truely exhausted.
wolfjb · 2022-03-13 16:45
Just a guess, but you haven't loaded org-roam yet. When Emacs starts, if org-roam isn't loaded then this configuration hasn't fired yet since you have this set as :after org-roam, so the variables you are looking for won't be present. Try reviewing an org-roam note and then look to see if the cats are loaded. Again, just a guess.
bram85 · 2022-03-13 19:18
The :hook defers package loading. Add :demand t to force loading it at startup.
mclearc · 2022-03-13 19:18
From [the docs](https://github.com/jwiegley/use-package#modes-and-interpreters): >If you aren't using :commands, :bind, :bind\*, :bind-keymap, :bind-keymap\*, :mode, :interpreter, or :hook (all of which imply :defer; see the docstring for use-package for a brief description of each), you can still defer loading with the :defer keyword: So with \`the ":hook" in there you don't need ":after". But in any case none of the package variables will be looked up by "describe-variable" until after the package is loaded, which as of your settings is after org-roam gets loaded. If you want it loaded sooner consider ":defer N" where N is some number of seconds instead of the hook.
awannaphasch2016 · 2022-03-13 20:04
excellent!
organic-bookworm · 2022-03-13 21:58
>`use-package!` I suppose you're using Doom, aren't ya? :) >What is going on here? The question's been answered and docs referred to, but here's a bit more practical approach, I think may be useful for better understanding. Doom's `use-package!` is a macro -- expand it, to see, what Emacs does. I'll simplify your declaration a bit (use-package! org-roam-bibtex :after (org-roam) :hook (org-roam-mode . org-roam-bibtex-mode) :config (require 'org-ref) (setq orb-templates nil)) With point at `use-package!` call the `macrostep-expand` command (`SPC m m` in Doom). What `macrostep-expand` does is, well, expanding nested macros level by level interactively. Repeat `macrostep-expand`. Here's what you get (again, a bit simplified) ;; :after (eval-after-load 'org-roam '(progn (unless (fboundp 'org-roam-bibtex-mode) ;; :hook (autoload #'org-roam-bibtex-mode "org-roam-bibtex" nil t)) (eval-after-load 'org-roam-bibtex '(progn ;; :config (require 'org-ref) (setq orb-templates nil) t)) ;; :hook (add-hook 'org-roam-mode-hook #'org-roam-bibtex-mode))) Essentially 1. Wait for `org-roam` feature to load, then 2. Make `org-roam-bibtex-mode` function `###autoload` `org-roam-bibtex` library before first call 3. Make `org-roam-mode-hook` call `org-roam-bibtex-mode` function 4. Wait for `org-roam-bibtex` feature to load, then 5. Run the `:config` section Now, there's a number of ways to cause a library to load, e.g. * Call any `###autoload` command * Call `load-library` command * `require` feature If you call e.g. `org-roam-buffer` command, which is `###autoload`, right after starting Emacs, it will make 1. Load `org-roam` library 2. Run `org-roam-mode-hook` calling `org-roam-bibtex-mode` `###autoload` function 3. Load `org-roam-bibtex` library 4. Run `:config` You *could* load `org-roam-bibtex` before `org-roam`, which *might* sidestep your `:config` section. But that's a fat chance and depends on implementation of `org-roam-bibtex` library. Note, that `eval-after-load` here waits for a **feature** `org-roam`. In Emacs lingo * [package](https://www.gnu.org/software/emacs/manual/html_node/elisp/Packaging.html) * one or more libraries formatted for distribution (think packages at ELPA, MELPA etc.) * [library](https://www.gnu.org/software/emacs/manual/html_node/elisp/Library-Search.html) * single Elisp file to load (try `find-library` command to list them) * [feature](https://www.gnu.org/software/emacs/manual/html_node/elisp/Named-Features.html) * one or more `provide` calls within a library, which, together with `require`, constitute a manual alternative to `autoload` (see `features` variable) The **package**, **library** and **feature** in general may be different, though *usually* a feature and a library file name are the same (e.g. the `org-roam` **feature** is `provide`ed by the "org-roam" library). Also, the library itself may be plain Elisp ".el" or byte-compiled Elisp ".elc" (see `load-suffixes`).
awannaphasch2016 · 2022-03-14 06:52
I figured i probly lazy load it.