0

When I start Emacs I get the error message

Error (use-package): Cannot load counsel

But when I open init.el in a buffer and run eval-buffer everything works fine. What I'm doing wrong?

My Emacs config: https://git.sr.ht/~inquisitive/emacs-adjustments/tree/package/ivy/.emacs.d/init.el

;; Bootstrap straight.el
(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

(straight-use-package 'use-package)

(use-package magit
  :bind ("C-x g" . magit-status))

(use-package counsel
  :config
  (counsel-mode 1))

;; Display line numbers in programming major modes
(add-hook 'prog-mode-hook 'display-line-numbers-mode)

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(inhibit-startup-screen t)
 '(menu-bar-mode nil)
 '(scroll-bar-mode nil)
 '(straight-use-package-by-default t)
 '(tool-bar-mode nil))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(default ((t (:inherit nil :stipple nil :background "#fcfcfc" :foreground "#232627" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 143 :width normal :foundry "FSD " :family "PragmataPro Mono Liga")))))
2
  • perhaps counsel isn't installed? try M-x package-install <ret> counsel <ret> Sep 8 '19 at 11:28
  • @manandearth: If the package isn't already installed it should be automatically installed with straight.el.
    – user24376
    Sep 8 '19 at 11:35
0

You need to add the straight keyword in the use-package macro call e.g. add :straight t

From straight.el documentation https://github.com/raxod502/straight.el#integration-with-use-package

To use use-package, first install it with straight.el:

(straight-use-package 'use-package)

Now use-package will use straight.el to automatically install missing packages if you provide :straight t:

(use-package el-patch
    :straight t)
0

It seems that the bug occurs because I set straight-use-package-by-default using the customize-interface. When I set the variable outside of custom-set-variables everything works fine.

-1

In general you need to initialize the package system if you're going to use packages at init time.

i.e. Do this first:

(setq package-enable-at-startup nil)
(package-initialize)

(That said, I'd be slightly surprised if use-package didn't do that itself, so maybe this isn't the issue; but it's certainly worth testing it.)

4
  • OP is using straight.el and does not use package use-package can use both
    – mmmmmm
    Sep 8 '19 at 13:49
  • Does straight have an equivalent to package-initialize then?
    – phils
    Sep 8 '19 at 13:57
  • Yes it ius somethink like the bootstrap code in the question - however I don't use it and don't know what the OP has miscopied or misunderstood
    – mmmmmm
    Sep 8 '19 at 14:00
  • 1
    Ok, thanks. I'll leave this answer here as extra information for others.
    – phils
    Sep 8 '19 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy