0

I'm trying to use the use-package method of organizing my Preferences.el file in Aquamacs. When I try to use use-package display-time-mode, I get the following error message.

Debugger entered--Lisp error: (file-error "Cannot open load file" "No such file or directory" "display-time-mode")
  require(display-time-mode nil nil)
  eval-buffer(#<buffer  *load*> nil "/Users/hdeyoung/Library/Preferences/Aquamacs Emacs/Preferences.el" nil t)  ; Reading at buffer position 1110
  load-with-code-conversion("/Users/hdeyoung/Library/Preferences/Aquamacs Emacs/Preferences.el" "/Users/hdeyoung/Library/Preferences/Aquamacs Emacs/Preferences.el" t nil)
  load("~/Library/Preferences/Aquamacs Emacs/Preferences" t)
  (let ((user-init-file file)) (load user-init-file t))
  (lambda (file) (let ((user-init-file file)) (load user-init-file t)))("~/Library/Preferences/Aquamacs Emacs/Preferences")
  mapc((lambda (file) (let ((user-init-file file)) (load user-init-file t))) ("/Library/Preferences/Emacs/Preferences" "/Library/Preferences/Aquamacs Emacs/Preferences" "~/Library/Preferences/Emacs/Preferences" "~/Library/Preferences/Aquamacs Emacs/Preferences"))
  (if init-file-debug (mapc (function (lambda (file) (let ((user-init-file file)) (load user-init-file t)))) aquamacs-preference-files) (mapc (function (lambda (file) (let ((user-init-file file)) (condition-case error (load user-init-file t) (error (let ... ... ... ... ...)))))) aquamacs-preference-files))
  (if (equal init-file-user nil) nil (condition-case nil (load custom-file) (error (message "Loading `custom-file' failed."))) (if init-file-debug (mapc (function (lambda (file) (let ((user-init-file file)) (load user-init-file t)))) aquamacs-preference-files) (mapc (function (lambda (file) (let ((user-init-file file)) (condition-case error (load user-init-file t) (error ...))))) aquamacs-preference-files)) (aquamacs-activate-features-new-in-this-version))
  aquamacs-load-preferences()
  #[0 "\205\274 \305=\203\306\307Q\202? \310=\204\306\311Q\202?\312\306\313\314#\203*\315\202?\312\306\313\316#\203>\317\320\321!D\nB\322\202?\315\323\324\323\211#\210\325\326!\203P\326 \210\323=\203n\327\330\331\306\332Q!\"\324\323\211#\210\323=\203m\210\203\260\333!\334\232\203\260\335!\211\336P\337!\203\212\211\202\225\337!\203\224\202\225\313\262\203\256\340\"\203\254\341\342#\210\343\344!\210\266\f?\205\272\324\345\323\211#\262\207" [init-file-user system-type delayed-warnings-list user-init-file inhibit-default-init ms-dos "~" "/_emacs" windows-nt "/.emacs" directory-files nil "^\\.emacs\\(\\.elc?\\)?$" "~/.emacs" "^_emacs\\(\\.elc?\\)?$" initialization format-message "`_emacs' init file is deprecated, please use `.emacs'" "~/_emacs" t load fboundp aquamacs-load-preferences expand-file-name "init" file-name-as-directory "/.emacs.d" file-name-extension "elc" file-name-sans-extension ".el" file-exists-p file-newer-than-file-p message "Warning: %s is newer than %s" sit-for 1 "default"] 7]()
  command-line()
  normal-top-level()

What am I doing wrong? For reference, here is my Preferences.el file.

(require 'package)
(add-to-list 'package-archives '("gnu"   . "https://elpa.gnu.org/packages/"))
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))

(package-initialize)
(unless package-archive-contents
  (package-refresh-contents))

(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(eval-and-compile
  (setq use-package-always-ensure t
        use-package-expand-minimally t))

(setq-default indent-tabs-mode nil)

(use-package display-time-mode
  :ensure nil
  :custom
    (display-time-default-load-average nil))
1
  • What is the value of load-path (C-h v load-path and add it to the question)? Do M-x locate-library RET time - what does it say?
    – NickD
    Jul 31, 2023 at 21:26

1 Answer 1

2

The problem here is that display-time-mode is not a package; it's a minor mode defined in the built-in package time (time.el). The first argument to use-package must be a package. [More accurately this argument must be a feature; see below for a more detailed explanation.]

The following code loads the time package, enables display-time-mode, and sets display-time-default-load-average to nil:

(use-package time
  :ensure nil
  :config
  (display-time-mode 1)
  :custom
  (display-time-default-load-average nil))

Information about features:

As pointed out by @shynur, use-package - like require - actually takes a feature as its first argument. A feature is a symbol that Emacs uses to represent "a collection of functions, variables, etc". Packages define a feature name using provide. By convention, the feature name is the same name as the name of the file (minus the file extension).

When use-package (or require) is called on a symbol that does not appear in the feature namespace, Emacs will look through the load-path to try to find a .el or .elc file that matches the provided symbol. If it does, it will load that package (which will then call the provide function to add the feature into the feature-namespace).

The benefit of using features is that it allows a package to only be loaded once even if it is required many times. Once a feature has been provided, if the corresponding package is loaded again by require or use-package then its source code will not run again. Whereas every time the function load is used the code will run. An example of where this is helpful is if many packages all use the same library. If they all use require, then the package will only need to be loaded once.

2
  • 1
    The first argument to use-package must be a _package_.” — minor mistake. It is a feature symbol.
    – shynur
    Jul 31, 2023 at 21:44
  • @shynur Thank you for that correction. I added some text below my original answer to provide information about how features are used by require and use-package.
    – D. Gillis
    Jul 31, 2023 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.