Auto install emacs packages with MELPA

前端 未结 6 1062
情话喂你
情话喂你 2020-12-22 22:42

I want to declare all packages that I want to use in emacs in a init.el file. I wonder if its possible to load the missing packages with e.g. MELPA when I startup e

6条回答
  •  一生所求
    2020-12-22 23:48

    All of these answers will work, but I would highly recommend using use-package

    found here: https://github.com/jwiegley/use-package

    use-package not only will automatically install your missing packages, but it greatly simplifies your init.el.

    Here's an example from my init.el

    ;; initial package setup
    (push "path/to/use-package" load-path)
    (require 'use-package)
    (require 'package)
    (mapc (lambda(p) (push p package-archives))
          '(("marmalade" . "http://marmalade-repo.org/packages/")
            ("melpa" . "http://melpa.milkbox.net/packages/")))
    (package-refresh-contents)
    (package-initialize)
    
    ;; this will install undo-tree if it's not there
    ;; and it will set it up how I want
    (use-package undo-tree
      :init (global-undo-tree-mode 1)
      :bind (("C-c j" . undo-tree-undo)
             ("C-c k" . undo-tree-redo)
             ("C-c l" . undo-tree-switch-branch)
             ("C-c ;" . undo-tree-visualize))
      :ensure t)
    

    Take a look at my init.el here: https://github.com/jordonbiondo/.emacs.d/blob/master/init.el

    each use-package block will install the specified package if it is not there, and it encapsulates all my additional setup for packages like keybindings, hooks, and other customizations.

提交回复
热议问题