0

Could you help me with smarter way of handling package-archives? At the moment I have the following in my init.el

;; This is dumb but...
(if (eq system-type 'windows-nt)
    (setq package-archives '(("elpa" .  "http://elpa.gnu.org/packages/")
                             ("melpa" . "http://melpa.org/packages/")))
  (setq package-archives '(("elpa" .  "https://elpa.gnu.org/packages/")
                           ("melpa" . "https://melpa.org/packages/"))))

Can I make it more DRY? Like this one (doesn't work):

(defvar package-protocol "https://")
(if (eq system-type 'windows-nt) (setq package-protocol "http://"))
(setq package-archives '(("elpa" .  (concat package-protocol "elpa.gnu.org/packages/"))
                         ("melpa" . (concat package-protocol "melpa.org/packages/")))))

thx, combined from the answers, using local variable:

;; Set up packaging system
(let ((package-protocol (if (eq system-type 'windows-nt) "http://" "https://")))
  (setq package-archives `(("elpa" .  ,(concat package-protocol "elpa.gnu.org/packages/"))
                           ("melpa" . ,(concat package-protocol "melpa.org/packages/")))))
1

Easy:

(setq package-archives 
      (list (cons "elpa" (concat package-protocol "elpa.gnu.org/packages/"))
            (cons "melpa" (concat package-protocol "melpa.org/packages/")))))

or use backquote:

(setq package-archives 
      `(("elpa" .  ,(concat package-protocol "elpa.gnu.org/packages/"))
        ("melpa" . ,(concat package-protocol "melpa.org/packages/")))))
1

This might help you get set up, you can change it afterwards

(let ((package-protocol (if (eq system-type 'windows-nt) "http://" "https://"))
      (package-suffix ".org/packages/")
      (archives-to-use '("elpa.gnu" "melpa")))
  (setq package-archives
    (cl-loop for cur-archive in archives-to-use
    collect (cons (first (split-string cur-archive "\\.")) 
                  (concat package-protocol cur-archive package-suffix)))))

It lets the package protocol, and then the suffix. It then loops through our list of archives and appends the suffix and prefix to each element. It sets that collected list to package-archives

Your Answer

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

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