help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Check and install/update necessary packages when calling them in emacs.


From: Hongyi Zhao
Subject: Check and install/update necessary packages when calling them in emacs.
Date: Tue, 30 Mar 2021 20:59:26 +0800

Currently, I use the following settings for my `.emacs.d/init.el`:

;;; begin
$ egrep -v '^[ ]*;' .emacs.d/init.el|sed -re '/^$/d'
(setq auth-sources
    '((:source "~/.emacs.d/epg/news.rusnet.ru.gpg")))
(setq url-user-agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88
Safari/537.36")
(when (version<= "26.0.50" emacs-version )
  (global-display-line-numbers-mode))

(require 'package)
(setq package-archives '(("gnu"   .
"https://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/";)
                         ("melpa" .
"https://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/";)
                         ("org" .
"https://mirrors.tuna.tsinghua.edu.cn/elpa/org/";)))
(package-initialize)
(eval-when-compile
  (add-to-list 'load-path "~/Public/repo/github.com/jwiegley/use-package.git")
  (require 'use-package))
  (require 'bind-key)                ;; if you use any :bind variant
(require 'use-package-ensure)
(setq use-package-always-ensure t)
(use-package auto-package-update
  :config
  (setq auto-package-update-delete-old-versions t)
  (setq auto-package-update-hide-results t)
  (auto-package-update-maybe))
(defun my-package-install-refresh-contents (&rest args)
  (package-refresh-contents)
  (advice-remove 'package-install 'my-package-install-refresh-contents))
(advice-add 'package-install :before 'my-package-install-refresh-contents)
(defvar prelude-packages
  '(
    dash flycheck posframe
    s ein
    smartparens
    valign
   )
  "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)
    (message "%s" "Emacs Prelude is now refreshing its package database...")
    (package-refresh-contents)
    (message "%s" " done.")
    (prelude-require-packages prelude-packages)))
(prelude-install-packages)
(use-package smartparens-config
  :ensure smartparens
  :config (progn (show-smartparens-global-mode t))
  :config (progn (smartparens-global-strict-mode t)))
(setq sp-navigate-close-if-unbalanced t)
(add-to-list 'load-path "~/Public/repo/code.orgmode.org/bzg/org-mode.git/lisp")
(add-to-list 'load-path
"~/Public/repo/code.orgmode.org/bzg/org-mode.git/contrib/lisp" t)
(require 'org)
(add-hook 'org-mode-hook #'valign-mode)
(add-hook 'text-mode-hook #'auto-fill-mode)
(setq-default fill-column 80)
(add-hook 'prog-mode-hook #'auto-fill-mode)
(use-package rime
  :bind
  (:map rime-mode-map
         ("C-`" . 'rime-send-keybinding))
  :custom
  (default-input-method "rime")
  (rime-share-data-dir "~/.local/share/fcitx5/rime")
  (rime-show-candidate 'posframe))
(custom-set-variables
 '(package-selected-packages '(dash rime use-package)))
(custom-set-faces
 '(default ((t (:family "DejaVuSansMono Nerd Font Mono" :foundry
"PfEd" :slant normal :weight normal :height 151 :width normal)))))
;;; end

But I want to have some functions similar to lazy loading, that is,
the corresponding installation/update process will be activated only
when the corresponding software package is actually called in Emacs.

Regards
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Polytechnic University of Science and Technology engineering
NO. 552 North Gangtie Road, Xingtai, China



reply via email to

[Prev in Thread] Current Thread [Next in Thread]