autoload is not a substitute for require. Typically require is used to make sure that a certain file is loaded. autoload on the other hand gives Emacs a hint in which file to find a given function without loading the file right away. Only when the autoloaded function is called is the corresponding file loaded.
Basically with autoload you can delay the ...
If you load a library repeatedly, that file will be read and its code evaluated repeatedly (each and every time you load it).
If you require a library repeatedly, it will load the library once (at most -- and not at all if the library had already been loaded).
require provides this efficiency even if require wasn't used to load the library initially, ...
You just test with featurep:
(require 'projectile nil t)
(when (featurep 'projectile)
or you use that the require returns nil if it is not possible to load:
(when (require 'projectile nil t)
(require <foo>) is treated specially when it's at top-level (it causes the compiler to require the file also, rather than only do the require at run-time).
If the require is not performed at compilation time, then your code can't be compiled properly since the define-clojure-indent macro won't be known during compilation, leading to mis-compilation, ...
I don't know of any standard way of doing this. However, you can fairly simply advice require so that it keeps trace of who calls it.
(defvar my/require-tree nil)
(defun require--advice (orig-fun feature &rest args)
(list (let ((my/require-tree (list feature)))
(apply orig-fun ...
In terms of Emacs initialization, don't make either choice. GitHub user jwiegley has the excellent use-package declaration macro, that will require or autoload a package as determined by need. Best used to defer the loading of packages that can be loaded on-demand.
What you are looking for is
(add-to-list 'load-path "~/Projects/modules-test")
The best thing you can do is C-h v load-path RET and follow links in the *Help* buffer.
@Stefan explained why you see what you see: Your require statement is not at top level of the file.
A solution to the byte-compiler not evaluating your (non top-level) require statement is to force its evaluation, using (eval-and-compile (require 'clojure-mode)).
The fact that require is evaluated by the byte-compiler when it is at top level is pointed out ...
IMHO, the right way is to ignore it. ;-)
But the standard Emacs answer is to use declare-function - see (elisp) Declaring Functions.
All you need to do is add a declare-function statement before the
first use of the function in question:
(declare-function gud-find-c-expr "gud.el" nil)
This says that gud-find-c-expr is defined in gud.el (the .el
You should be able to use require, yes, but only after running package-initialize (in Emacs≥27, this is done for you before the beginning of the .emacs file).
Note that for 99% of the packages require should not be needed (the autoloads should cause the package to be loaded as soon as you try to make use of it). E.g. if you have use-package installed as an ...
You discovered most of the answer yourself. When you install clojure-mode, you also get a file clojure-mode-autoloads.el. That file besides adding the entries you mentioned to auto-mode-alist, also defines autoloads for the functions clojure-mode, clojurec-mode, etc.
Once the autoload file has been loaded (which normally package-initialize does on start up),...
If you want a certain feature to be loaded and available directly when your Emacs has started, use require, otherwise use autoload. I personally value startup time much (I actually restart Emacs a couple of times per week, sometimes several times per day), so I accept that it will take a little bit of time when Emacs autoloads a certain function when I need ...
Emacs initializes the package system after loading .emacs, not before. (See Startup Summary and Packaging Basisc.) I think the reason is to allow you to configure (or even disable) the package loading process from .emacs.
You can add flx-ido-mode to after-init-hook. Or you can follow the officious advice which is to call package-initialize from your init ...
If the package has its dependencies properly declared,cask install should do all the setup that is necessary. Cask then builds the load-path automatically for you so that (require ...) statements resolve when you invoke cask exec.
Interactively evaluation / development of a package with cask-installed dependencies seems to be a shortcoming of Cask. Four ...
Noe that the warnings you see are real: your code happens to work because you're lucky enough that it doesn't get byte-compiled, but if for some reason it gets byte-compiled then it won't work any more (unless flycheck was loaded already when the code got byte-compiled).
So to fix your code "right", you have two options:
add a (eval-when-compile (require '...
In general it's fine to require things inside functions, assuming the function in question is not necessarily going to be used, and the rest of your library doesn't need that dependency.
Your example wouldn't necessitate that, though. Based on the autoload cookie, you're intending that your library doesn't get loaded at all until my-mode is invoked, at ...
Command dirtree is not marked for autoloading so you need do (require 'dirtree) first.
Or follow instructions provided in dirtree commentary section:
Put the following into your ~/.emacs:
(autoload 'dirtree "dirtree" "Add directory to tree view" t)
(provide 'wordpress-mode) provides a feature named wordpress-mode and your use-package config clearly wants to (require 'wordpress) and is, naturally, failing to do so.
Check the use-package documentation -- I'm sure there's a simple way to specify that the feature symbol name and the library name are not the same. Without use-package, this would be: (...
The point of require is not lazy-loading (that would be autoload instead). Instead, the purpose is to avoid loading the same package multiple times.
In the case of config files, which of load or require is preferable is unclear and will depend on your particular use case (but I think in most cases the difference will be negligible).
I have one answer with Nix, but I am curious as to how it is possible to do so without Nix
#! /usr/bin/env nix-shell
#! nix-shell -i "emacs --script" -p "pkgs.emacsWithPackages(epkgs: (with epkgs.melpaPackages; [ dash ]))"
#! nix-shell -I nixpkgs=channel:nixos-18.03
"function definition is void" most probably means the file where the function is defined has not be loaded yet. In this case you need to first
Now, how can you find this is calc-ext? Just use calc, this triggers loading of necessary files, then ask for the docstring of calc-precision:
C-h f calc-precision
calc-precision is an ...
require takes following arguments:
(require FEATURE &optional FILENAME NOERROR)
The NOERROR argument causes the function to return nil when file with the feature isn't found. Without that argument set to t, you'd get an error.
As ocoh2 points out, cl-lib is not autoloaded, the only way to get it is to require it or have it indirectly autoloaded (some autoloaded package requires it).
It must be the Debugger that loads cl-lib. With emacs -Q --eval '(cl-evenp 2)', there is an error but no debugger and cl-lib is not loaded. cl-lib only gets loaded after the Debugger pops up once ...