如何通过指定包名称列表来自动安装emacs包? [英] how to automatically install emacs packages by specifying a list of package names?

查看:137
本文介绍了如何通过指定包名称列表来自动安装emacs包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用来管理我的emacs扩展。为了在不同的计算机上同步我的emacs设置,我想要一种方法来指定 .emacs 文件中的包名称列表,然后指定可以自动搜索和安装软件包,因此我不需要通过调用 Mx package-list-packages 手动安装它们。如何做?

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 names in .emacs file and then package could automatically search and install the packages, so that I don't need to install them manually by calling M-x package-list-packages. How to do that?

推荐答案

根据Profpatsch的评论和以下答案:

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)

这篇关于如何通过指定包名称列表来自动安装emacs包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆