{"id":411,"date":"2022-08-30T15:00:54","date_gmt":"2022-08-30T15:00:54","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/in-emacs-how-can-i-add-a-function-to-hook-when-the-function-hasnt-yet-been-defined-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:00:54","modified_gmt":"2022-08-30T15:00:54","slug":"in-emacs-how-can-i-add-a-function-to-hook-when-the-function-hasnt-yet-been-defined-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/in-emacs-how-can-i-add-a-function-to-hook-when-the-function-hasnt-yet-been-defined-collection-of-common-programming-errors\/","title":{"rendered":"In emacs, how can I add a function to hook when the function hasn&#39;t yet been defined?-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;ve installed some things from ELPA, namely evil and rainbow-delimiters.<\/p>\n<p>In order to have them run whenever emacs loads, I would put something like:<\/p>\n<pre><code>(evil-mode)\n(global-rainbow-delimiters-mode)\n<\/code><\/pre>\n<p>In my init.el file.<\/p>\n<p>However, because I installed them from ELPA, they&#8217;re not loaded until after my init.el has been loaded, and so both symbols are undefined.<\/p>\n<p>As far as I understand, this also prevents me from doing something like<\/p>\n<pre><code>(add-hook 'after-init-hook 'global-rainbow-delimiters-mode)\n<\/code><\/pre>\n<p>How can I work around this?<\/p>\n<ol>\n<li>\n<p>Your <code>add-hook<\/code> solution will work.<\/p>\n<p>There, <code>'global-rainbow-delimiters-mode<\/code> is just a name, it will be resolved to the function later, when <code>add-hook<\/code> is called, and the function will exist by that time.<\/p>\n<p>The ELPA documentation does mention this method, although it seems to consider it as a last resort.<\/p>\n<\/li>\n<li>\n<p>AFAIU compiling the init file is not a good idea &#8211; but not related so far.<\/p>\n<p>Your hook fails, as it runs after reading the init, but before stuff gets loaded. You need a function to run after load from ELPA.<\/p>\n<p>Try eval-after-load<\/p>\n<\/li>\n<li>\n<p>You can also initialize your packages early with <code>(package-initialize)<\/code>. This will allow you to not put all that code in one hook.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 19:07:07. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve installed some things from ELPA, namely evil and rainbow-delimiters. In order to have them run whenever emacs loads, I would put something like: (evil-mode) (global-rainbow-delimiters-mode) In my init.el file. However, because I installed them from ELPA, they&#8217;re not loaded until after my init.el has been loaded, and so both symbols are undefined. As far [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-411","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/411","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=411"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/411\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}