this post was submitted on 17 Nov 2023
1 points (100.0% liked)

Emacs

313 readers
2 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS
 

emacs noob here.

I'm rewriting my init.el file from scratch using use-package macro. In my existing init file I use require to configure MELPA package archive.

(require 'package)

(add-to-list 'package-archives '("MELPA" . "http://melpa.org/packages/"))

(package-initialize)

Can I rewrite this using use-package macro?

top 2 comments
sorted by: hot top controversial new old
[–] mekeor@alien.top 1 points 1 year ago

I don't use use-package myself, but maybe you could write:

(use-package package
  :init
  (add-to-list 'package-archives '("MELPA" . "http://melpa.org/packages/")))

I'd expect it to understand that you are referring to package.el, where package-archives variable is defined.

[–] thetemp_@alien.top 1 points 1 year ago

You can use the `setopt' macro, which is also new in Emacs 29.1.

(setopt package-archives
        '(("gnu" . "https://elpa.gnu.org/packages/")
          ("nongnu" . "https://elpa.nongnu.org/nongnu/")
          ("melpa" . "https://melpa.org/packages/")))