패키지 이름 목록을 지정하여 Emacs 패키지를 자동으로 설치하는 방법은 무엇입니까?
package
Emacs 확장 프로그램을 관리하는 데 사용 하고 있습니다. 다른 컴퓨터에서 내 Emacs 설정을 동기화하기 위해 .emacs
파일 에 패키지 이름 목록을 지정한 다음 package
패키지를 자동으로 검색하여 설치할 수 있으므로을 호출하여 수동으로 설치할 필요가 없습니다 M-x package-list-packages
. 그렇게하는 방법?
; list the packages you want
(setq package-list '(package1 package2))
; 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/")))
; activate all the packages (in particular autoloads)
(package-initialize)
; fetch the list of packages available
(unless package-archive-contents
(package-refresh-contents))
; install the missing packages
(dolist (package package-list)
(unless (package-installed-p package)
(package-install package)))
Profpatsch의 의견과 아래 답변을 기반으로합니다.
(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 25.1+는 사용자 정의 package-selected-packages
변수 에서 사용자 설치 패키지를 자동으로 추적 합니다. package-install
사용자 정의 변수를 업데이트하고 선택한 모든 패키지를 package-install-selected-packages
기능 과 함께 설치할 수 있습니다 .
이 방법의 또 다른 편리한 장점은 package-autoremove
포함되지 않은 패키지를 자동으로 제거 하는 데 사용할 수 있다는 것 입니다 package-selected-packages
(종속성은 유지되지만).
(package-initialize)
(unless package-archive-contents
(package-refresh-contents))
(package-install-selected-packages)
출처 : http://endlessparentheses.com/new-in-package-el-in-emacs-25-1-user-selected-packages.html
Emacs Prelude에 사용하는 코드는 다음과 같습니다 .
(require 'package)
(require 'melpa)
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-initialize)
(setq url-http-attempt-keepalives nil)
(defvar prelude-packages
'(ack-and-a-half auctex clojure-mode coffee-mode deft expand-region
gist haml-mode haskell-mode helm helm-projectile inf-ruby
magit magithub markdown-mode paredit projectile
python sass-mode rainbow-mode scss-mode solarized-theme
volatile-highlights yaml-mode yari yasnippet zenburn-theme)
"A list of packages to ensure are installed at launch.")
(defun prelude-packages-installed-p ()
(loop for p in prelude-packages
when (not (package-installed-p p)) do (return nil)
finally (return t)))
(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
(dolist (p prelude-packages)
(when (not (package-installed-p p))
(package-install p))))
(provide 'prelude-packages)
당신이 MELPA을 사용하지 않는 경우 당신이 그것을 필요로 할 필요가 없습니다 (그리고 당신이 경우에 melpa.el
가지고에있을 당신 load-path
(또는) MELPA를 통해 설치되어 있어야합니다.이 크게 시작 속도를 느리게하는 것처럼 패키지 데시벨은 (마다 새로 고쳐지지 않습니다 )-제거 된 패키지가있는 경우에만 해당합니다.
아직 Cask에 대해 언급 한 사람은 없지만이 작업에 적합합니다.
Basically you create ~/.emacs.d/Cask
listing the packages you want to install. For example:
(source melpa)
(depends-on "expand-region")
(depends-on "goto-last-change")
; ... etc
Running cask
from the command line will install these packages for you, and any dependencies they need.
Also, you can automatically update installed packages using cask update
.
Call package-install
with the package name as a symbol. You can find the package names for your packages by calling package-install
interactively and completing on the name. The function package-installed-p
will let you know if it's already been installed.
For example:
(mapc
(lambda (package)
(or (package-installed-p package)
(package-install package)))
'(package1 package2 package3))
(require 'cl)
(require 'package)
(setq cfg-var:packages '(
emmet-mode
ergoemacs-mode
flycheck
flycheck-pyflakes
monokai-theme
py-autopep8
py-isort
rainbow-mode
yafolding
yasnippet))
(defun cfg:install-packages ()
(let ((pkgs (remove-if #'package-installed-p cfg-var:packages)))
(when pkgs
(message "%s" "Emacs refresh packages database...")
(package-refresh-contents)
(message "%s" " done.")
(dolist (p cfg-var:packages)
(package-install p)))))
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/") t)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
(add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/") t)
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
(package-initialize)
(cfg:install-packages)
I like checking if the user wants to install the packages first as done in this answer. Also I'm refreshing my package contents once before installing anything. I'm not sure if this is the best way, but I don't think the top answers were doing it for me.
(setq required-pkgs '(jedi flycheck cider clojure-mode paredit markdown-mode jsx-mode company))
(require 'cl)
(setq pkgs-to-install
(let ((uninstalled-pkgs (remove-if 'package-installed-p required-pkgs)))
(remove-if-not '(lambda (pkg) (y-or-n-p (format "Package %s is missing. Install it? " pkg))) uninstalled-pkgs)))
(when (> (length pkgs-to-install) 0)
(package-refresh-contents)
(dolist (pkg pkgs-to-install)
(package-install pkg)))
I ran into a problem that nothing happened after adding (package-install 'org)
into .emacs
. I wanted to install the up-to-date version of org-mode
and the built-in org-mode
is quite old.
I dug out the source code of package-install
from Emacs 25.3.1. The function self already checks if a package is installed or not and refuses to install it if the package is already installed. So the check (unless (package-installed-p package) ...)
from answer 10093312 is in fact uncalled for.
(defun package-install (pkg &optional dont-select)
"Install the package PKG.
PKG can be a package-desc or a symbol naming one of the available packages
in an archive in `package-archives'. Interactively, prompt for its name.
If called interactively or if DONT-SELECT nil, add PKG to
`package-selected-packages'.
If PKG is a package-desc and it is already installed, don't try
to install it but still mark it as selected."
(interactive
(progn
;; Initialize the package system to get the list of package
;; symbols for completion.
(unless package--initialized
(package-initialize t))
(unless package-archive-contents
(package-refresh-contents))
(list (intern (completing-read
"Install package: "
(delq nil
(mapcar (lambda (elt)
(unless (package-installed-p (car elt))
(symbol-name (car elt))))
package-archive-contents))
nil t))
nil)))
(add-hook 'post-command-hook #'package-menu--post-refresh)
(let ((name (if (package-desc-p pkg)
(package-desc-name pkg)
pkg)))
(unless (or dont-select (package--user-selected-p name))
(package--save-selected-packages
(cons name package-selected-packages)))
(if-let ((transaction
(if (package-desc-p pkg)
(unless (package-installed-p pkg)
(package-compute-transaction (list pkg)
(package-desc-reqs pkg)))
(package-compute-transaction () (list (list pkg))))))
(package-download-transaction transaction)
(message "`%s' is already installed" name))))
The built-in org-mode
also counts as installed and package-install
refuses to install the newer version from ELPA. After spending some time reading package.el, I came up with the following solution.
(dolist (package (package-compute-transaction
() (list (list 'python '(0 25 1))
(list 'org '(20171211)))))
;; package-download-transaction may be more suitable here and
;; I don't have time to check it
(package-install package))
The reason why it works is that package-*
family functions handle the arguments differently based on whether if it is a symbol or a package-desc
object. You can only specify version info for package-install
via a package-desc
object.
Here's mine, it's shorter :)
(mapc
(lambda (package)
(unless (package-installed-p package)
(progn (message "installing %s" package)
(package-refresh-contents)
(package-install package))))
'(browse-kill-ring flycheck less-css-mode tabbar org auto-complete undo-tree clojure-mode markdown-mode yasnippet paredit paredit-menu php-mode haml-mode rainbow-mode fontawesome))
'development' 카테고리의 다른 글
0 [0]이 구문 적으로 유효한 이유는 무엇입니까? (0) | 2020.07.16 |
---|---|
rvalue 참조로 반환하는 것이 더 효율적입니까? (0) | 2020.07.16 |
O (n) 시간 및 O (1) 공간에서 중복 찾기 (0) | 2020.07.16 |
Java Builder 클래스 서브 클래 싱 (0) | 2020.07.16 |
모든 파일의 후행 공백을 재귀 적으로 제거하는 방법은 무엇입니까? (0) | 2020.07.16 |