From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Hongyi Zhao Newsgroups: gmane.emacs.help Subject: Install packages picked up from a list automatically. Date: Thu, 24 Dec 2020 21:37:20 +0800 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17453"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 24 14:38:30 2020 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ksQp3-0004QF-LP for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 24 Dec 2020 14:38:29 +0100 Original-Received: from localhost ([::1]:34788 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ksQp2-0001tz-O0 for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 24 Dec 2020 08:38:28 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ksQoI-0001tq-FP for help-gnu-emacs@gnu.org; Thu, 24 Dec 2020 08:37:43 -0500 Original-Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]:36795) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ksQoD-0003bP-Ou for help-gnu-emacs@gnu.org; Thu, 24 Dec 2020 08:37:41 -0500 Original-Received: by mail-lf1-x133.google.com with SMTP id o13so4836282lfr.3 for ; Thu, 24 Dec 2020 05:37:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=03vEksurYpZrVdWkqifum8kxQexNeqnX+t9Zlbn7rIg=; b=UKYGpe/QDyz4CFBOGfE+73mYXvFg90dbgETS2aJjIkIxg8Q4BYJgfDNheye7zbxRGM a0dAqtHgJCgf9//8df6AGFtlGTh1T40xP/GSHbDI6TmgDUdaGd7zKtllPw1kOGIWtgDV c6SOHqGeTMq+fa/EC9MIsu69lp7TowX2edggzQLSO1RVTMssVJF883iW5dx6e/6+1kvq X8ZMORL26t/BmToJ04shZUEH74Hh1VXtlnO4eaxjnzY6fkETAmQWQa7Kuz16XJdXswa8 09d22hehKlEANWYV2mkzm17seFqjYGJQZ9cx1oc3JTqtOWFhQxrgnY/N/da8YgPHlTfH FvIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=03vEksurYpZrVdWkqifum8kxQexNeqnX+t9Zlbn7rIg=; b=R8R9vf0cVISF/MvjeHiUwuslj9nKfhDPA7b3uoLRvgBX3brh/avS6zPpqACKzbJTiG 2Eu6G/RO7l5lOsYf4wKIh/HsMGHGPOKE+ipO4zAb6tjYJzER1sEwP2Wa8Uj7RaxP1BHw t1aI1udYHXKdAdY01OChtdBZo/Eztw8SENglzWQQzKNVSyowy9m4yGdi4k2s0y7lTW+X Vz7TlhwtofRLwbu73pjuABElfqUOCAWR5zYVsYPFq/TicZ5s3UFkgs7xXOtFInojCLYS botHZZ8376UtiQGOoKBKRKyNNzFWRe+hkE0oBO8eOnEOEcEpnpMPZh3H8pD6AmIwAhAx D6Xg== X-Gm-Message-State: AOAM5312wKBJdiW/prTql8PWbDDiEe+NvDD9lfli/4GRMdrdPLaZNQRh X33c9DM+y593n3jqJPZt3Ht8q9WcRU/ihD4ljfTy1+Pj/ahsWBJ9 X-Google-Smtp-Source: ABdhPJzM6YOlSbsd70mNE105muSmwyD72eZSCMsX/e6vqmI9HSt47+8dwU+O+lPY69FCifv/aewp1PyyhL6oLaBEjps= X-Received: by 2002:a2e:5756:: with SMTP id r22mr15447766ljd.481.1608817052231; Thu, 24 Dec 2020 05:37:32 -0800 (PST) Received-SPF: pass client-ip=2a00:1450:4864:20::133; envelope-from=hongyi.zhao@gmail.com; helo=mail-lf1-x133.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:126744 Archived-At: I want to let emacs install needed packages stored in a list automatically. For this purpose, I find the following methods which can be used in ~/.emacs.d/init.el: 1. The method represented at : ;; If there are no archived package contents, refresh them (when (not package-archive-contents) (package-refresh-contents)) ;; Installs packages ;; ;; myPackages contains a list of package names (defvar myPackages '(better-defaults ;; Set up some better Emacs defaults material-theme ;; Theme ) ) ;; Scans the list in myPackages ;; If the package listed is not already installed, install it (mapc #'(lambda (package) (unless (package-installed-p package) (package-install package))) myPackages) 2. The method given by Bozhidar Batsov in his prelude project, see for more information. (defvar prelude-packages ;; https://github.com/magnars/s.el#installation '(s flycheck) "A list of packages to ensure are installed at launch.") (defun prelude-packages-installed-p () "Check if all packages in `prelude-packages' are installed." (cl-every #'package-installed-p prelude-packages)) (defun prelude-require-package (package) "Install PACKAGE unless already installed." (unless (memq package prelude-packages) (add-to-list 'prelude-packages package)) (unless (package-installed-p package) (package-install package))) (defun prelude-require-packages (packages) "Ensure PACKAGES are installed. Missing packages are installed automatically." (mapc #'prelude-require-package packages)) (defun prelude-install-packages () "Install all packages listed in `prelude-packages'." (unless (prelude-packages-installed-p) ;; check for new packages (package versions) (message "%s" "Emacs Prelude is now refreshing its package database...") (package-refresh-contents) (message "%s" " done.") ;; install the missing packages (prelude-require-packages prelude-packages))) ;; run package installation (prelude-install-packages) I'm a thorough beginner as for emacs lisp. Could you please give me some hints/notes/comments on the pros can cons of the above two mentioned methods? Thanks in advance. Regards, HY -- Assoc. Prof. Hongyi Zhao Theory and Simulation of Materials Hebei Polytechnic University of Science and Technology engineering NO. 552 North Gangtie Road, Xingtai, China