0

This post is asking this question more clearly and concisely.

My code contains the following function to install dependencies:

(defun literef-install-packages()
  "Install any missing packages. The code is taken from
`https://stackoverflow.com/a/10093312/2725810'."

  (setq package-list '(org org-ref pdf-tools smooth-scrolling company))

                    ; list the repositories containing them
  (setq package-archives '(("elpa" . "http://tromey.com/elpa/")
               ("gnu" . "http://elpa.gnu.org/packages/")
               ("marmalade" . "http://marmalade-repo.org/packages/")
               ("melpa" . "http://melpa.milkbox.net/packages/")))
  (package-initialize)
  (unless package-archive-contents
    (package-refresh-contents))

  (dolist (package package-list)
    (unless (eq (package-installed-p package) t)
      (when 
      (yes-or-no-p (concat
            "The package " (symbol-name package)
            " is not installed. Install it? "))
    (package-install package)
    (when (eq package 'pdf-tools) (pdf-tools-install))))))

This code installs all the required packages besides org, whose earlier (compared to the version in MELPA) version is built-in. In particular, when I try to evaluate (package-install 'org), I get the message saying that the package is already installed. How do I get around this problem?

2
  • If this question is just asking another question more clearly, why not edit the other question to just make it clearer? Why duplicate the question with a more clear version?
    – Drew
    Nov 12 '18 at 16:24
  • @Drew This is what was suggested to me there. See the comments. Nov 12 '18 at 20:11
0

The trick is to get the structure describing the version available for installation. The following function does just that:

(defun literef-package-desc(pkg)
  (car (cdr (assq pkg package-archive-contents))))

We can now install org:

(package-install (literef-package-desc 'org) 'dont-select)
3
  • 1
    Can you add an description of how your code is supposed to be used, or anything else that adds to it?
    – user12563
    Nov 12 '18 at 16:06
  • @DoMiNeLa10 Done. Nov 12 '18 at 20:15
  • This will always install the first version returned. If you have multiple archives loaded with the same package (for example "gnu" and "org") this may not be what you want. Jun 8 '20 at 18:01

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