Skip to main content
29 votes
Accepted

What does (require 'package) mean for emacs and how does it differ from load-file?

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 ...
phils's user avatar
  • 51.9k
11 votes
Accepted

Require a file in the current directory without setting load-path

Like John Kitchin pointed out, load-file does what you want. For example: (setq my-utils-file "utils.el") (load-file (expand-file-name my-utils-file (file-name-directory (...
Heikki's user avatar
  • 3,076
8 votes
Accepted

Soft-require a feature, then conditionally run more commands

You just test with featurep: (require 'projectile nil t) (when (featurep 'projectile) (do-some-stuff-that-needs-projectile)) or you use that the require returns nil if it is not possible to load: (...
Andrew Swann's user avatar
  • 3,576
7 votes

Deep eager macroexpansion

(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 ...
Stefan's user avatar
  • 26.5k
5 votes
Accepted

require vs. package-initialize?

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 ...
Stefan's user avatar
  • 26.5k
5 votes
Accepted

Prevent byte-compiler warnings after requiring features

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 ...
Drew's user avatar
  • 78.1k
5 votes
Accepted

How to require/provide a package name with the value of `user-login-name`, without hard coding it?

(require (intern user-login-name)) require needs a symbol as its argument, the value of user-log-name is a string, intern takes a string and returns a symbol.
xuchunyang's user avatar
  • 14.6k
4 votes
Accepted

How to load libraries (Lisp files), wherever they are located

What you are looking for is (add-to-list 'load-path "~/Projects/modules-test") See docs: Lisp Libraries Library Search The best thing you can do is C-h v load-path RET and follow links in the *...
sds's user avatar
  • 6,134
4 votes
Accepted

Deep eager macroexpansion

@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 ...
Drew's user avatar
  • 78.1k
4 votes
Accepted

How to autoload a package without requiring in the init file?

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 ...
Omar's user avatar
  • 4,842
3 votes
Accepted

Should I use "require" or "load" when writing my own configuration?

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 ...
Stefan's user avatar
  • 26.5k
3 votes

Prevent byte-compiler warnings after requiring features

Here's how I'd do it: (require 'markdown-mode nil 'noerror) ... ... ... (if (fboundp 'markdown-mode) ..use markdown-mode..)
Stefan's user avatar
  • 26.5k
3 votes

cl-lib isn't loaded the first time an autoloaded function is used from it

It's an internal autoload of the cl-lib package, not a global autoload. cl- has no global autoloads. To use cl- functions, require cl-lib. To use cl- macros, eval-when-compile require cl-lib.
ocoh2's user avatar
  • 31
3 votes
Accepted

What is the difference/purpose between "require" and "package-install"?

Think of a package as a bunch of e-lisp and maybe other files. Many of these (such as the package package itself) come as part of your emacs (these are said to be built-in) and so need no further ...
Fran Burstall's user avatar
3 votes
Accepted

require can't find file that do exist

The error is: (file-missing "Cannot open load file" "No such file or directory" "f") For the backtrace: require(f) eval-buffer(#<buffer *load*-752679> nil &...
phils's user avatar
  • 51.9k
2 votes
Accepted

(require 'flx-ido) fails, but "M-x flx-ido-mode" succeeds

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 ...
Gilles 'SO- stop being evil''s user avatar
2 votes
Accepted

How do I require a package installed via .cask in a project

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 ...
ebpa's user avatar
  • 7,529
2 votes
Accepted

How do you remove compiler warnings for macro usage when running macro with 'with-eval-after-load'?

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 ...
Stefan's user avatar
  • 26.5k
2 votes
Accepted

Installing Emacs from source: the command `C-h v` for accessing variables doesn't work

make is a program often used to automate life-cycle of another program. Compiling, testing, packaging and installing would be examples of events in a program's life-cycle managed by make. Usually, it ...
wvxvw's user avatar
  • 11.4k
2 votes
Accepted

How do I use a function from subr.el?

subr.el is one of the numerous libraries which is pre-loaded. You do not need to load it; you can simply go ahead and use the functions. Note that there is no version>= -- the function you have ...
phils's user avatar
  • 51.9k
2 votes

For convenience, how should I load a package whenever a specific other package loads?

Use autoload for specific commands etc. Use require if your library depends on another. That's the main question to ask yourself: does your library need the other library? If so, require it. You can ...
Drew's user avatar
  • 78.1k
2 votes

Undefined-function error about function called by my function

Put (require 'THE-LIBRARY) inside your definition of safe-mail-send-and-exit, at the beginning (just after (interactive), where THE-LIBRARY is the library that defines function mail-send-and-exit. (...
Drew's user avatar
  • 78.1k
2 votes

How do you install DoReMi?

You install it the same way you install any code from any random .el file: copy it into your load-path, and then call require. require takes one argument, which is the name of the feature to load. Add ...
db48x's user avatar
  • 18.5k
2 votes
Accepted

Function load raises error on loading an existing file

OK. If anyone has a similar problem, I figured it out. The problem was not a failure to find the file that was the argument to the (load) function, the problem was that /that/ file was doing a (...
Daniel Doherty's user avatar
1 vote

Why isnt `(require 'use-package)` triggered when I open Emacs?

Like mentioned above your init.el file is probably not loaded properly. Please keep in mind that emacs has an particular order in which it searches for the initial init files. https://www.gnu.org/...
Tietan's user avatar
  • 140
1 vote
Accepted

Symbol's function definition is void: rx-let

Solution for me: M-x package-delete then python-0.27.1. Ubuntu 20.10, emacs 26.3 (from distro). I had installed python-0.27.1 (via Options > Manage Emacs Packages) after naively assuming that ...
Reece's user avatar
  • 126
1 vote
Accepted

Delaying (require ...) for packages that define minor modes

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 ...
phils's user avatar
  • 51.9k
1 vote

use-package: autoload function outside the main package file

You cannot easily run simplenote2-setup when lazy loading the package. However, there are several options, to make lazy loading happening: 1. use of :after and defining a use-package declaration ...
jue's user avatar
  • 4,636
1 vote

The dirtree mode not present installed using melpa

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 '...
muffinmad's user avatar
  • 2,330
1 vote
Accepted

Error on loading my custom minor mode

(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 ...
phils's user avatar
  • 51.9k

Only top scored, non community-wiki answers of a minimum length are eligible