How to automatically install Emacs packages by specifying a list of package names?

后端 未结 11 2607
隐瞒了意图╮
隐瞒了意图╮ 2020-12-22 15:22

I am using package to manage my Emacs extensions. In order to synchronize my Emacs settings on different computers, I\'d like a way to specify a list of package

11条回答
  •  离开以前
    2020-12-22 15:40

    Based on comments by Profpatsch and answers below:

    (defun ensure-package-installed (&rest packages)
      "Assure every package is installed, ask for installation if it’s not.
    
    Return a list of installed packages or nil for every skipped package."
      (mapcar
       (lambda (package)
         ;; (package-installed-p 'evil)
         (if (package-installed-p package)
             nil
           (if (y-or-n-p (format "Package %s is missing. Install it? " package))
               (package-install package)
             package)))
       packages))
    
    ;; make sure to have downloaded archive description.
    ;; Or use package-archive-contents as suggested by Nicolas Dudebout
    (or (file-exists-p package-user-dir)
        (package-refresh-contents))
    
    (ensure-package-installed 'iedit 'magit) ;  --> (nil nil) if iedit and magit are already installed
    
    ;; activate installed packages
    (package-initialize)
    

提交回复
热议问题